Пример #1
1
 @Override
 public void deserialize(DataInput in) throws IOException {
   // little endian
   this.cardinality = 0;
   for (int k = 0; k < bitmap.length; ++k) {
     bitmap[k] = Long.reverseBytes(in.readLong());
     this.cardinality += Long.bitCount(bitmap[k]);
   }
 }
Пример #2
0
  public static void main(String[] args) {

    int numBombs = Integer.parseInt(getLine());

    Point[] ary = new Point[numBombs];
    for (int i = 0; i < numBombs; i++) {
      String[] inp = getLine().split("\\s+");
      ary[i] = new Point(Long.parseLong(inp[0]), Long.parseLong(inp[1]));
    }

    Arrays.sort(
        ary,
        new Comparator<Point>() {
          public int compare(Point a, Point b) {
            if (a.absx + a.absy == b.absx + b.absy) {
              return 0;
            }
            return a.absx + a.absy < b.absx + b.absy ? -1 : 1;
          }
        });

    out.append(cnt + "\n");
    for (Point p : ary) {
      remove(p);
    }
    System.out.print(out);
  }
Пример #3
0
 /** Convert a collection of ConstantSets to the format expected by GenTest.addClassLiterals. */
 public static MultiMap<Class<?>, PrimitiveOrStringOrNullDecl> toMap(
     Collection<ConstantSet> constantSets) {
   final MultiMap<Class<?>, PrimitiveOrStringOrNullDecl> map =
       new MultiMap<Class<?>, PrimitiveOrStringOrNullDecl>();
   for (ConstantSet cs : constantSets) {
     Class<?> clazz;
     try {
       clazz = Class.forName(cs.classname);
     } catch (ClassNotFoundException e) {
       throw new Error("Class " + cs.classname + " not found on the classpath.");
     }
     for (Integer x : cs.ints) {
       map.add(clazz, new PrimitiveOrStringOrNullDecl(int.class, x.intValue()));
     }
     for (Long x : cs.longs) {
       map.add(clazz, new PrimitiveOrStringOrNullDecl(long.class, x.longValue()));
     }
     for (Float x : cs.floats) {
       map.add(clazz, new PrimitiveOrStringOrNullDecl(float.class, x.floatValue()));
     }
     for (Double x : cs.doubles) {
       map.add(clazz, new PrimitiveOrStringOrNullDecl(double.class, x.doubleValue()));
     }
     for (String x : cs.strings) {
       map.add(clazz, new PrimitiveOrStringOrNullDecl(String.class, x));
     }
     for (Class<?> x : cs.classes) {
       map.add(clazz, new PrimitiveOrStringOrNullDecl(Class.class, x));
     }
   }
   return map;
 }
  @Test
  public void printVdso() throws IOException, InterruptedException {
    long start = 0;
    long end = 0;
    String maps = "/proc/self/maps";
    if (!new File(maps).exists()) return;
    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(maps)));
    try {
      for (String line; (line = br.readLine()) != null; ) {
        if (line.endsWith("[vdso]")) {
          String[] parts = line.split("[- ]");
          start = Long.parseLong(parts[0], 16);
          end = Long.parseLong(parts[1], 16);
        }

        //                System.out.println(line);
      }
    } catch (IOException ioe) {
      br.close();
      throw ioe;
    }
    System.out.printf("vdso %x to %x %n", start, end);
    NativeBytes nb = new NativeBytes(start, end);
    long[] longs = new long[(int) ((end - start) / 8)];
    for (int i = 0; i < longs.length; i++) longs[i] = nb.readLong(i * 8);
    Jvm.pause(1);
    for (int i = 0; i < longs.length; i++) {
      long l = nb.readLong(i * 8);
      if (l != longs[i]) System.out.printf("%d: %d %x%n", i, l, l);
    }
  }
  public static void fromCRAWDAD(
      LinkTrace links,
      InputStream in,
      double timeMul,
      long ticsPerSecond,
      long offset,
      IdGenerator idGen)
      throws IOException {

    StatefulWriter<LinkEvent, Link> linkWriter = links.getWriter();
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String line;

    while ((line = br.readLine()) != null) {
      String[] elems = line.split("[ \t]+");
      Integer id1 = idGen.getInternalId(elems[0]);
      Integer id2 = idGen.getInternalId(elems[1]);
      long begin = (long) (Long.parseLong(elems[2]) * timeMul) + offset;
      long end = (long) (Long.parseLong(elems[3]) * timeMul) + offset;
      linkWriter.queue(begin, new LinkEvent(id1, id2, LinkEvent.UP));
      linkWriter.queue(end, new LinkEvent(id1, id2, LinkEvent.DOWN));
    }
    linkWriter.flush();
    linkWriter.setProperty(Trace.timeUnitKey, Units.toTimeUnit(ticsPerSecond));
    idGen.writeTraceInfo(linkWriter);
    linkWriter.close();
    br.close();
  }
  @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());
  }
