java.util.NavigableMap#remove ( )源码实例Demo

下面列出了java.util.NavigableMap#remove ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: journalkeeper   文件: AbstractServer.java
private void compactJournalToSnapshot(long index) {
    logger.info("Compact journal to index: {}...", index);
    try {
        Snapshot snapshot = snapshots.get(index);
        if (null != snapshot) {
            JournalSnapshot journalSnapshot = snapshot.getJournalSnapshot();
            logger.info("Compact journal entries, journal snapshot: {}, journal: {}...", journalSnapshot, journal);
            journal.compact(snapshot.getJournalSnapshot());
            logger.info("Compact journal finished, journal: {}.", journal);

            NavigableMap<Long, Snapshot> headMap = snapshots.headMap(index, false);
            while (!headMap.isEmpty()) {
                snapshot = headMap.remove(headMap.firstKey());
                logger.info("Discard snapshot: {}.", snapshot.getPath());
                snapshot.close();
                snapshot.clear();
            }
        } else {
            logger.warn("Compact journal failed! Cause no snapshot at index: {}.", index);
        }
    } catch (Throwable e) {
        logger.warn("Compact journal exception!", e);
    }
}
 
源代码2 项目: besu   文件: DebugStorageRangeAt.java
private JsonRpcSuccessResponse extractStorageAt(
    final JsonRpcRequestContext requestContext,
    final Address accountAddress,
    final Hash startKey,
    final int limit,
    final MutableWorldState worldState) {
  final Account account = worldState.get(accountAddress);
  final NavigableMap<Bytes32, AccountStorageEntry> entries =
      account.storageEntriesFrom(startKey, limit + 1);

  Bytes32 nextKey = null;
  if (entries.size() == limit + 1) {
    nextKey = entries.lastKey();
    entries.remove(nextKey);
  }
  return new JsonRpcSuccessResponse(
      requestContext.getRequest().getId(),
      new DebugStorageRangeAtResult(entries, nextKey, shortValues));
}
 
源代码3 项目: besu   文件: AbstractWorldUpdater.java
@Override
public NavigableMap<Bytes32, AccountStorageEntry> storageEntriesFrom(
    final Bytes32 startKeyHash, final int limit) {
  final NavigableMap<Bytes32, AccountStorageEntry> entries;
  if (account != null) {
    entries = account.storageEntriesFrom(startKeyHash, limit);
  } else {
    entries = new TreeMap<>();
  }
  updatedStorage.entrySet().stream()
      .map(entry -> AccountStorageEntry.forKeyAndValue(entry.getKey(), entry.getValue()))
      .filter(entry -> entry.getKeyHash().compareTo(startKeyHash) >= 0)
      .forEach(entry -> entries.put(entry.getKeyHash(), entry));

  while (entries.size() > limit) {
    entries.remove(entries.lastKey());
  }
  return entries;
}
 
源代码4 项目: j2objc   文件: TreeSubMapTest.java
/**
 * pollLastEntry returns entries in order
 */
