Java Code Examples for java.util.NavigableSet#remove()

The following examples show how to use java.util.NavigableSet#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BadQueryHistoryManager.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public BadQueryHistory upsertEntryToProject(BadQueryEntry badQueryEntry, String project) throws IOException {
    if (StringUtils.isEmpty(project) || badQueryEntry.getAdj() == null || badQueryEntry.getSql() == null)
        throw new IllegalArgumentException();

    BadQueryHistory badQueryHistory = getBadQueriesForProject(project);
    NavigableSet<BadQueryEntry> entries = badQueryHistory.getEntries();
    
    entries.remove(badQueryEntry); // in case the entry already exists and this call means to update
    
    entries.add(badQueryEntry);
    
    int maxSize = kylinConfig.getBadQueryHistoryNum();
    if (entries.size() > maxSize) {
        entries.pollFirst();
    }

    getStore().checkAndPutResource(badQueryHistory.getResourcePath(), badQueryHistory, BAD_QUERY_INSTANCE_SERIALIZER);
    return badQueryHistory;
}
 
Example 2
Source File: BadQueryHistoryManager.java    From kylin with Apache License 2.0 6 votes vote down vote up
public BadQueryHistory upsertEntryToProject(BadQueryEntry badQueryEntry, String project) throws IOException {
    if (StringUtils.isEmpty(project) || badQueryEntry.getAdj() == null || badQueryEntry.getSql() == null)
        throw new IllegalArgumentException();

    BadQueryHistory badQueryHistory = getBadQueriesForProject(project);
    NavigableSet<BadQueryEntry> entries = badQueryHistory.getEntries();
    
    entries.remove(badQueryEntry); // in case the entry already exists and this call means to update
    
    entries.add(badQueryEntry);
    
    int maxSize = kylinConfig.getBadQueryHistoryNum();
    if (entries.size() > maxSize) {
        entries.pollFirst();
    }

    getStore().checkAndPutResource(badQueryHistory.getResourcePath(), badQueryHistory, BAD_QUERY_INSTANCE_SERIALIZER);
    return badQueryHistory;
}
 
Example 3
Source File: BTreeMapNavigableTest.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
public void testNavigableKeySet() {
	navigableMap.put("ka", "xx");
	navigableMap.put("kb", "aa");
	navigableMap.put("kc", "zz");
	final NavigableSet<String> navigableSet = navigableMap
			.navigableKeySet();
	assertEquals("bad first element", "ka", navigableSet.first());
	assertEquals("bad last element", "kc", navigableSet.last());
	assertTrue(MUST_CONTAINS_KA, navigableSet.contains("ka"));
	assertTrue(MUST_CONTAINS_KB, navigableSet.contains("kb"));
	assertTrue(MUST_CONTAINS_KC, navigableSet.contains("kc"));

	navigableSet.remove("kb");
	assertEquals(BAD_SIZE, 2, navigableMap.size());
	assertFalse(MUST_NOT_BE_EMPTY, navigableMap.isEmpty());
	assertTrue("must contains key 'ka'", navigableMap.containsKey("ka"));
	assertFalse("must not contains key 'kb'", navigableMap
			.containsKey("kb"));
	assertTrue("must contains key 'kc'", navigableMap.containsKey("kc"));
}
 
Example 4
Source File: WatermarkManager.java    From beam with Apache License 2.0 6 votes vote down vote up
/**
 * For each (Object, NavigableSet) pair in the provided map, remove each Timer that is before the
 * latestTime argument and put in in the result with the same key, then remove all of the keys
 * which have no more pending timers.
 *
 * <p>The result collection retains ordering of timers (from earliest to latest).
 */