Пример #7
0
  /**
   * Returns a new working directory (in temporary space). Ensures the directory exists. Any
   * directory levels that had to be created are marked for deletion on exit.
   *
   * @return working directory
   * @exception IOException
   * @since 2.0
   */
  public static synchronized File createWorkingDirectory() throws IOException {

    if (dirRoot == null) {
      dirRoot = System.getProperty("java.io.tmpdir"); // $NON-NLS-1$
      // in Linux, returns '/tmp', we must add '/'
      if (!dirRoot.endsWith(File.separator)) dirRoot += File.separator;

      // on Unix/Linux, the temp dir is shared by many users, so we need to ensure
      // that the top working directory is different for each user
      if (!Platform.getOS().equals("win32")) { // $NON-NLS-1$
        String home = System.getProperty("user.home"); // $NON-NLS-1$
        home = Integer.toString(home.hashCode());
        dirRoot += home + File.separator;
      }
      dirRoot +=
          "eclipse"
              + File.separator
              + ".update"
              + File.separator
              + Long.toString(tmpseed)
              + File.separator; // $NON-NLS-1$ //$NON-NLS-2$
    }

    String tmpName = dirRoot + Long.toString(++tmpseed) + File.separator;

    File tmpDir = new File(tmpName);
    verifyPath(tmpDir, false);
    if (!tmpDir.exists()) throw new FileNotFoundException(tmpName);
    return tmpDir;
  }
Пример #8
0
  public static Network initParamFromFile(Network n, String fileName) throws Exception {
    n = LtWeightInitiator.initParam(n, 0.0);

    BufferedReader br = new BufferedReader(new FileReader(fileName));
    String tmpLine = null;
    while (true) {
      tmpLine = br.readLine();
      if (tmpLine == null) break;
      String[] tmp = tmpLine.split("\t");
      Long from = Long.parseLong(tmp[0]);
      Long to = Long.parseLong(tmp[1]);
      double value = Double.parseDouble(tmp[2]);
      Long rid = n.findEdge(from, to);
      if (rid == null) continue;
      Relation r = n.getRelation(rid);
      r.setLtWeight(value);
    }
    br.close();

    /*Collection<LinkUnit> linkWeights = IOUtility.readLinkValue( fileName );
    for( LinkUnit linkunit : linkWeights ){
    	Integer from = linkunit.getFrom();
    	Integer to = linkunit.getTo();
    	double value = linkunit.getValue();
    	Integer rid = n.findEdge( from , to );
    	Relation r = n.getRelation( rid );
    	r.setLtWeight( value );
    }
    */
    return n;
  }
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str;
    str = in.readLine().split(" ");
    int N = Integer.parseInt(str[0]);

    long[] A = new long[N];
    long[] B = new long[N];
    long[] C = new long[N];
    long[] D = new long[N];
    for (int i = 0; i < N; i++) {
      str = in.readLine().split(" ");
      A[i] = Long.parseLong(str[0]);
      B[i] = Long.parseLong(str[1]);
      C[i] = Long.parseLong(str[2]);
      D[i] = Long.parseLong(str[3]);
    }

    long[] CD = new long[N * N];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        CD[i * N + j] = C[i] + D[j];
      }
    }
    Arrays.sort(CD);
    long count = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        long sum = A[i] + B[j];
        count += upperbound(CD, -sum) - lowerbound(CD, -sum) + 1;
      }
    }
    System.out.println(count);
  }
