Last active
December 28, 2015 14:09
-
-
Save jonasurbano/7512908 to your computer and use it in GitHub Desktop.
Servicio.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.pfc.domain; | |
import javax.persistence.Column; | |
import org.codehaus.jackson.annotate.JsonIgnore; | |
import org.pfc.utils.JsonMap; | |
public class Servicio { | |
private static final String CLAVE_VISITAS = "visitas"; | |
// Otras propiedades | |
@Column | |
private String misc; | |
// Otros métodos | |
/** | |
* Obtiene {@code clave} del misc | |
* convirtiendo a Map el String | |
*/ | |
private String getMisc(String clave) { | |
return JsonMap.toMap(misc).get(clave); | |
} | |
/** | |
* Añade o actualiza {@code "clave"} en el JSON | |
* convirtiendo a Map la propiedad misc | |
*/ | |
private void setMisc(String clave,String valor) { | |
misc = JsonMap.toJson(clave, valor, misc); | |
} | |
public int getVisitas() { | |
String visitas = getMisc(CLAVE_VISITAS); | |
if (visitas == null) return 0; | |
try { | |
return Integer.parseInt(visitas); | |
} catch (Exception e) { | |
return 0; | |
} | |
} | |
public void incrementarVisitas() { | |
int visitas = getVisitas(); | |
if (visitas == 0) setMisc(CLAVE_VISITAS, Integer.toString(1)); | |
else setMisc(CLAVE_VISITAS,Integer.toString(++visitas)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment