Exemplo n.º 1
0
  @Override
  public void characters(char ch[], int start, int length) throws SAXException {
    if (_isCost) {
      // TODO: set cost once attribute is in IntervalReading obj
      _isCost = false;
    } else if (_isDuration) {
      // in seconds
      _intervalReading.setDuration(Integer.parseInt(new String(ch, start, length)));
      // System.out.println("Duration: " + new String(ch, start, length));
      _isDuration = false;
    } else if (_isStart) {
      // unix time stamp - must multiply by 1000L because Date obj
      // ctor expects ms not s.
      long timeStamp = 1000L * Long.parseLong(new String(ch, start, length));
      Date d = new Date(timeStamp);
      _intervalReading.setStartTime(d);

      // System.out.println("Start Time: " + new String(ch, start, length));
      _isStart = false;
    } else if (_isValue) {
      _intervalReading.setValue(Integer.parseInt(new String(ch, start, length)));
      // System.out.println("Value: " + new String(ch, start, length));
      _isValue = false;
    }
  }
Exemplo n.º 2
0
  // El string debe estar em formato json
  public boolean updateRegistry(String dataJson) {
    try {
      // Crea objeto json con string por parametro
      JSONObject json = new JSONObject(dataJson);
      // Obtiene el array de Registos
      JSONArray arr = json.getJSONArray("Registry");
      // Recorre el array
      for (int i = 0; i < arr.length(); i++) {
        // Obtiene los datos idSensor y value
        int idSensor = arr.getJSONObject(i).getInt("idSensor");

        int value = arr.getJSONObject(i).getInt("value");
        // Recorre la configuracion de registro
        for (RegistryConf reg : registryConf) {

          // Se fija si el registro corresponde a esta configuracion
          if (reg.getIdSensor() == idSensor) {

            // Checkea el criterio para guardar, o no en la BD
            // Checkea tambien si el valor es igual al anterior
            if (reg.getSaveTypeString() == "ONCHANGE" && lastRead.get(idSensor) != value) {
              // Actualizo la ultima lectura y guardo en la BD
              lastRead.put(idSensor, value);
              saveRegistry(idSensor, value);

            } else if (reg.getSaveTypeString() == "ONTIME") {
              // Variables auxiliares, para checkear tiempo
              Long auxLong = System.currentTimeMillis() / 1000;
              int now = auxLong.intValue();
              int timeToSave = lastRead.get(idSensor) + reg.getValue();
              // Checkea si ya es tiempo para guerdar un nuevo registro
              if (now >= timeToSave) {
                // Actualizo el ultimo guardado
                lastRead.put(idSensor, now);
                saveRegistry(idSensor, value);
              }
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return false;
  }
Exemplo n.º 3
0
 public long getLongContent(long defaultValue) {
   String c = node.getTextContent();
   if (c != null) {
     try {
       return Long.parseLong(c);
     } catch (NumberFormatException nfe) {
     }
   }
   return defaultValue;
 }
Exemplo n.º 4
0
  public long getUnicodeAsLong() {
    long retval = -1;

    String s = getUnicodeAsString();
    if (s.equals("")) {
      return retval;
    } // if

    try {
      retval = Long.parseLong(s, 16);
    } catch (NumberFormatException e) {
      retval = -1;
    } // try-catch

    return retval;
  }
Exemplo n.º 5
0
  /** creates new file */
  public GlyphFile(File a_dir, String a_name, long a_unicode) throws FileNotFoundException {
    super();

    m_fileName = createFileName(a_dir, a_name);

    init(getClass().getResource(s_emptyFileName));
    setGlyphTitle(a_name);
    setUnicode(Long.toHexString(a_unicode));

    /*int eastAsianWidth = UCharacter.getIntPropertyValue(
    (int) a_unicode,
    0x1004); //UProperty.EAST_ASIAN_WIDTH);
         */
    int eastAsianWidth = 5; // ??
    if (eastAsianWidth == 5 || eastAsianWidth == 1) {
      setAdvanceWidth(k_fullWidth);
    } // if

    saveGlyphFile();
  }
Exemplo n.º 6
0
 /**
  * Returns the value of an attribute.
  *
  * @param name the non-null full name of the attribute.
  * @param defaultValue the default value of the attribute.
  * @return the value, or defaultValue if the attribute does not exist.
  */
 public long getLong(String name, long defaultValue) {
   String value = getString(name);
   return (value == null) ? defaultValue : Long.parseLong(value);
 }