/** * Returns an unmodifiable map backed by the given map. * <p> * This method uses the implementation in the decorators subpackage. * * @param <K> the key type * @param <V> the value type * @param map the map to make unmodifiable, must not be null * @return an unmodifiable map backed by the given map * @throws NullPointerException if the map is null */ public static <K, V> Map<K, V> unmodifiableMap(final Map<? extends K, ? extends V> map) { return UnmodifiableMap.unmodifiableMap(map); }
/** * Factory method to create an unmodifiable map. * * @param <K> the key type * @param <V> the value type * @param map the map to decorate, must not be null * @return a new unmodifiable map * @throws NullPointerException if map is null * @since 4.0 */ public static <K, V> Map<K, V> unmodifiableMap(final Map<? extends K, ? extends V> map) { if (map instanceof Unmodifiable) { @SuppressWarnings("unchecked") // safe to upcast final Map<K, V> tmpMap = (Map<K, V>) map; return tmpMap; } return new UnmodifiableMap<>(map); }
if (this.version == other.version && this.localLsnByRegion.size() != other.localLsnByRegion.size()) { throw new InternalServerErrorException( String.format(RMResources.InvalidRegionsInSessionToken, this.sessionToken, other.sessionToken)); for (Map.Entry<Integer, Long> kvp : sessionTokenWithHigherVersion.localLsnByRegion.entrySet()) { Integer regionId = kvp.getKey(); Math.max(this.version, other.version), Math.max(this.globalLsn, other.globalLsn), (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(highestLocalLsnByRegion));
Character.toString(VectorSessionToken.SegmentSeparator), localLsnByRegion. entrySet() .stream() .map(kvp -> String.format("%s%s%s",
private boolean areRegionProgressEqual(UnmodifiableMap<Integer, Long> other) { if (this.localLsnByRegion.size() != other.size()) { return false; } for (Map.Entry<Integer, Long> kvp : this.localLsnByRegion.entrySet()) { Integer regionId = kvp.getKey(); ValueHolder<Long> localLsn1 = ValueHolder.initialize(kvp.getValue()); ValueHolder<Long> localLsn2 = ValueHolder.initialize(-1l); if (Utils.tryGetValue(other, regionId, localLsn2)) { if (ObjectUtils.notEqual(localLsn1.v, localLsn2.v)) { return false; } } } return true; }
public Term get(Term key) { return entries.get(key); }
private void concatenate(Term term, boolean update) { if (!term.sort().equals(Sort.MAP)) { throw KEMException.criticalError("unexpected sort " + term.sort() + " of concatenated term " + term + "; expected " + Sort.MAP); } if (term instanceof BuiltinMap) { BuiltinMap map = (BuiltinMap) term; if (!update && entries.keySet().stream().anyMatch(key -> map.entries.containsKey(key) && !entries.get(key).equals(map.entries.get(key)))) { List<Triple<Term, Term, Term>> clashingKeys = entries.keySet().stream().filter(map.entries::containsKey).map(k -> Triple.of(k, entries.get(k), map.entries.get(k))).collect(Collectors.toList()); throw KEMException.criticalError("failed to concatenate maps with common keys: " + clashingKeys); } entries.putAll(map.entries); patternsBuilder.addAll(map.collectionPatterns); functionsBuilder.addAll(map.collectionFunctions); variablesBuilder.addAll(map.collectionVariables); } else if (term instanceof KItem && ((KLabel) ((KItem) term).kLabel()).isPattern()) { patternsBuilder.add((KItem) term); } else if (term instanceof KItem && ((KLabel) ((KItem) term).kLabel()).isFunction()) { functionsBuilder.add(term); } else if (term instanceof Variable) { variablesBuilder.add((Variable) term); } else { throw KEMException.criticalError("unexpected concatenated term" + term); } }
@Override public int concreteSize() { return entries.size(); }
@Override protected int computeHash() { int hashCode = 1; hashCode = hashCode * Constants.HASH_PRIME + entries.hashCode(); hashCode = hashCode * Constants.HASH_PRIME + collectionPatterns.hashCode(); hashCode = hashCode * Constants.HASH_PRIME + collectionFunctions.hashCode(); hashCode = hashCode * Constants.HASH_PRIME + collectionVariables.hashCode(); return hashCode; }
@Override public boolean equals(Object object) { if (this == object) { return true; } if (!(object instanceof BuiltinMap)) { return false; } BuiltinMap map = (BuiltinMap) object; return entries.equals(map.entries) && collectionPatterns.equals(map.collectionPatterns) && collectionFunctions.equals(map.collectionFunctions) && collectionVariables.equals(map.collectionVariables); }
public static BoolToken in_keys(Term key, BuiltinMap map, TermContext context) { boolean in = map.getEntries().containsKey(key); BoolToken r = BoolToken.of(in); if (in) { return r; } else if (key.isGround() && map.isConcreteCollection() && map.hasOnlyGroundKeys()) { return r; } else if (map.isEmpty()) { return r; } else { return null; } }
if (other.version == this.version && other.localLsnByRegion.size() != this.localLsnByRegion.size()) { throw new InternalServerErrorException( String.format(RMResources.InvalidRegionsInSessionToken, this.sessionToken, other.sessionToken)); for (Map.Entry<Integer, Long> kvp : other.localLsnByRegion.entrySet()) { Integer regionId = kvp.getKey(); long otherLocalLsn = kvp.getValue();
public Object invoke(Object proxy, Method method, Object[] args) { String member = method.getName(); Class<?>[] paramTypes = method.getParameterTypes(); // Handle Object and Annotation methods if (member.equals("equals") && paramTypes.length == 1 && paramTypes[0] == Object.class) { if (!type.isInstance(args[0])) { return false; } return AnnotationUtils.equals((Annotation) proxy, (Annotation) args[0]); } else if(paramTypes.length == 0) { if (member.equals("toString")) { return AnnotationUtils.toString((Annotation) proxy); } else if (member.equals("hashCode")) { return AnnotationUtils.hashCode((Annotation) proxy); } else if (member.equals("annotationType")) { return type; } else { Object result = memberValues.get(member); if (result == null) { return method.getDefaultValue(); } if (result.getClass().isArray() && Array.getLength(result) != 0) { result = cloneArray(result); } return result; } } else { throw new IllegalStateException("No implementation for method " + method); } }
public static BuiltinSet keys(BuiltinMap map, TermContext context) { if (map.getEntries().isEmpty() && !map.isEmpty()) { return null; } BuiltinSet.Builder builder = BuiltinSet.builder(context.global()); builder.addAll(map.getEntries().keySet()); if (!map.isConcreteCollection()) { builder.add(KItem.of( KLabelConstant.of(KLabels.MAP_KEYS, context.definition()), KList.concatenate(BuiltinMap.concatenate(context.global(), map.baseTerms())), context.global())); } return (BuiltinSet) builder.build(); }
@Override public Map<K, Collection<V>> asMap() { return UnmodifiableMap.unmodifiableMap(decorated().asMap()); }
@Override public void visit(BuiltinMap builtinMap) { builtinMap.getEntries().entrySet().stream().forEach(e -> { visitNode(e.getKey()); visitNode(e.getValue()); }); builtinMap.baseTerms().stream().forEach(this::visitNode); visit((Collection) builtinMap); }
locationIndex = Math.min(locationIndex%2, currentLocationInfo.availableWriteLocations.size()-1); String writeLocation = currentLocationInfo.availableWriteLocations.get(locationIndex); return currentLocationInfo.availableWriteEndpointByLocation.get(writeLocation); } else { return this.defaultEndpoint;
public Map<Term, Term> getEntries() { return UnmodifiableMap.unmodifiableMap(entries); }