Пример #10
0
 public long GetRateTimeFrame(Long UserId, Long numofhours) {
   this.log4j.info("=================================================================");
   this.log4j.info(
       "getting rate for user id: " + UserId + " within the last " + numofhours + " hours");
   long diff = numofhours * 60 * 60 * 1000; // hours to millis
   BasicDBObject docline = new BasicDBObject();
   docline.put("user_id", UserId); // querying to find the right userId
   DBObject doc = this.collrate.findOne(docline);
   if (doc == null) // there is no document for the user
   {
     this.log4j.error("user id : " + UserId + " does not exist");
     return -1L;
   } else // document exists
   {
     long result = 0;
     long currstart = Long.parseLong(doc.get("current_slot_start_time_millis").toString());
     if (System.currentTimeMillis() - diff > currstart) {
       this.log4j.info("result is 0");
       return 0;
     } else {
       double backslots = diff / this.slot_time_millis;
       if (backslots > this.num_of_slots) {
         this.log4j.info(
             "you requested longer time than the time frame, the result will be only for the previous timeframe");
       }
       for (int i = 0; i < backslots || i < this.num_of_slots; i++) {
         int slot = (int) ((this.current_slot_index - i + this.num_of_slots) % this.num_of_slots);
         result += Long.parseLong(doc.get("slot" + slot).toString());
       }
       this.log4j.info("result is " + result);
       return result;
     }
   }
 }
Пример #11
0
 public static void main(String[] args) throws Exception {
   Scanner s = new Scanner(new FileReader("pb.in"));
   while (s.hasNext()) {
     String line = s.nextLine();
     String[] rep = line.split("\\(");
     String[] nonrep = (rep[0] + "0").split("\\.");
     long num1 = Integer.parseInt(rep[1].substring(0, rep[1].length() - 1));
     String nine = "";
     while (nine.length() != rep[1].length() - 1) nine += "9";
     for (int i = 0; i < nonrep[1].length() - 1; i++) nine += "0";
     String ten = "";
     while (nonrep[1].length() != ten.length()) ten += "0";
     ten = "1" + ten;
     String nr = nonrep[0] + nonrep[1];
     long den1 = Long.parseLong(nine);
     long den2 = Long.parseLong(ten);
     long num2 = Long.parseLong(nr);
     long num = num1 * den2 + num2 * den1;
     long den = den1 * den2;
     long gcd = new BigInteger("" + num).gcd(new BigInteger("" + den)).longValue();
     num /= gcd;
     den /= gcd;
     System.out.println(line + " = " + num + " / " + den);
   }
 }
Пример #12
0
  public static void main(String[] args) throws IOException {
    System.out.println("Input Stream:");
    long start = System.currentTimeMillis();
    Path filename = Paths.get(args[0]);
    long crcValue = checksumInputStream(filename);
    long end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");

    System.out.println("Buffered Input Stream:");
    start = System.currentTimeMillis();
    crcValue = checksumBufferedInputStream(filename);
    end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");

    System.out.println("Random Access File:");
    start = System.currentTimeMillis();
    crcValue = checksumRandomAccessFile(filename);
    end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");

    System.out.println("Mapped File:");
    start = System.currentTimeMillis();
    crcValue = checksumMappedFile(filename);
    end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");
  }
