@Test
  public void test_manuel_int32_t() throws IOException {
    // 6B 73 68 6F
    // 107 115 104 111
    // 29547 28520
    // 1869116267

    byte[] input1 = {107, 115, 104, 111}; // 6B 73 68 6F
    Long expected1 = 1869116267L; // 1869116267
    BinFileReader binFileReader =
        new BinFileReader(new BufferedInputStream(new ByteArrayInputStream(input1)));
    SignedInteger result1 = binFileReader.int32_t();
    assertEquals("int32_t6B 73 68 6F asLong() = 1869116267", expected1, result1.asLong());
    assertEquals(
        "int32_t6B 73 68 6F getSignedValue() = 1869116267",
        (Integer) expected1.intValue(),
        result1.getSignedValue());
    byte[] input2 = {32, 75, -61, -68}; // 20 4B C3 BC
    Long expected2 = -1128051936L; // -1128051936
    binFileReader = new BinFileReader(new BufferedInputStream(new ByteArrayInputStream(input2)));
    SignedInteger result2 = binFileReader.int32_t();
    assertEquals("int32_t20 4B C3 BC asLong() = -1128051936", expected2, result2.asLong());
    assertEquals(
        "int32_t20 4B C3 BC getSignedValue() = -1128051936",
        (Integer) expected2.intValue(),
        result2.getSignedValue());
  }
