<K, V> void testNavigationAgainstExpected(
     NavigableMap<K, V> expected, NavigableMap<K, V> navigableMap, Iterable<K> keysToTest) {
   for (K key : keysToTest) {
     assertEquals(expected.lowerEntry(key), navigableMap.lowerEntry(key));
     assertEquals(expected.floorEntry(key), navigableMap.floorEntry(key));
     assertEquals(expected.ceilingEntry(key), navigableMap.ceilingEntry(key));
     assertEquals(expected.higherEntry(key), navigableMap.higherEntry(key));
     for (boolean inclusive : new boolean[] {false, true}) {
       ASSERT
           .that(navigableMap.headMap(key, inclusive).entrySet())
           .has()
           .allFrom(expected.headMap(key, inclusive).entrySet())
           .inOrder();
       ASSERT
           .that(navigableMap.tailMap(key, inclusive).entrySet())
           .has()
           .allFrom(expected.tailMap(key, inclusive).entrySet())
           .inOrder();
       ASSERT
           .that(navigableMap.headMap(key, inclusive).descendingMap().entrySet())
           .has()
           .allFrom(expected.headMap(key, inclusive).descendingMap().entrySet())
           .inOrder();
       ASSERT
           .that(navigableMap.tailMap(key, inclusive).descendingMap().entrySet())
           .has()
           .allFrom(expected.tailMap(key, inclusive).descendingMap().entrySet())
           .inOrder();
     }
   }
 }
예제 #2
0
파일: OCPAgent.java 프로젝트: ccbon/ocp
  public Queue<Contact> makeContactQueue(Id key) throws Exception {
    Queue<Contact> contactQueue = new LinkedList<Contact>();
    NavigableMap<Id, OCPContact> nodeMap = new TreeMap<Id, OCPContact>(this.nodeMap);
    if (nodeMap.containsKey(key)) {
      contactQueue.offer(nodeMap.get(key));
    }

    NavigableMap<Id, OCPContact> s = nodeMap.headMap(key, false);
    Iterator<Id> it = s.navigableKeySet().descendingIterator();
    while (it.hasNext()) {
      Id nodeId = it.next();
      OCPContact contact = s.get(nodeId);
      if (!contactQueue.contains(contact)) {
        contactQueue.offer(contact);
      }
    }
    s = nodeMap.tailMap(key, false);
    it = s.navigableKeySet().descendingIterator();
    while (it.hasNext()) {
      Id nodeId = it.next();
      OCPContact contact = s.get(nodeId);
      if (!contactQueue.contains(contact)) {
        contactQueue.offer(contact);
      }
    }
    return contactQueue;
  }
 @Override
 NavigableMap<K, V> createSubMap(SortedMap<K, V> sortedMap, K firstExclusive, K lastExclusive) {
   NavigableMap<K, V> map = (NavigableMap<K, V>) sortedMap;
   if (from == Bound.NO_BOUND && to == Bound.INCLUSIVE) {
     return map.headMap(lastInclusive, true);
   } else if (from == Bound.EXCLUSIVE && to == Bound.NO_BOUND) {
     return map.tailMap(firstExclusive, false);
   } else if (from == Bound.EXCLUSIVE && to == Bound.EXCLUSIVE) {
     return map.subMap(firstExclusive, false, lastExclusive, false);
   } else if (from == Bound.EXCLUSIVE && to == Bound.INCLUSIVE) {
     return map.subMap(firstExclusive, false, lastInclusive, true);
   } else if (from == Bound.INCLUSIVE && to == Bound.INCLUSIVE) {
     return map.subMap(firstInclusive, true, lastInclusive, true);
   } else {
     return (NavigableMap<K, V>) super.createSubMap(map, firstExclusive, lastExclusive);
   }
 }