Пример #13
0
  /**
   * Creates the tool context denoting the range of samples that should be analysed by a tool.
   *
   * @return a tool context, never <code>null</code>.
   */
  private ToolContext createToolContext() {
    int startOfDecode = -1;
    int endOfDecode = -1;

    final int dataLength = this.dataContainer.getValues().length;
    if (this.dataContainer.isCursorsEnabled()) {
      if (this.dataContainer.isCursorPositionSet(0)) {
        final Long cursor1 = this.dataContainer.getCursorPosition(0);
        startOfDecode = this.dataContainer.getSampleIndex(cursor1.longValue()) - 1;
      }
      if (this.dataContainer.isCursorPositionSet(1)) {
        final Long cursor2 = this.dataContainer.getCursorPosition(1);
        endOfDecode = this.dataContainer.getSampleIndex(cursor2.longValue()) + 1;
      }
    } else {
      startOfDecode = 0;
      endOfDecode = dataLength;
    }

    startOfDecode = Math.max(0, startOfDecode);
    if ((endOfDecode < 0) || (endOfDecode >= dataLength)) {
      endOfDecode = dataLength - 1;
    }

    return new DefaultToolContext(startOfDecode, endOfDecode);
  }
Пример #14
0
    public void applyInfoToFriendFromBuddyInfo(final Friend friend, BuddyInfo info) {
      friend.setIsAvailable(true);
      long status = info.getIcqStatus();
      if ((status & FullUserInfo.ICQSTATUS_AWAY) == 1) {
        friend.setStatus(Friend.Status.AWAY);
      } else if (((status & FullUserInfo.ICQSTATUS_DND) == 1)) {
        friend.setStatus(Friend.Status.DND);
      } else if ((status & FullUserInfo.ICQSTATUS_OCCUPIED) == 1) {
        friend.setStatus(Friend.Status.DND);
      } else if ((status & FullUserInfo.ICQSTATUS_NA) == 1) {
        friend.setStatus(Friend.Status.NA);
      } else if ((status & FullUserInfo.ICQSTATUS_DEFAULT) == 1) {
        friend.setStatus(Friend.Status.AVAILABLE);
      } else if ((status & FullUserInfo.ICQSTATUS_FFC) == 1) {
        friend.setStatus(Friend.Status.AVAILABLE);
      }

      friend.setStatusMessage(info.getStatusMessage());
      //			Screenname buddy = new Screenname(friend.getUserName());
      //			connection.getInfoService().requestDirectoryInfo(buddy);
      //			connection.getInfoService().requestUserProfile(buddy);

      //			 int requestId = nextSeqId();
      long buddyUIN = Long.parseLong(friend.getUserName());
      long ownerUIN = Long.parseLong(getUserName());
      MetaShortInfoRequest req = new MetaShortInfoRequest(ownerUIN, 2, buddyUIN);

      //	         ShortInfoResponseRetriever responseRetriever = new ShortInfoResponseRetriever();
      connection
          .getInfoService()
          .getOscarConnection()
          .sendSnacRequest(
              req,
              new SnacRequestAdapter() {
                public void handleResponse(SnacResponseEvent e) {
                  SnacCommand snac = e.getSnacCommand();
                  if (snac instanceof MetaShortInfoCmd) {
                    MetaShortInfoCmd infoSnac = (MetaShortInfoCmd) snac;
                    String nick = infoSnac.getNickname();
                    String firstName = infoSnac.getFirstName();
                    String lastName = infoSnac.getLastName();
                    String fullname = firstName + " " + lastName;
                    if (fullname.length() < 2) fullname = nick;
                    friend.setName(fullname);
                  }
                }
              });

      //	         synchronized(responseRetriever)
      //	         {
      //	             try{
      //	                 responseRetriever.wait(30000);
      //	             }
      //	             catch (InterruptedException ex)
      //	             {
      //	             }
      //	         }

    }
Пример #15
0
 /**
  * Goes to the current cursor position of the cursor with the given index.
  *
  * @param aCursorIdx the index of the cursor to go to, >= 0 && < 10.
  */
 public void gotoCursorPosition(final int aCursorIdx) {
   if ((this.mainFrame != null) && this.dataContainer.isCursorsEnabled()) {
     final Long cursorPosition = this.dataContainer.getCursorPosition(aCursorIdx);
     if (cursorPosition != null) {
       this.mainFrame.gotoPosition(cursorPosition.longValue());
     }
   }
 }
 @Test
 public void test_int64_t() throws IOException {
   for (Long exp : expected_int64) {
     SignedLong result = binFileReader.int64_t();
     assertEquals("int64_t " + exp + " getSignedValue()", exp, result.getSignedValue());
     assertEquals("int64_t " + exp + " toString()", exp.toString(), result.toString());
   }
 }
  /** {@inheritDoc} */
  @Override
  public int compareTo(GridClockDeltaVersion o) {
    int res = Long.compare(topVer, o.topVer);

    if (res == 0) res = Long.compare(ver, o.ver);

    return res;
  }