Пример #2
0
 Response doSend() throws IOException {
   connection.setRequestMethod(this.verb.name());
   if (connectTimeout != null) {
     connection.setConnectTimeout(connectTimeout.intValue());
   }
   if (readTimeout != null) {
     connection.setReadTimeout(readTimeout.intValue());
   }
   if (boundary != null) {
     connection.setRequestProperty(CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
   }
   addHeaders(connection);
   if (verb.equals(Verb.PUT) || verb.equals(Verb.POST)) {
     addBody(connection, getByteBodyContents());
   }
   return new Response(connection);
 }
Пример #3
0
 public int read(byte[] b, int off, int len) {
   buf.buf = b;
   buf.pos = off;
   buf.size = b.length;
   Long n = in.readBuf(buf, len);
   buf.buf = null;
   if (n == null) return -1;
   return n.intValue();
 }
Пример #4
0
 Response doSend(RequestTuner tuner) throws IOException
 {
   connection.setRequestMethod(this.verb.name());
   if (connectTimeout != null) 
   {
     connection.setConnectTimeout(connectTimeout.intValue());
   }
   if (readTimeout != null)
   {
     connection.setReadTimeout(readTimeout.intValue());
   }
   tuner.tune(this);
   addHeaders(connection);
   if (verb.equals(Verb.PUT) || verb.equals(Verb.POST))
   {
     addBody(connection, getByteBodyContents());
   }
   return new Response(connection);
 }
Пример #5
0
 public TcpSocket bind(TcpSocket fan, IpAddr addr, Long port) {
   try {
     InetAddress javaAddr = (addr == null) ? null : addr.peer.java;
     int javaPort = (port == null) ? 0 : port.intValue();
     socket.bind(new InetSocketAddress(javaAddr, javaPort));
     return fan;
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
 @Test
 public void test_int32_t() throws IOException {
   for (Long exp : expected_int32) {
     SignedInteger result = binFileReader.int32_t();
     assertEquals("int32_t " + exp + " asInt()", exp, result.asLong());
     assertEquals(
         "int32_t " + exp + " getSignedValue()",
         (Integer) exp.intValue(),
         result.getSignedValue());
     assertEquals("int32_t " + exp + " toString()", exp.toString(), result.toString());
   }
 }
Пример #7
0
  @Override
  public BigInteger getTotalDifficultyForHash(byte[] hash) {
    Block block = this.getBlockByHash(hash);
    if (block == null) return ZERO;

    Long level = block.getNumber();
    List<BlockInfo> blockInfos = index.get(level.intValue());
    for (BlockInfo blockInfo : blockInfos)
      if (areEqual(blockInfo.getHash(), hash)) {
        return blockInfo.cummDifficulty;
      }

    return ZERO;
  }
Пример #8
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;
  }
  @Override
  public void execute() throws ExecutionException {
    interrupted = false;

    // quit if setup failed
    if (gracefulExit) {
      gracefulExit("Plugin was not initialised correctly. Exiting gracefully ... ");
      return;
    }

    AnnotationSet inputAS =
        (inputASName == null || inputASName.trim().length() == 0)
            ? document.getAnnotations()
            : document.getAnnotations(inputASName);
    AnnotationSet outputAS =
        (outputASName == null || outputASName.trim().length() == 0)
            ? document.getAnnotations()
            : document.getAnnotations(outputASName);

    AnnotationSet sentenceAS = null;
    if (sentenceType != null && !sentenceType.isEmpty()) {
      sentenceAS = inputAS.get(sentenceType);
    }

    // Document content
    String docContent = document.getContent().toString();
    int docLen = docContent.length();

    // For matching purposes replace all whitespace characters with a single space
    docContent = docContent.replaceAll("[\\s\\xA0\\u2007\\u202F]", " ");

    fireStatusChanged("Locating anatomy, disease and procedure mentions in " + document.getName());
    fireProgressChanged(0);

    if (sentenceAS != null) {
      for (Annotation sentence : sentenceAS) {
        Long sentStartOffset = sentence.getStartNode().getOffset();
        Long sentEndOffset = sentence.getEndNode().getOffset();

        // Converting the sentence to lower case prevents the need to use case-insenstive regex
        // matching, which should give a small performance boost
        String sentenceContent =
            docContent
                .substring(sentStartOffset.intValue(), sentEndOffset.intValue())
                .toLowerCase(Locale.ENGLISH);

        if (diseaseType != null && !diseaseType.isEmpty()) {
          doMatch(
              patternMap.get("disease_suffix"),
              sentenceContent,
              inputAS,
              outputAS,
              "suffDisease",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("disease_abbrevs"),
              sentenceContent,
              inputAS,
              outputAS,
              "preDisease",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("disease_named_syndrome"),
              sentenceContent,
              inputAS,
              outputAS,
              "namedDisease",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("disease_sense"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpDiseaseSense",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("disease_sense_context"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpDiseaseSenseContext",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("disease_generic_context"),
              sentenceContent,
              inputAS,
              outputAS,
              "poDisease",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("disease_anatomy_context"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpDisease",
              sentStartOffset,
              docLen);
        }

        if (procedureType != null && !procedureType.isEmpty()) {
          doMatch(
              patternMap.get("procedure_suffix"),
              sentenceContent,
              inputAS,
              outputAS,
              "poProcedure",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("procedure_key"),
              sentenceContent,
              inputAS,
              outputAS,
              "poProcedure",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("procedure_anatomy_context"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpProcedure",
              sentStartOffset,
              docLen);
        }

        if (symptomType != null && !symptomType.isEmpty()) {
          doMatch(
              patternMap.get("symptom_key"),
              sentenceContent,
              inputAS,
              outputAS,
              "poSymptom",
              sentStartOffset,
              docLen);
        }

        if (testType != null && !testType.isEmpty()) {
          doMatch(
              patternMap.get("test_key"),
              sentenceContent,
              inputAS,
              outputAS,
              "poTest",
              sentStartOffset,
              docLen);
        }

        if (anatomyType != null && !anatomyType.isEmpty()) {
          doMatch(
              patternMap.get("anatomy_suffix_adjective"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpAnatSuffAdj",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("anatomy_suffix"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpAnatSuff",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("anatomy_prefix"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpAnatPre",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("anatomy_position"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpAnatPos",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("anatomy_space_region_junction"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpAnatSpace",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("anatomy_part_adjective"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpAnatAdj",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("anatomy_latin_noun"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpAnatLatin",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("anatomy_muscle"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpAnatMuscle",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("anatomy_part"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpAnatPart",
              sentStartOffset,
              docLen);
          doMatch(
              patternMap.get("anatomy_fluid"),
              sentenceContent,
              inputAS,
              outputAS,
              "tmpAnatFluid",
              sentStartOffset,
              docLen);
        }
      }
      // Run JAPE transducer to clean up the output
      fireStatusChanged(
          "Processing anatomical, disease and procedure mentions in " + document.getName());
      try {
        japeTransducer.setDocument(document);
        japeTransducer.setInputASName(inputASName);
        japeTransducer.setOutputASName(outputASName);
        japeTransducer.addProgressListener(this);
        japeTransducer.execute();
      } catch (ExecutionException re) {
        gate.util.Err.println("Unable to run " + japeURL);
        gracefulExit = true;
      } finally {
        japeTransducer.setDocument(null);
      }
      // rename temporary annotations
      if (!debug) {
        renameAnnotations(outputAS, "tmpAnatomicalTerm", anatomyType);
        renameAnnotations(outputAS, "suffDisease", diseaseType);
        renameAnnotations(outputAS, "poDisease", diseaseType);
        renameAnnotations(outputAS, "preDisease", diseaseType);
        renameAnnotations(outputAS, "poProcedure", procedureType);
        renameAnnotations(outputAS, "poSymptom", symptomType);
        renameAnnotations(outputAS, "poTest", testType);
      }
    } else {
      gracefulExit("No sentences to process!");
    }

    // want list of disease key words plus symptoms such as oedema? or just diseases

    fireProcessFinished();
  } // end execute()
Пример #10
0
  public static void list(
      String search, int category, Integer size, Integer page, int firstPage, int lastPage) {
    List<Ad> ads = null;

    List<Category> cats = Category.find("categorytype_id=?1", "1").fetch();

    EntityManager entityManager = play.db.jpa.JPA.em();
    List<BigInteger> bCounts =
        entityManager
            .createNativeQuery(
                "select count(*) as maxCount from Ad as a group by category_id order by maxCount")
            .getResultList();
    int min = bCounts.get(0).intValue();
    int max = bCounts.get(bCounts.size() - 1).intValue();
    bCounts =
        entityManager
            .createNativeQuery(
                "select count(*) as maxCount from Ad as a group by category_id order by category_id ")
            .getResultList();
    List<String> fonts = new ArrayList<String>();
    for (int i = 0; i < bCounts.size(); i++) {
      BigInteger count = bCounts.get(i);
      int x = Ads.getFontSize(count.intValue(), min, max);
      fonts.add(String.valueOf(x));
    }

    int pagesCount = 0;

    page = page != null ? page : 1;
    if (search.trim().length() == 0) {
      Long l = null;
      if (category == 0) {

        ads = Ad.find("order by createDate desc").fetch(page, size);
        l = Ad.count();
      } else {

        ads = Ad.find(" category_id=?1 order by createDate desc", category).fetch(page, size);
        l = Ad.count(" category_id=?1 ", category);
      }

      Long l2 = (l / 10);
      if ((l % 10) > 0) l2 = (long) (Math.floor(l2) + 1);
      pagesCount = Integer.valueOf(l2.intValue());

    } else {
      search = search.toLowerCase();
      Long l = null;
      if (category == 0) {
        ads =
            Ad.find(
                    "(lower(headline) like ?1 OR lower(description) like ?2)",
                    "%" + search + "%",
                    "%" + search + "%")
                .fetch(page, size);
        l =
            Ad.count(
                "(lower(headline) like ?1 OR lower(description) like ?2)",
                "%" + search + "%",
                "%" + search + "%");
      } else {
        ads =
            Ad.find(
                    " category_id=?1 and (lower(headline) like ?2 OR lower(description) like ?3)",
                    category,
                    "%" + search + "%",
                    "%" + search + "%")
                .fetch(page, size);
        l =
            Ad.count(
                "category_id=?1 and (lower(headline) like ?2 OR lower(description) like ?3)",
                category,
                "%" + search + "%",
                "%" + search + "%");
      }

      Long l2 = (l / 10);
      if ((l % 10) > 0) l2 = (long) (Math.floor(l2) + 1);
      pagesCount = Integer.valueOf(l2.intValue());
    }

    if ((lastPage - page) <= 2) {
      firstPage = page - 2;
      lastPage = page + 7;
      if (lastPage > pagesCount) lastPage = pagesCount;

    } else if ((page - firstPage) <= 2) {
      firstPage = page - 7;
      lastPage = page + 2;
      if (firstPage < 1) {
        firstPage = 1;
        lastPage = 10;
      }
    }

    if (lastPage > pagesCount) lastPage = pagesCount;

    render(ads, search, size, page, pagesCount, firstPage, lastPage, cats, fonts);
  }
 public int getIntParameter(String parameter, int defaultValue) {
   Long tempValue = getLongParameterRaw(parameter);
   return tempValue != null ? tempValue.intValue() : defaultValue;
 }
Пример #12
0
 final int getCurrentCount() {
   Long count =
       (Long) getPlayerCountScript.eval(ImmutableList.<String>of(), ImmutableList.<String>of());
   return count.intValue();
 }
Пример #13
0
 public void setOutBufferSize(TcpSocket fan, Long v) {
   if (in != null) throw Err.make("Must set outBufSize before connection");
   outBufSize = (v == null) ? 0 : v.intValue();
 }
Пример #14
0
 public static SysInStream make(java.io.InputStream in, Long bufSize) {
   if (bufSize == null || bufSize.longValue() == 0) return new SysInStream(in);
   else return new SysInStream(new java.io.BufferedInputStream(in, bufSize.intValue()));
 }