コード例 #1
0
 public void testStandardLastEntry() {
   NavigableMap<String, Integer> forwarding =
       new StandardLastEntryForwardingNavigableMap<String, Integer>(
           new SafeTreeMap<String, Integer>());
   assertNull(forwarding.lastEntry());
   forwarding.put("b", 2);
   assertEquals(immutableEntry("b", 2), forwarding.lastEntry());
   forwarding.put("c", 3);
   assertEquals(immutableEntry("c", 3), forwarding.lastEntry());
   forwarding.put("a", 1);
   assertEquals(immutableEntry("c", 3), forwarding.lastEntry());
   forwarding.remove("c");
   assertEquals(immutableEntry("b", 2), forwarding.lastEntry());
 }
コード例 #2
0
 @Test
 public void testHBColumnMultiVersion() {
   Double[] testNumbers = new Double[] {3.14159, 2.71828, 0.0};
   for (Double n : testNumbers) {
     // Written as unversioned, read as versioned
     Result result = hbMapper.writeValueAsResult(new CrawlNoVersion("key").setF1(n));
     Crawl versioned = hbMapper.readValue(result, Crawl.class);
     NavigableMap<Long, Double> columnHistory = versioned.getF1();
     assertEquals("Column history size mismatch", 1, columnHistory.size());
     assertEquals(
         String.format(
             "Inconsistency between %s and %s",
             HBColumn.class.getSimpleName(), HBColumnMultiVersion.class.getSimpleName()),
         n,
         columnHistory.lastEntry().getValue());
     // Written as versioned, read as unversioned
     Result result1 =
         hbMapper.writeValueAsResult(
             new Crawl("key")
                 .addF1(Double.MAX_VALUE)
                 .addF1(Double.MAX_VALUE)
                 .addF1(Double.MAX_VALUE)
                 .addF1(n));
     CrawlNoVersion unversioned = hbMapper.readValue(result1, CrawlNoVersion.class);
     Double f1 = unversioned.getF1();
     assertEquals(
         String.format(
             "Inconsistency between %s and %s",
             HBColumnMultiVersion.class.getSimpleName(), HBColumn.class.getSimpleName()),
         n,
         f1);
   }
 }
コード例 #3
0
 @CollectionSize.Require(ZERO)
 public void testEmptyMapLast() {
   assertNull(navigableMap.lastEntry());
   try {
     assertNull(navigableMap.lastKey());
     fail();
   } catch (NoSuchElementException e) {
   }
 }
コード例 #4
0
ファイル: StorageLayer.java プロジェクト: jaasilva/TomP2P
 private NavigableMap<Number640, Data> getLatestInternalOrig(NavigableMap<Number640, Data> input) {
   // delete all predecessors
   NavigableMap<Number640, Data> result = new TreeMap<Number640, Data>();
   while (!input.isEmpty()) {
     // first entry is a latest version
     Entry<Number640, Data> latest = input.lastEntry();
     // store in results list
     result.put(latest.getKey(), latest.getValue());
     // delete all predecessors of latest entry
     deletePredecessors(latest.getKey(), input);
   }
   return result;
 }
コード例 #5
0
  // -----------------------------------------------------------------------
  // getVersions(String)
  // -----------------------------------------------------------------------
  @Test
  public void test_getVersions_String() {
    NavigableMap<String, ZoneRules> versions = ZoneRulesProvider.getVersions("Europe/London");
    assertTrue(versions.size() >= 1);
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(versions.lastEntry().getValue(), rules);

    NavigableMap<String, ZoneRules> copy = new TreeMap<>(versions);
    versions.clear();
    assertEquals(versions.size(), 0);
    NavigableMap<String, ZoneRules> versions2 = ZoneRulesProvider.getVersions("Europe/London");
    assertEquals(versions2, copy);
  }
コード例 #6
0
 /**
  * Convert from an offset and length flag pair to a token range.
  *
  * @param offset the {@code 0}-based offset in characters
  * @param length the length in characters
  * @return the {@code 0}-based {@link Range} of tokens
  * @throws FormatterException
  */
 Range<Integer> characterRangeToTokenRange(int offset, int length) throws FormatterException {
   int requiredLength = offset + length;
   if (requiredLength > text.length()) {
     throw new FormatterException(
         String.format(
             "invalid length %d, offset + length (%d) is outside the file",
             requiredLength, requiredLength));
   }
   if (length <= 0) {
     return Formatter.EMPTY_RANGE;
   }
   NavigableMap<Integer, JavaInput.Token> map = getPositionTokenMap();
   Map.Entry<Integer, JavaInput.Token> tokenEntryLo =
       firstNonNull(map.floorEntry(offset), map.firstEntry());
   Map.Entry<Integer, JavaInput.Token> tokenEntryHi =
       firstNonNull(map.ceilingEntry(offset + length - 1), map.lastEntry());
   return Range.closedOpen(
       tokenEntryLo.getValue().getTok().getIndex(),
       tokenEntryHi.getValue().getTok().getIndex() + 1);
 }
コード例 #7
0
  public Word getNextWord(String previousWord, boolean limit) throws Exception {
    if (weightsMap.isEmpty()) {
      return new Word(null, 1.0);
    }
    if (null == previousWord || previousWord.equals(weightsMap.lastEntry().getValue().getValue())) {
      if (!limit) {
        return weightsMap.firstEntry().getValue();
      }
      throw new LimitReachedException(
          previousWord, "Last word in dictionary \"" + name + "\" already reached.");
    }

    Iterator<Word> iterator = weightsMap.values().iterator();
    while (iterator.hasNext()) {
      if (previousWord.equals(iterator.next().getValue())) {
        return iterator.next();
      }
    }
    throw new Exception(
        "No previous word \"" + previousWord + "\" was found in dictionary \"" + name + "\".");
  }
コード例 #8
0
 @CollectionSize.Require(SEVERAL)
 public void testLast() {
   assertEquals(c, navigableMap.lastEntry());
   assertEquals(c.getKey(), navigableMap.lastKey());
 }
コード例 #9
0
 @CollectionSize.Require(ONE)
 public void testSingletonMapLast() {
   assertEquals(a, navigableMap.lastEntry());
   assertEquals(a.getKey(), navigableMap.lastKey());
 }
コード例 #10
0
 @Override
 public int max() {
   return casesMap.lastEntry().getKey();
 }