public void testDescendingPollLastEntry() {
    NavigableMap map = dmap5();
    Map.Entry e = map.pollLastEntry();
    assertEquals(m5, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(m4, e.getKey());
    map.put(m5, "E");
    e = map.pollLastEntry();
    assertEquals(m5, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(m3, e.getKey());
    map.remove(m2);
    e = map.pollLastEntry();
    assertEquals(m1, e.getKey());
    try {
        e.setValue("E");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollLastEntry();
    assertNull(e);
}
 
源代码5 项目: openjdk-jdk9   文件: TreeSubMapTest.java
/**
 * pollLastEntry returns entries in order
 */
public void testPollLastEntry() {
    NavigableMap map = map5();
    Map.Entry e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(four, e.getKey());
    map.put(five, "E");
    e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(three, e.getKey());
    map.remove(two);
    e = map.pollLastEntry();
    assertEquals(one, e.getKey());
    try {
        e.setValue("E");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollLastEntry();
    assertNull(e);
}
 
源代码6 项目: symja_android_library   文件: UnitImpl.java
@Override // from Unit
public IUnit add(IUnit unit) {
	NavigableMap<String, IExpr> map = new TreeMap<>(navigableMap);
	for (Entry<String, IExpr> entry : unit.map().entrySet()) {
		String key = entry.getKey();
		IExpr value = entry.getValue();
		if (map.containsKey(key)) {
			// TODO this may not always use the defined UnitHelper.EvalEngine
			IExpr sum = F.Plus.of(UnitHelper.ENGINE, map.get(key), value);
			if (sum.isZero())
				map.remove(key); // exponents cancel out
			else
				map.put(key, sum); // exponent is updated
		} else
			map.put(key, value); // unit is introduced
	}
	return new UnitImpl(map);
}
 
源代码7 项目: j2objc   文件: TreeSubMapTest.java
/**
 * pollLastEntry returns entries in order
 */
public void testPollLastEntry() {
    NavigableMap map = map5();
    Map.Entry e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(four, e.getKey());
    map.put(five, "E");
    e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(three, e.getKey());
    map.remove(two);
    e = map.pollLastEntry();
    assertEquals(one, e.getKey());
    try {
        e.setValue("E");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollLastEntry();
    assertNull(e);
}
 
源代码8 项目: kareldb   文件: VersionedCache.java
public boolean setCommit(Comparable[] key, long version, long commit) {
    NavigableMap<Long, VersionedValue> rowData = cache.getOrDefault(key, new ConcurrentSkipListMap<>());
    VersionedValue value = rowData.get(version);
    if (value == null) {
        return false;
    }
    if (commit == INVALID_TX) {
        rowData.remove(version);
    } else {
        rowData.put(version, new VersionedValue(version, commit, value.isDeleted(), value.getValue()));
    }
    garbageCollect(rowData);
    cache.put(key, rowData);
    return true;
}
 
源代码9 项目: sketch   文件: SizeConfigStrategy.java
private void decrementBitmapOfSize(Integer size, Bitmap.Config config) {
    NavigableMap<Integer, Integer> sizes = getSizesForConfig(config);
    Integer current = sizes.get(size);
    if (current == 1) {
        sizes.remove(size);
    } else {
        sizes.put(size, current - 1);
    }
}
 
源代码10 项目: giffun   文件: SizeConfigStrategy.java
private void decrementBitmapOfSize(Integer size, Bitmap.Config config) {
    NavigableMap<Integer, Integer> sizes = getSizesForConfig(config);
    Integer current = sizes.get(size);
    if (current == 1) {
        sizes.remove(size);
    } else {
        sizes.put(size, current - 1);
    }
}
 
源代码11 项目: teku   文件: ScheduledDuties.java
private void performDutyForSlot(
    final NavigableMap<UnsignedLong, ? extends Duty> duties, final UnsignedLong slot) {
  discardDutiesBeforeSlot(duties, slot);

  final Duty duty = duties.remove(slot);
  if (duty == null) {
    return;
  }
  duty.performDuty()
      .finish(
          result -> result.report(duty.getProducedType(), slot, VALIDATOR_LOGGER),
          error -> VALIDATOR_LOGGER.dutyFailed(duty.getProducedType(), slot, error));
}
 
源代码12 项目: j2objc   文件: TreeSubMapTest.java
/**
 * remove(null) throws NPE
 */
public void testRemove1_NullPointerException() {
    NavigableMap c = map5();
    try {
        c.remove(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
源代码13 项目: openjdk-jdk9   文件: TreeSubMapTest.java
/**
 * remove removes the correct key-value pair from the map
 */
public void testRemove() {
    NavigableMap map = map5();
    map.remove(five);
    assertEquals(4, map.size());
    assertFalse(map.containsKey(five));
}
 
源代码14 项目: j2objc   文件: TreeSubMapTest.java
/**
 * pollFirstEntry returns entries in order
 */
public void testPollFirstEntry() {
    NavigableMap map = map5();
    Map.Entry e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(two, e.getKey());
    map.put(one, "A");
    e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(three, e.getKey());
    map.remove(four);
    e = map.pollFirstEntry();
    assertEquals(five, e.getKey());
    try {
        e.setValue("A");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    assertTrue(map.isEmpty());
    Map.Entry f = map.firstEntry();
    assertNull(f);
    e = map.pollFirstEntry();
    assertNull(e);
}
 
源代码15 项目: openjdk-jdk9   文件: TreeSubMapTest.java
/**
 * remove removes the correct key-value pair from the map
 */
public void testDescendingRemove() {
    NavigableMap map = dmap5();
    map.remove(m5);
    assertEquals(4, map.size());
    assertFalse(map.containsKey(m5));
}
 
源代码16 项目: j2objc   文件: TreeSubMapTest.java
/**
 * remove removes the correct key-value pair from the map
 */
public void testRemove() {
    NavigableMap map = map5();
    map.remove(five);
    assertEquals(4, map.size());
    assertFalse(map.containsKey(five));
}
 
源代码17 项目: journalkeeper   文件: AbstractServer.java
void installSnapshot(long offset, long lastIncludedIndex, int lastIncludedTerm, byte[] data, boolean isDone) throws IOException, TimeoutException {
    synchronized (partialSnapshot) {
        logger.info("Install snapshot, offset: {}, lastIncludedIndex: {}, lastIncludedTerm: {}, data length: {}, isDone: {}... " +
                        "journal minIndex: {}, maxIndex: {}, commitIndex: {}...",
                ThreadSafeFormat.formatWithComma(offset),
                ThreadSafeFormat.formatWithComma(lastIncludedIndex),
                lastIncludedTerm,
                data.length,
                isDone,
                ThreadSafeFormat.formatWithComma(journal.minIndex()),
                ThreadSafeFormat.formatWithComma(journal.maxIndex()),
                ThreadSafeFormat.formatWithComma(journal.commitIndex())
        );

        Snapshot snapshot;
        long lastApplied = lastIncludedIndex + 1;
        Path snapshotPath = snapshotsPath().resolve(String.valueOf(lastApplied));
        partialSnapshot.installTrunk(offset, data, snapshotPath);

        if (isDone) {
            logger.info("All snapshot files received, discard any existing snapshot with a same or smaller index...");
            // discard any existing snapshot with a same or smaller index
            NavigableMap<Long, Snapshot> headMap = snapshots.headMap(lastApplied, true);
            while (!headMap.isEmpty()) {
                snapshot = headMap.remove(headMap.firstKey());
                logger.info("Discard snapshot: {}.", snapshot.getPath());
                snapshot.close();
                snapshot.clear();
            }
            logger.info("add the installed snapshot to snapshots: {}...", snapshotPath);
            partialSnapshot.finish();
            // add the installed snapshot to snapshots.
            snapshot = new Snapshot(stateFactory, metadataPersistence);
            snapshot.recover(snapshotPath, properties);
            snapshots.put(lastApplied, snapshot);

            logger.info("New installed snapshot: {}.", snapshot.getJournalSnapshot());
            // If existing log entry has same index and term as snapshot’s
            // last included entry, retain log entries following it.
            // Discard the entire log

            logger.info("Compact journal entries, journal: {}...", journal);
            threads.stopThread(threadName(ThreadNames.FLUSH_JOURNAL_THREAD));
            try {
                if (journal.minIndex() >= lastIncludedIndex &&
                        lastIncludedIndex < journal.maxIndex() &&
                        journal.getTerm(lastIncludedIndex) == lastIncludedTerm) {
                    journal.compact(snapshot.getJournalSnapshot());

                } else {
                    journal.clear(snapshot.getJournalSnapshot());
                }
            } finally {
                threads.startThread(threadName(ThreadNames.FLUSH_JOURNAL_THREAD));
            }
            logger.info("Compact journal finished, journal: {}.", journal);

            // Reset state machine using snapshot contents (and load
            // snapshot’s cluster configuration)

            logger.info("Use the new installed snapshot as server's state...");
            stopAndWaitScheduledFeature(flushStateFuture, 1000L);
            threads.stopThread(threadName(ThreadNames.STATE_MACHINE_THREAD));
            try {
                state.close();
                state.clear();
                snapshot.dump(statePath());
                state.recover(statePath(), properties);
            } finally {
                threads.startThread(threadName(ThreadNames.STATE_MACHINE_THREAD));
                flushStateFuture = scheduledExecutor.scheduleAtFixedRate(this::flushState,
                        ThreadLocalRandom.current().nextLong(10L, 50L),
                        config.getFlushIntervalMs(), TimeUnit.MILLISECONDS);
            }
            logger.info("Install snapshot successfully!");
        }
    }
}
 
源代码18 项目: openjdk-jdk9   文件: ConcurrentSkipListMapTest.java
void remove(NavigableMap<Integer, Integer> map, int key) {
    if (map.remove(key) != null)
        bs.clear(key);
}
 
源代码19 项目: j2objc   文件: TreeMapTest.java
void remove(NavigableMap<Integer, Integer> map, int key) {
    if (map.remove(key) != null)
        bs.clear(key);
}
 
源代码20 项目: incubator-heron   文件: KafkaSpout.java
@SuppressWarnings("Duplicates")
@Override
public void ack(Object msgId) {
  long start = System.nanoTime();
  ConsumerRecordMessageId consumerRecordMessageId = (ConsumerRecordMessageId) msgId;
  TopicPartition topicPartition = consumerRecordMessageId.getTopicPartition();
  if (!assignedPartitions.contains(topicPartition)) {
    LOG.info("ignore {} because it's been revoked", consumerRecordMessageId);
    return;
  }
  long offset = consumerRecordMessageId.getOffset();
  ackRegistry.putIfAbsent(topicPartition, new TreeMap<>());
  NavigableMap<Long, Long> navigableMap = ackRegistry.get(topicPartition);

  Map.Entry<Long, Long> floorRange = navigableMap.floorEntry(offset);
  Map.Entry<Long, Long> ceilingRange = navigableMap.ceilingEntry(offset);

  long floorBottom = floorRange != null ? floorRange.getKey() : Long.MIN_VALUE;
  long floorTop = floorRange != null ? floorRange.getValue() : Long.MIN_VALUE;
  long ceilingBottom = ceilingRange != null ? ceilingRange.getKey() : Long.MAX_VALUE;
  long ceilingTop = ceilingRange != null ? ceilingRange.getValue() : Long.MAX_VALUE;

  //the ack is for a message that has already been acknowledged.
  //This happens when a failed tuple has caused
  //Kafka consumer to seek back to earlier position, and some messages are replayed.
  if ((offset >= floorBottom && offset <= floorTop)
      || (offset >= ceilingBottom && offset <= ceilingTop)) {
    return;
  }
  if (ceilingBottom - floorTop == 2) {
    //the ack connects the two adjacent range
    navigableMap.put(floorBottom, ceilingTop);
    navigableMap.remove(ceilingBottom);
  } else if (offset == floorTop + 1) {
    //the acknowledged offset is the immediate neighbour
    // of the upper bound of the floor range
    navigableMap.put(floorBottom, offset);
  } else if (offset == ceilingBottom - 1) {
    //the acknowledged offset is the immediate neighbour
    // of the lower bound of the ceiling range
    navigableMap.remove(ceilingBottom);
    navigableMap.put(offset, ceilingTop);
  } else {
    //it is a new born range
    navigableMap.put(offset, offset);
  }
  LOG.debug("ack {} in {} ns", msgId, System.nanoTime() - start);
  LOG.debug("{}", ackRegistry.get(consumerRecordMessageId.getTopicPartition()));
}