Java Code Examples for java.util.NavigableMap#containsKey()

The following examples show how to use java.util.NavigableMap#containsKey() . 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: ComponentServiceImpl.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Match a set of strings of new types to be imported against the set of existing extensions
 * based on package names and type names. This method returns a set of old extensions that
 * are a subset of the new types based on the type names. For example, if you have an old
 * extension com.foo.Bar and you import a new extension that is package name com.foo, then we
 * will need to check that com.foo.Bar is inside com.foo and, if so, perform an upgrade.
 *
 * @param existing Existing set of extensions in the project
 * @param newTypes New type(s) defined by the extension being imported
 * @return A subset of the existing extensions that will need to be checked against the new
 * extension to determine whether we are performing an upgrade or adding a fresh extension.
 */
private static Set<String> matchExtensions(NavigableMap<String, Set<String>> existing,
    Set<String> newTypes) {
  Set<String> results = new HashSet<>();
  String packageName = getPackageName(newTypes.iterator().next());
  if (existing.containsKey(packageName)) {
    results.add(packageName);
  }
  NavigableMap<String, Set<String>> related = existing.tailMap(packageName, true);
  for (String k : related.navigableKeySet()) {
    if (!k.startsWith(packageName)) {
      break;  // no longer in the same package
    }
    results.add(k);
  }
  return results;
}
 
Example 2
Source File: JavaProjectPipelineOptionsHierarchy.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
public NavigableMap<PipelineOptionsType, Set<PipelineOptionsProperty>> getOptionsHierarchy(
    String... typeNames) {
  NavigableMap<PipelineOptionsType, Set<PipelineOptionsProperty>> result =
      new TreeMap<>(new PipelineOptionsTypeWeightOrdering());
  Queue<PipelineOptionsType> optionsTypesToAdd = new ArrayDeque<>();
  for (String typeName : typeNames) {
    if (!Strings.isNullOrEmpty(typeName)) {
      PipelineOptionsType pipelineOptionsType = getPipelineOptionsType(typeName);
      if (pipelineOptionsType != null) {
        optionsTypesToAdd.add(pipelineOptionsType);
      }
    }
  }
  while (!optionsTypesToAdd.isEmpty()) {
    PipelineOptionsType type = optionsTypesToAdd.poll();
    if (!result.containsKey(type)) {
      result.put(type, type.getDeclaredProperties());
      optionsTypesToAdd.addAll(type.getDirectSuperInterfaces());
    }
  }
  return result.descendingMap();
}
 
Example 3
Source File: BaseVersionManager.java    From Hive2Hive with MIT License 6 votes vote down vote up
protected NavigableMap<Number160, Set<Number160>> buildDigest(Map<PeerAddress, DigestResult> rawDigest) {
	NavigableMap<Number160, Set<Number160>> digestMap = new TreeMap<Number160, Set<Number160>>();
	if (rawDigest == null) {
		return digestMap;
	}
	for (PeerAddress peerAddress : rawDigest.keySet()) {
		NavigableMap<Number640, Collection<Number160>> tmp = rawDigest.get(peerAddress).keyDigest();
		if (tmp == null || tmp.isEmpty()) {
			// ignore this peer
		} else {
			for (Number640 key : tmp.keySet()) {
				for (Number160 bKey : tmp.get(key)) {
					if (!digestMap.containsKey(key.versionKey())) {
						digestMap.put(key.versionKey(), new HashSet<Number160>());
					}
					digestMap.get(key.versionKey()).add(bKey);
				}
			}
		}
	}
	return digestMap;
}
 
Example 4
Source File: UnitImpl.java    From symja_android_library with GNU General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example 5
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns message sequence number in the folder by its UID.
 * 
 * @param uid - message UID.
 * @return message sequence number.
 * @throws FolderException if no message with given UID.
 */
@Override
public int getMsn(long uid) throws FolderException
{
    NavigableMap<Long, FileInfo> messages = searchMails();
    if (!messages.containsKey(uid))
    {
        throw new FolderException("No such message.");            
    }
    return messages.headMap(uid, true).size();
}
 
Example 6
Source File: TreeSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * containsKey(null) of nonempty map throws NPE
 */
public void testContainsKey_NullPointerException() {
    NavigableMap c = map5();
    try {
        c.containsKey(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 7
Source File: RobotSerializer.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor. Note that the defaultprotocol version must occur in the map
 * of {@link Gson}s.
 *
 * @param gsons an map of {@link Gson}s for serializing and deserializing
 *     JSON, keyed by protocol version.
 * @param defaultProtocolVersion the default protocol version.
 */
public RobotSerializer(NavigableMap<ProtocolVersion, Gson> gsons,
    ProtocolVersion defaultProtocolVersion) {
  if (!gsons.containsKey(defaultProtocolVersion)) {
    throw new IllegalArgumentException(
        "The serializer map does not contain a serializer for the default protocol version");
  }
  this.gsons = gsons;
  this.defaultProtocolVersion = defaultProtocolVersion;
  this.jsonParser = new JsonParser();
}
 
Example 8
Source File: TreeSubMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * containsKey(null) of nonempty map throws NPE
 */
public void testContainsKey_NullPointerException() {
    NavigableMap c = map5();
    try {
        c.containsKey(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 9
Source File: RobotSerializer.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor. Note that the defaultprotocol version must occur in the map
 * of {@link Gson}s.
 *
 * @param gsons an map of {@link Gson}s for serializing and deserializing
 *     JSON, keyed by protocol version.
 * @param defaultProtocolVersion the default protocol version.
 */
public RobotSerializer(NavigableMap<ProtocolVersion, Gson> gsons,
    ProtocolVersion defaultProtocolVersion) {
  if (!gsons.containsKey(defaultProtocolVersion)) {
    throw new IllegalArgumentException(
        "The serializer map does not contain a serializer for the default protocol version");
  }
  this.gsons = gsons;
  this.defaultProtocolVersion = defaultProtocolVersion;
  this.jsonParser = new JsonParser();
}
 
Example 10
Source File: IndexSegmentTest.java    From ambry with Apache License 2.0 5 votes vote down vote up
/**
 * Generates {@code count} unique ids that arent in {@code referenceIndex}.
 * @param referenceIndex the current reference index
 * @param count the number of unique ids to generate
 * @return a set with {@code count} unique ids
 */
private List<MockId> generateIds(NavigableMap<MockId, NavigableSet<IndexValue>> referenceIndex, int count) {
  List<MockId> generatedIds = new ArrayList<>();
  for (int i = 0; i < count; i++) {
    MockId id;
    do {
      id = new MockId(TestUtils.getRandomString(CUSTOM_ID_SIZE));
    } while (referenceIndex.containsKey(id) || generatedIds.contains(id));
    generatedIds.add(id);
  }
  return generatedIds;
}