private static Map<StructuralKey<?>, List<TimerData>> extractFiredTimers(
    Instant latestTime, Map<StructuralKey<?>, NavigableSet<TimerData>> objectTimers) {
  Map<StructuralKey<?>, List<TimerData>> result = new HashMap<>();
  Set<StructuralKey<?>> emptyKeys = new HashSet<>();
  for (Map.Entry<StructuralKey<?>, NavigableSet<TimerData>> pendingTimers :
      objectTimers.entrySet()) {
    NavigableSet<TimerData> timers = pendingTimers.getValue();
    if (!timers.isEmpty() && timers.first().getTimestamp().isBefore(latestTime)) {
      ArrayList<TimerData> keyFiredTimers = new ArrayList<>();
      result.put(pendingTimers.getKey(), keyFiredTimers);
      while (!timers.isEmpty() && timers.first().getTimestamp().isBefore(latestTime)) {
        keyFiredTimers.add(timers.first());
        timers.remove(timers.first());
      }
    }
    if (timers.isEmpty()) {
      emptyKeys.add(pendingTimers.getKey());
    }
  }
  objectTimers.keySet().removeAll(emptyKeys);
  return result;
}
 
Example 5
Source File: Chapter07Concurrency02.java    From Java-11-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
private static void demoNavigableSetRemove(NavigableSet<Integer> set) {
    System.out.println("set: " + set);
    try {
        for (int i : set) {
            System.out.println(i);
            System.out.println("Calling set.remove(2)...");
            set.remove(2);
        }
    } catch (Exception ex) {
        System.out.println(ex.getClass().getName());
    }
    System.out.println("set: " + set);
}
 
Example 6
Source File: Chapter07Concurrency02.java    From Java-9-Cookbook with MIT License 5 votes vote down vote up
private static void demoNavigableSetRemove(NavigableSet<Integer> set) {
    System.out.println("set: " + set);
    try {
        for (int i : set) {
            System.out.println(i);
            System.out.println("Calling set.remove(2)...");
            set.remove(2);
        }
    } catch (Exception ex) {
        System.out.println(ex.getClass().getName());
    }
    System.out.println("set: " + set);
}
 
Example 7
Source File: BTreeMapNavigable2Test.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public void testNavigableKeySet()
{
	int size0 = map.size();
	NavigableSet<Integer> keySet = map.navigableKeySet();
	int size1 = keySet.size();
	assertEquals(size0, size1);
	
	keySet.remove(2);
	size0 = map.size();
	size1 = keySet.size();
	assertEquals(size0, size1);
	assertNull(map.get(2));
}
 
Example 8
Source File: InMemoryTimerInternals.java    From beam with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated use {@link #setTimer(StateNamespace, String, String, Instant, Instant,
 *     TimeDomain)}.
 */
@Deprecated
@Override
public void setTimer(TimerData timerData) {
  WindowTracing.trace("{}.setTimer: {}", getClass().getSimpleName(), timerData);

  @Nullable
  TimerData existing =
      existingTimers.get(
          timerData.getNamespace(), timerData.getTimerId() + '+' + timerData.getTimerFamilyId());
  if (existing == null) {
    existingTimers.put(
        timerData.getNamespace(),
        timerData.getTimerId() + '+' + timerData.getTimerFamilyId(),
        timerData);
    timersForDomain(timerData.getDomain()).add(timerData);
  } else {
    checkArgument(
        timerData.getDomain().equals(existing.getDomain()),
        "Attempt to set %s for time domain %s, but it is already set for time domain %s",
        timerData.getTimerId(),
        timerData.getDomain(),
        existing.getDomain());

    if (!timerData.getTimestamp().equals(existing.getTimestamp())) {
      NavigableSet<TimerData> timers = timersForDomain(timerData.getDomain());
      timers.remove(existing);
      timers.add(timerData);
      existingTimers.put(
          timerData.getNamespace(),
          timerData.getTimerId() + '+' + timerData.getTimerFamilyId(),
          timerData);
    }
  }
}
 
Example 9
Source File: MembershipView.java    From rapid with Apache License 2.0 5 votes vote down vote up
/**
 * Delete a host from all K rings.
 *
 * @param node the host to be removed
 */
