package art.servers.gost.access.types.neural; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import java.lang.reflect.Field; @JsonPropertyOrder ({ "Alarm checksum", "Alarm online", "Alarm VID", "Alarm NTP", "Alarm GPS" }) public class NeuralStatusAlarms { @JsonProperty("Alarm checksum") public long alarm_checksum = 0; @JsonProperty("Alarm online") public long alarm_online = 0; @JsonProperty("Alarm VID") public long alarm_vid = 0; @JsonProperty("Alarm NTP") public long alarm_ntp = 0; @JsonProperty("Alarm GPS") public long alarm_gps = 0; @JsonIgnore public boolean setAlarm(String fieldName, boolean value) { try { Object object = NeuralStatusAlarms.this; Field field = getField(fieldName, this.getClass()); field.setAccessible(true); long alarmTimestamp = field.getLong(object); if ((value == true) && (alarmTimestamp > 0)) return false; if ((value == false) && (alarmTimestamp == 0)) return false; if (value == true) { field.set(object, System.currentTimeMillis()); } else { field.set(object, 0); } } catch (Exception e) { } return true; } @JsonIgnore public Field getField(String fieldName, Class clazz) { while (clazz != null && clazz != Object.class) { for (Field field : clazz.getDeclaredFields()) { if (field.getName().equals(fieldName)) { return field; } } clazz = clazz.getSuperclass(); } return null; } }