下面列出了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();
}
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;
}
@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);
}
/**
* 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();
}
/**
* containsKey(null) of nonempty map throws NPE
*/
public void testContainsKey_NullPointerException() {
NavigableMap c = map5();
try {
c.containsKey(null);
shouldThrow();
} catch (NullPointerException success) {}
}
/**
* 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();
}
/**
* containsKey(null) of nonempty map throws NPE
*/
public void testContainsKey_NullPointerException() {
NavigableMap c = map5();
try {
c.containsKey(null);
shouldThrow();
} catch (NullPointerException success) {}
}
/**
* 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();
}
/**
* 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;
}