Пример #18
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();
 }
Пример #19
0
 boolean isEnabled(long m) {
   if (enabledMechanisms != null) {
     return enabledMechanisms.contains(Long.valueOf(m));
   }
   if (disabledMechanisms != null) {
     return !disabledMechanisms.contains(Long.valueOf(m));
   }
   return true;
 }
Пример #20
0
 /**
  * {@code #revNumber}의 이전 리비전에 해당하는 커밋 정보를 번환한다.
  *
  * @param revNumber
  * @return
  */
 @Override
 public Commit getParentCommitOf(String revNumber) {
   Long rev = Long.parseLong(revNumber) - 1;
   try {
     return getCommit(rev.toString());
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Пример #21
0
 /**
  * Returns the filter decision
  *
  * @param message - the message content
  * @return
  */
 public boolean filter(String message, String filterCondition) {
   Date dt = new Date();
   long currentTime = dt.getTime();
   String digest = DigestUtils.md5Hex(message);
   Long lastTime = digestDB.get(digest);
   if (lastTime == null) return true;
   long per = currentTime - lastTime.longValue();
   if (per > getPeriod(filterCondition)) return true;
   else return false;
 }
  public void testO2PMap() {
    // Long-long
    TObjectLongHashMap<Long> olmap = new TObjectLongHashMap<Long>();
    assertTrue(serializesCorrectly(olmap, "o2p-l-1"));
    olmap.put(Long.valueOf(0), 1);
    assertTrue(serializesCorrectly(olmap, "o2p-l-2"));
    olmap.put(Long.valueOf(Long.MIN_VALUE), Long.MIN_VALUE);
    assertTrue(serializesCorrectly(olmap, "o2p-l-3"));
    olmap.put(Long.valueOf(Long.MAX_VALUE), Long.MAX_VALUE);
    assertTrue(serializesCorrectly(olmap, "o2p-l-4"));

    // Int-int
    TObjectIntHashMap<Integer> oimap = new TObjectIntHashMap<Integer>();
    assertTrue(serializesCorrectly(oimap, "o2p-i-1"));
    oimap.put(Integer.valueOf(0), 1);
    assertTrue(serializesCorrectly(oimap, "o2p-i-2"));
    oimap.put(Integer.valueOf(Integer.MIN_VALUE), Integer.MIN_VALUE);
    assertTrue(serializesCorrectly(oimap, "o2p-i-3"));
    oimap.put(Integer.valueOf(Integer.MAX_VALUE), Integer.MAX_VALUE);
    assertTrue(serializesCorrectly(oimap, "o2p-i-4"));

    // Double-double
    TObjectDoubleHashMap<Double> odmap = new TObjectDoubleHashMap<Double>();
    assertTrue(serializesCorrectly(odmap, "o2p-d-1"));
    odmap.put(Double.valueOf(0), 1);
    assertTrue(serializesCorrectly(odmap, "o2p-d-2"));
    odmap.put(Double.valueOf(Double.MIN_VALUE), Double.MIN_VALUE);
    assertTrue(serializesCorrectly(odmap, "o2p-d-3"));
    odmap.put(Double.valueOf(Double.MAX_VALUE), Double.MAX_VALUE);
    assertTrue(serializesCorrectly(odmap, "o2p-d-4"));
    odmap.put(Double.valueOf(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY);
    assertTrue(serializesCorrectly(odmap, "o2p-d-5"));
    odmap.put(Double.valueOf(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY);
    assertTrue(serializesCorrectly(odmap, "o2p-d-6"));
    // NOTE: trove doesn't deal well with NaN
    //        ddmap.put( Double.NaN, Double.NaN );
    //        assertTrue( serializesCorrectly( ddmap ) );

    // Float-float
    TObjectFloatHashMap<Float> ofmap = new TObjectFloatHashMap<Float>();
    assertTrue(serializesCorrectly(ofmap, "o2p-f-1"));
    ofmap.put(Float.valueOf(0), 1);
    assertTrue(serializesCorrectly(ofmap, "o2p-f-2"));
    ofmap.put(Float.valueOf(Float.MIN_VALUE), Float.MIN_VALUE);
    assertTrue(serializesCorrectly(ofmap, "o2p-f-3"));
    ofmap.put(Float.valueOf(Float.MAX_VALUE), Float.MAX_VALUE);
    assertTrue(serializesCorrectly(ofmap, "o2p-f-4"));
    ofmap.put(Float.valueOf(Float.POSITIVE_INFINITY), Float.POSITIVE_INFINITY);
    assertTrue(serializesCorrectly(ofmap, "o2p-f-5"));
    ofmap.put(Float.valueOf(Float.NEGATIVE_INFINITY), Float.NEGATIVE_INFINITY);
    assertTrue(serializesCorrectly(ofmap, "o2p-f-6"));
    // NOTE: trove doesn't deal well with NaN
    //        ffmap.put( Float.NaN, Float.NaN );
    //        assertTrue( serializesCorrectly( ffmap ) );
  }
  public void testP2OMap() {
    // Long-long
    TLongObjectHashMap<Long> lomap = new TLongObjectHashMap<Long>();
    assertTrue(serializesCorrectly(lomap, "p2o-l-1"));
    lomap.put(0, Long.valueOf(1));
    assertTrue(serializesCorrectly(lomap, "p2o-l-2"));
    lomap.put(Long.MIN_VALUE, Long.valueOf(Long.MIN_VALUE));
    assertTrue(serializesCorrectly(lomap, "p2o-l-3"));
    lomap.put(Long.MAX_VALUE, Long.valueOf(Long.MAX_VALUE));
    assertTrue(serializesCorrectly(lomap, "p2o-l-4"));

    // Int-int
    TIntObjectHashMap<Integer> iomap = new TIntObjectHashMap<Integer>();
    assertTrue(serializesCorrectly(iomap, "p2o-i-1"));
    iomap.put(0, Integer.valueOf(1));
    assertTrue(serializesCorrectly(iomap, "p2o-i-2"));
    iomap.put(Integer.MIN_VALUE, Integer.valueOf(Integer.MIN_VALUE));
    assertTrue(serializesCorrectly(iomap, "p2o-i-3"));
    iomap.put(Integer.MAX_VALUE, Integer.valueOf(Integer.MAX_VALUE));
    assertTrue(serializesCorrectly(iomap, "p2o-i-4"));

    // Double-double
    TDoubleObjectHashMap<Double> domap = new TDoubleObjectHashMap<Double>();
    assertTrue(serializesCorrectly(domap, "p2o-d-1"));
    domap.put(0, Double.valueOf(1));
    assertTrue(serializesCorrectly(domap, "p2o-d-2"));
    domap.put(Double.MIN_VALUE, Double.valueOf(Double.MIN_VALUE));
    assertTrue(serializesCorrectly(domap, "p2o-d-3"));
    domap.put(Double.MAX_VALUE, Double.valueOf(Double.MAX_VALUE));
    assertTrue(serializesCorrectly(domap, "p2o-d-4"));
    domap.put(Double.POSITIVE_INFINITY, Double.valueOf(Double.POSITIVE_INFINITY));
    assertTrue(serializesCorrectly(domap, "p2o-d-5"));
    domap.put(Double.NEGATIVE_INFINITY, Double.valueOf(Double.NEGATIVE_INFINITY));
    assertTrue(serializesCorrectly(domap, "p2o-d-6"));
    // NOTE: trove doesn't deal well with NaN
    //        ddmap.put( Double.NaN, Double.NaN );
    //        assertTrue( serializesCorrectly( ddmap ) );

    // Float-float
    TFloatObjectHashMap<Float> fomap = new TFloatObjectHashMap<Float>();
    assertTrue(serializesCorrectly(fomap, "p2o-f-1"));
    fomap.put(0, Float.valueOf(1));
    assertTrue(serializesCorrectly(fomap, "p2o-f-2"));
    fomap.put(Float.MIN_VALUE, Float.valueOf(Float.MIN_VALUE));
    assertTrue(serializesCorrectly(fomap, "p2o-f-3"));
    fomap.put(Float.MAX_VALUE, Float.valueOf(Float.MAX_VALUE));
    assertTrue(serializesCorrectly(fomap, "p2o-f-4"));
    fomap.put(Float.POSITIVE_INFINITY, Float.valueOf(Float.POSITIVE_INFINITY));
    assertTrue(serializesCorrectly(fomap, "p2o-f-5"));
    fomap.put(Float.NEGATIVE_INFINITY, Float.valueOf(Float.NEGATIVE_INFINITY));
    assertTrue(serializesCorrectly(fomap, "p2o-f-6"));
    // NOTE: trove doesn't deal well with NaN
    //        ffmap.put( Float.NaN, Float.NaN );
    //        assertTrue( serializesCorrectly( ffmap ) );
  }
Пример #24
0
 private String getNameFromID(Long id) throws IOException {
   if (id.longValue() == 0L) {
     return "";
   }
   String result = names.get(id);
   if (result == null) {
     warn("Name not found at " + toHex(id.longValue()));
     return "unresolved name " + toHex(id.longValue());
   }
   return result;
 }
Пример #25
0
 /**
  * @param file
  * @return
  * @throws IOException
  */
 static long readUnsignedLong(final ERandomAccessFile file) throws IOException {
   final long result = file.readLongE();
   if (result < 0) {
     throw new IOException(
         "Maximal file offset is "
             + Long.toHexString(Long.MAX_VALUE)
             + " given offset is "
             + Long.toHexString(result));
   }
   return result;
 }
Пример #26
0
 @Override
 public int rank(short lowbits) {
   int x = Util.toIntUnsigned(lowbits);
   int leftover = (x + 1) & 63;
   int answer = 0;
   for (int k = 0; k < (x + 1) / 64; ++k) answer += Long.bitCount(bitmap[k]);
   if (leftover != 0) {
     answer += Long.bitCount(bitmap[(x + 1) / 64] << (64 - leftover));
   }
   return answer;
 }
 @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());
   }
 }
Пример #28
0
 @Override
 public int nextAsInt() {
   long t = w & -w;
   int answer = (x + 1) * 64 - 1 - Long.bitCount(t - 1);
   w ^= t;
   while (w == 0) {
     --x;
     if (x < 0) break;
     w = Long.reverse(bitmap[x]);
   }
   return answer;
 }
Пример #29
0
  /** create it and set status */
  protected InMemoInformation(
      String contentType, long lastModified, long creationTime, PeerSTSet recipientSet) {

    try {
      this.setProperty(InMemoInformation.INFO_CONTENT_TYPE, contentType);
      this.setProperty(InMemoInformation.INFO_LAST_MODIFED, Long.toString(lastModified));
      this.setProperty(InMemoInformation.INFO_CREATION_TIME, Long.toString(creationTime));
      this.setProperty(
          InMemoInformation.INFO_ID_PROPERTY_NAME, java.util.UUID.randomUUID().toString());
    } catch (SharkKBException ex) {
      // cannot happen
    }
  }
Пример #30
0
 /** Goes to the current cursor position of the last available cursor. */
 public void gotoLastAvailableCursor() {
   if ((this.mainFrame != null) && this.dataContainer.isCursorsEnabled()) {
     for (int c = CapturedData.MAX_CURSORS - 1; c >= 0; c--) {
       if (this.dataContainer.isCursorPositionSet(c)) {
         final Long cursorPosition = this.dataContainer.getCursorPosition(c);
         if (cursorPosition != null) {
           this.mainFrame.gotoPosition(cursorPosition.longValue());
         }
         break;
       }
     }
   }
 }