containsKey ( )源码实例Demo

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

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

/**
 * 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;
}
 
@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();
}
 
源代码3 项目: Hive2Hive   文件: BaseVersionManager.java
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;
}
 
源代码4 项目: 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);
}
 
源代码5 项目: alfresco-repository   文件: AlfrescoImapFolder.java
/**
 * 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();
}
 
源代码6 项目: openjdk-jdk9   文件: TreeSubMapTest.java
/**
 * containsKey(null) of nonempty map throws NPE
 */
public void testContainsKey_NullPointerException() {
    NavigableMap c = map5();
    try {
        c.containsKey(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
源代码7 项目: swellrt   文件: RobotSerializer.java
/**
 * 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();
}
 
源代码8 项目: j2objc   文件: TreeSubMapTest.java
/**
 * containsKey(null) of nonempty map throws NPE
 */
public void testContainsKey_NullPointerException() {
    NavigableMap c = map5();
    try {
        c.containsKey(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
源代码9 项目: incubator-retired-wave   文件: RobotSerializer.java
/**
 * 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();
}
 
源代码10 项目: ambry   文件: IndexSegmentTest.java
/**
 * 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;
}