예제 #4
0
    @Override
    public void remove() {
      if (currentRemoved)
        throw new IllegalStateException("Current element has already been removed");

      if (currentValue == null)
        throw new IllegalStateException("Next method was not called for given iterator");

      if (removeFromNewEntries(currentValue)) {
        if (size >= 0) size--;
      } else {
        Change counter = changedValues.get(currentValue);
        if (counter != null) {
          counter.decrement();
          if (size >= 0)
            if (counter.isUndefined()) size = -1;
            else size--;
        } else {
          if (nextChange != null) {
            changedValues.put(currentValue, new DiffChange(-1));
            changedValuesIterator =
                changedValues.tailMap(nextChange.getKey(), false).entrySet().iterator();
          } else {
            changedValues.put(currentValue, new DiffChange(-1));
          }

          size = -1;
        }
      }

      if (OSBTreeRidBag.this.owner != null)
        ORecordInternal.unTrack(OSBTreeRidBag.this.owner, currentValue);

      if (updateOwner)
        fireCollectionChangedEvent(
            new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>(
                OMultiValueChangeEvent.OChangeType.REMOVE,
                currentValue,
                null,
                currentValue,
                false));
      currentRemoved = true;
    }
예제 #5
0
  /**
   * lowInclusive and highInclusive are ignored if the respective bound in null (unbounded).
   *
   * @param low
   * @param lowInclusive
   * @param high
   * @param highInclusive
   * @return
   */
  public RangeApacheLogEntryIterator getIterator(
      Date low, Date high, boolean lowInclusive, boolean highInclusive) {
    NavigableMap<Date, File> subMap = dateToFile;

    Date adjustedLow = low == null ? null : dateToFile.floorKey(low);
    Date adjustedHigh = high == null ? null : dateToFile.ceilingKey(high);

    // lower bound
    if (adjustedLow != null) {
      subMap = subMap.tailMap(adjustedLow, true);
    }

    // upperbound
    if (adjustedHigh != null) {
      subMap = subMap.headMap(adjustedHigh, true);
    }

    logger.debug(
        "Adjust: Creating an iterator from "
            + adjustedLow
            + " until "
            + adjustedHigh
            + "; spanning "
            + subMap.size()
            + " files.");
    logger.debug(
        "Creating an iterator from "
            + low
            + " until "
            + high
            + "; spanning "
            + subMap.size()
            + " files.");

    return new RangeApacheLogEntryIterator(
        subMap.entrySet().iterator(), low, lowInclusive, high, highInclusive);
  }
예제 #6
0
  @Override
  public Records recordsNewerThan(
      DateTime changeSetTime, boolean inclusive, boolean descendingOrder) {
    if (stopped) {
      return Records.EMPTY;
    }

    long changeSetMillisUTC = -1;
    long searchBound = -1;
    if (changeSetTime != null) {
      changeSetMillisUTC = changeSetTime.getMillis();
      // adjust the millis using a delta so that we are sure we catch everything in a cluster which
      // may have differences in
      // clock time
      searchBound = TIME_BASED_KEYS.getCounterStartingAt(changeSetMillisUTC - searchTimeDelta);
    }

    NavigableMap<Long, JournalRecord> subMap = records.tailMap(searchBound, true);

    // process each of the records from the result and look at the timestamp of the changeset, so
    // that we're sure we only include
    // the correct ones (we used a delta to make sure we get everything)
    long startKeyInSubMap = -1;
    for (Long timeBasedKey : subMap.keySet()) {
      JournalRecord record = subMap.get(timeBasedKey);
      long recordChangeTimeMillisUTC = record.getChangeTimeMillis();
      if (((recordChangeTimeMillisUTC == changeSetMillisUTC) && inclusive)
          || recordChangeTimeMillisUTC > changeSetMillisUTC) {
        startKeyInSubMap = timeBasedKey;
        break;
      }
    }
    return startKeyInSubMap != -1
        ? recordsFrom(subMap.tailMap(startKeyInSubMap, true), descendingOrder)
        : Records.EMPTY;
  }
 public void testTailMap_K_B() {
   NavigableMap<String, Integer> map = create();
   NavigableMap<String, Integer> subMap = map.tailMap("a", true);
   assertTrue(subMap instanceof SynchronizedNavigableMap);
   assertSame(mutex, ((SynchronizedNavigableMap<String, Integer>) subMap).mutex);
 }