void ringDelete(final Endpoint node) {
    Objects.requireNonNull(node);
    rwLock.writeLock().lock();
    try {

        if (!rings.get(0).contains(node)) {
            throw new NodeNotInRingException(node);
        }

        final Set<Endpoint> affectedSubjects = new HashSet<>();

        for (int k = 0; k < K; k++) {
            final NavigableSet<Endpoint> endpoints = rings.get(k);

            final Endpoint oldSubject = endpoints.lower(node);
            if (oldSubject != null) {
                affectedSubjects.add(oldSubject);
            }

            endpoints.remove(node);

            addressComparators.get(k).removeEndpoint(node);
            cachedObservers.remove(node);
        }
        allNodes.remove(node);

        for (final Endpoint subject : affectedSubjects) {
            cachedObservers.remove(subject);
        }

        shouldUpdateConfigurationId = true;
    } finally {
        rwLock.writeLock().unlock();
    }
}
 
Example 10
Source File: ConcurrentSkipListSetTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
void remove(NavigableSet<Integer> set, int element, BitSet bs) {
    if (set.remove(element))
        bs.clear(element);
}
 
Example 11
Source File: TreeSetTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
void remove(NavigableSet<Integer> set, int element) {
    if (set.remove(element))
        bs.clear(element);
}
 
Example 12
Source File: ConcurrentSkipListSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
void remove(NavigableSet<Integer> set, int element, BitSet bs) {
    if (set.remove(element))
        bs.clear(element);
}
 
Example 13
Source File: GrammarConstraintProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Computing the lower bound for a given feature is equivalent to the shortest path problem in the
 * corresponding automaton graph. Dijkstra's algorithm solves this in quadratic time to the number
 * of nodes.
 */
private int computeLowerBound(int featureId) {
	ISemState currentNode = nfa.getStart();
	final ISemState stopNode = nfa.getStop();
	final Map<ISemState, DijkstraNode> idAndDistance = Maps.newHashMap();
	idAndDistance.put(currentNode, new DijkstraNode());
	// The unvisited nodes are sorted by their tentative distance.
	// Nodes with equal distance still have to be separated, which is achieved with the id value. 
	NavigableSet<ISemState> unvisited = new TreeSet<>(Comparator.comparing((s) -> {
		return idAndDistance.get(s).distance;
	}).thenComparing((s) -> {
		return idAndDistance.get(s).id;
	}));
	int nextStateId = 1;
	do {
		int currentDistance = idAndDistance.get(currentNode).distance;
		if (currentNode == stopNode) {
			// We have reached the stop node and thus know the shortest path from start to stop.
			return currentDistance;
		}
		for (ISemState follower : currentNode.getFollowers()) {
			DijkstraNode fdn = idAndDistance.get(follower);
			// The cost of proceeding to this follower is 1 iff it has the correct feature id.
			int increment = follower.getFeatureID() == featureId ? 1 : 0;
			if (fdn == null) {
				// We haven't reached this node before. Assign a new id and distance and mark as unvisited.
				fdn = new DijkstraNode();
				fdn.id = nextStateId++;
				fdn.distance = currentDistance + increment;
				idAndDistance.put(follower, fdn);
				unvisited.add(follower);
			} else {
				// This follower node has already been reached.
				fdn.distance = Math.min(fdn.distance, currentDistance + increment);
				if (unvisited.remove(follower)) {
					// The position of the follower in the sorted set must be updated.
					unvisited.add(follower);
				}
			}
		}
		unvisited.remove(currentNode);
		// Choose the unvisited node with the lowest tentative distance.
		currentNode = unvisited.pollFirst();
	} while (currentNode != null);
	// If we get to this point, the stop state is not reachable from the start.
	throw new AssertionError("Stop state is not reachable.");
}
 
Example 14
Source File: ConcurrentSkipListSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
void remove(NavigableSet<Integer> set, int element, BitSet bs) {
    if (set.remove(element))
        bs.clear(element);
}
 
Example 15
Source File: BTreeSet2Test.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
void remove(NavigableSet<Integer> set, int element, BitSet bs) {
    if (set.remove(element))
        bs.clear(element);
}
 
Example 16
Source File: ConcurrentSkipListSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
void remove(NavigableSet<Integer> set, int element, BitSet bs) {
    if (set.remove(element))
        bs.clear(element);
}
 
Example 17
Source File: TreeSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
void remove(NavigableSet<Integer> set, int element) {
    if (set.remove(element))
        bs.clear(element);
}