List of usage examples for com.google.common.collect ImmutableMap keySet
public ImmutableSet<K> keySet()
From source file:com.facebook.buck.versions.VersionedTargetGraphBuilder.java
/** * Get/cache the transitive version info for this node. *///from w w w . ja v a2s .co m private VersionInfo getVersionInfo(TargetNode<?, ?> node) { VersionInfo info = this.versionInfo.get(node.getBuildTarget()); if (info != null) { return info; } Map<BuildTarget, ImmutableSet<Version>> versionDomain = new HashMap<>(); Optional<TargetNode<VersionedAliasDescription.Arg, ?>> versionedNode = TargetGraphVersionTransformations .getVersionedNode(node); if (versionedNode.isPresent()) { ImmutableMap<Version, BuildTarget> versions = versionedNode.get().getConstructorArg().versions; // Merge in the versioned deps and the version domain. versionDomain.put(node.getBuildTarget(), versions.keySet()); // If this version has only one possible choice, there's no need to wrap the constraints from // it's transitive deps in an implication constraint. if (versions.size() == 1) { Map.Entry<Version, BuildTarget> ent = versions.entrySet().iterator().next(); VersionInfo depInfo = getVersionInfo(getNode(ent.getValue())); versionDomain.putAll(depInfo.getVersionDomain()); } else { // For each version choice, inherit the transitive constraints by wrapping them in an // implication dependent on the specific version that pulls them in. for (Map.Entry<Version, BuildTarget> ent : versions.entrySet()) { VersionInfo depInfo = getVersionInfo(getNode(ent.getValue())); versionDomain.putAll(depInfo.getVersionDomain()); } } } else { // Merge in the constraints and version domain/deps from transitive deps. for (BuildTarget depTarget : TargetGraphVersionTransformations.getDeps(node)) { TargetNode<?, ?> dep = getNode(depTarget); if (TargetGraphVersionTransformations.isVersionPropagator(dep) || TargetGraphVersionTransformations.getVersionedNode(dep).isPresent()) { VersionInfo depInfo = getVersionInfo(dep); versionDomain.putAll(depInfo.getVersionDomain()); } } } info = VersionInfo.of(versionDomain); this.versionInfo.put(node.getBuildTarget(), info); return info; }
From source file:com.google.enterprise.connector.persist.HybridPersistentStore.java
@Override public ImmutableMap<StoreContext, ConnectorStamps> getInventory() { ImmutableMap<StoreContext, ConnectorStamps> scheduleInventory = scheduleStore.getInventory(); ImmutableMap<StoreContext, ConnectorStamps> stateInventory = stateStore.getInventory(); ImmutableMap<StoreContext, ConnectorStamps> configurationInventory = configurationStore.getInventory(); // TODO: This won't work for JdbcStore, as its StoreContext is // missing connectorDir. This will correct itself when StoreContext // is changed to use ConnectorTypeName, rather than connectorDir. HashSet<StoreContext> contexts = new HashSet<StoreContext>(); contexts.addAll(scheduleInventory.keySet()); contexts.addAll(stateInventory.keySet()); contexts.addAll(configurationInventory.keySet()); ImmutableMap.Builder<StoreContext, ConnectorStamps> builder = ImmutableMap.builder(); for (StoreContext context : contexts) { Stamp configurationStamp = null; Stamp checkpointStamp = null;/*from ww w . j a v a2 s. c o m*/ Stamp scheduleStamp = null; ConnectorStamps stamps = configurationInventory.get(context); if (stamps != null) { configurationStamp = stamps.getConfigurationStamp(); } stamps = scheduleInventory.get(context); if (stamps != null) { scheduleStamp = stamps.getScheduleStamp(); } stamps = stateInventory.get(context); if (stamps != null) { checkpointStamp = stamps.getCheckpointStamp(); } builder.put(context, new ConnectorStamps(checkpointStamp, configurationStamp, scheduleStamp)); } return builder.build(); }
From source file:com.android.builder.shrinker.Shrinker.java
private ImmutableMap<ShrinkType, Set<T>> buildMapPerShrinkType(ImmutableMap<ShrinkType, KeepRules> keepRules) { ImmutableMap.Builder<ShrinkType, Set<T>> builder = ImmutableMap.builder(); for (ShrinkType shrinkType : keepRules.keySet()) { builder.put(shrinkType, Sets.<T>newConcurrentHashSet()); }/*w w w .j a v a 2s . com*/ return builder.build(); }
From source file:pl.asie.foamfix.client.Deduplicator.java
public Object deduplicateObject(Object o, int recursion) { if (o == null || recursion > maxRecursion) return o; Class c = o.getClass();/*from w ww . j a v a2 s . c o m*/ if (!shouldCheckClass(c)) return o; if (!deduplicatedObjects.add(o)) return o; // System.out.println("-" + Strings.repeat("-", recursion) + " " + c.getName()); if (o instanceof IBakedModel) { if (o instanceof IPerspectiveAwareModel.MapWrapper) { try { Object to = IPAM_MW_TRANSFORMS_GETTER.invoke(o); Object toD = deduplicate0(to); if (toD != null && to != toD) { IPAM_MW_TRANSFORMS_SETTER.invoke(o, toD); } } catch (Throwable t) { t.printStackTrace(); } } else if ("net.minecraftforge.client.model.ItemLayerModel$BakedItemModel".equals(c.getName())) { try { Object to = BIM_TRANSFORMS_GETTER.invoke(o); Object toD = deduplicate0(to); if (toD != null && to != toD) { BIM_TRANSFORMS_SETTER.invoke(o, toD); } } catch (Throwable t) { t.printStackTrace(); } } } if (c == UnpackedBakedQuad.class) { try { float[][][] array = (float[][][]) FIELD_UNPACKED_DATA_GETTER.invokeExact((UnpackedBakedQuad) o); // float[][][]s are not currently deduplicated deduplicate0(array); } catch (Throwable t) { t.printStackTrace(); } } else if (o instanceof ResourceLocation || o instanceof TRSRTransformation) { return deduplicate0(o); } else if (c == ItemCameraTransforms.class) { Object d = deduplicate0(o); if (d != o) return d; // TODO: Add ItemTransformVec3f dedup, maybe return o; } else if (o instanceof Item || o instanceof Block || o instanceof World || o instanceof Entity || o instanceof Logger || o instanceof IRegistry) { BLACKLIST_CLASS.add(c); } else if (o != ItemOverrideList.NONE && c == ItemOverrideList.class && ((ItemOverrideList) o).getOverrides().isEmpty()) { successfuls++; return ItemOverrideList.NONE; } else if (o instanceof com.google.common.base.Optional) { Optional opt = (Optional) o; if (opt.isPresent()) { Object b = deduplicateObject(opt.get(), recursion + 1); if (b != null && b != opt.get()) { return Optional.of(b); } } } else if (o instanceof Multimap) { if (o instanceof ImmutableMultimap) { // TODO: Handle me? } else { for (Object key : ((Multimap) o).keySet()) { List l = Lists.newArrayList(((Multimap) o).values()); for (int i = 0; i < l.size(); i++) { l.set(i, deduplicateObject(l.get(i), recursion + 1)); } ((Multimap) o).replaceValues(key, l); } } } else if (o instanceof Map) { if (o instanceof ImmutableMap) { ImmutableMap im = (ImmutableMap) o; Map newMap = new HashMap(); boolean deduplicated = false; for (Object key : im.keySet()) { Object a = im.get(key); Object b = deduplicateObject(a, recursion + 1); newMap.put(key, b != null ? b : a); if (b != null && b != a) deduplicated = true; } if (deduplicated) { return ImmutableMap.copyOf(newMap); } } else { for (Object key : ((Map) o).keySet()) { Object value = ((Map) o).get(key); Object valueD = deduplicateObject(value, recursion + 1); if (valueD != null && value != valueD) ((Map) o).put(key, valueD); } } } else if (o instanceof List) { if (o instanceof ImmutableList) { ImmutableList il = (ImmutableList) o; List newList = new ArrayList(); boolean deduplicated = false; for (int i = 0; i < il.size(); i++) { Object a = il.get(i); Object b = deduplicateObject(a, recursion + 1); newList.add(b != null ? b : a); if (b != null && b != a) deduplicated = true; } if (deduplicated) { return ImmutableList.copyOf(newList); } } else { List l = (List) o; for (int i = 0; i < l.size(); i++) { l.set(i, deduplicateObject(l.get(i), recursion + 1)); } } } else if (o instanceof Collection) { if (!COLLECTION_CONSTRUCTORS.containsKey(c)) { try { COLLECTION_CONSTRUCTORS.put(c, MethodHandles.publicLookup().findConstructor(c, MethodType.methodType(void.class))); } catch (Exception e) { COLLECTION_CONSTRUCTORS.put(c, null); } } MethodHandle constructor = COLLECTION_CONSTRUCTORS.get(c); if (constructor != null) { try { Collection nc = (Collection) constructor.invoke(); for (Object o1 : ((Collection) o)) { nc.add(deduplicateObject(o1, recursion + 1)); } return nc; } catch (Throwable t) { } } // fallback for (Object o1 : ((Collection) o)) { deduplicateObject(o1, recursion + 1); } } else if (c.isArray()) { for (int i = 0; i < Array.getLength(o); i++) { Object entry = Array.get(o, i); Object entryD = deduplicateObject(entry, recursion + 1); if (entryD != null && entry != entryD) Array.set(o, i, entryD); } } else { if (!CLASS_FIELDS.containsKey(c)) { ImmutableSet.Builder<MethodHandle[]> fsBuilder = ImmutableSet.builder(); Class cc = c; do { for (Field f : cc.getDeclaredFields()) { f.setAccessible(true); if ((f.getModifiers() & Modifier.STATIC) != 0) continue; if (shouldCheckClass(f.getType())) { try { fsBuilder.add(new MethodHandle[] { MethodHandles.lookup().unreflectGetter(f), MethodHandles.lookup().unreflectSetter(f) }); } catch (IllegalAccessException e) { e.printStackTrace(); } } } } while ((cc = cc.getSuperclass()) != Object.class); CLASS_FIELDS.put(c, fsBuilder.build()); } for (MethodHandle[] mh : CLASS_FIELDS.get(c)) { try { // System.out.println("-" + Strings.repeat("-", recursion) + "* " + f.getName()); Object value = mh[0].invoke(o); Object valueD = deduplicateObject(value, recursion + 1); if (TRIM_ARRAYS_CLASSES.contains(c)) { if (valueD instanceof ArrayList) { ((ArrayList) valueD).trimToSize(); } } if (valueD != null && value != valueD) mh[1].invoke(o, valueD); } catch (IllegalAccessException e) { } catch (Throwable t) { t.printStackTrace(); } } } return o; }
From source file:org.apache.abdera2.activities.model.ASBase.java
@SuppressWarnings("rawtypes") public <T extends ASBase> T as(Class<T> type, Map<String, Object> other) { ImmutableMap<String, Object> copy = other instanceof ImmutableMap ? (ImmutableMap<String, Object>) other : ImmutableMap.copyOf(other); Builder builder = as(type, withoutFields(copy.keySet())).template(); for (Entry<String, Object> entry : copy.entrySet()) builder.set(entry.getKey(), entry.getValue()); return (T) builder.get(); }
From source file:com.google.devtools.build.android.AndroidResourceClassWriter.java
private List<FieldInitializer> getStyleableInitializers(Map<String, Integer> attrAssignments, Collection<String> styleableFields) throws AttrLookupException { ImmutableList.Builder<FieldInitializer> initList = ImmutableList.builder(); for (String field : styleableFields) { Set<String> attrs = styleableAttrs.get(field).keySet(); ImmutableMap.Builder<String, Integer> arrayInitValues = ImmutableMap.builder(); for (String attr : attrs) { Integer attrId = attrAssignments.get(attr); if (attrId == null) { // It should be a framework resource, otherwise we don't know about the resource. if (!attr.startsWith(NORMALIZED_ANDROID_PREFIX)) { throw new AttrLookupException("App attribute not found: " + attr); }/*from ww w. java 2s . co m*/ String attrWithoutPrefix = attr.substring(NORMALIZED_ANDROID_PREFIX.length()); attrId = androidIdProvider.getAttrId(attrWithoutPrefix); } arrayInitValues.put(attr, attrId); } // The styleable array should be sorted by ID value. // Make sure that if we have android: framework attributes, their IDs are listed first. ImmutableMap<String, Integer> arrayInitMap = arrayInitValues .orderEntriesByValue(Ordering.<Integer>natural()).build(); initList.add(new IntArrayFieldInitializer(field, arrayInitMap.values())); int index = 0; for (String attr : arrayInitMap.keySet()) { initList.add(new IntFieldInitializer(field + "_" + attr, index)); ++index; } } return initList.build(); }
From source file:org.apache.abdera2.activities.model.ASBase.java
public <X extends ASBase, M extends Builder<X, M>> M templateWith(Map<String, Object> other) { ImmutableMap<String, Object> copy = other instanceof ImmutableMap ? (ImmutableMap<String, Object>) other : ImmutableMap.copyOf(other); M builder = this.<X, M>template(withoutFields(copy.keySet())); for (Map.Entry<String, Object> entry : copy.entrySet()) builder.set(entry.getKey(), entry.getValue()); return builder; }
From source file:com.google.auto.value.processor.AutoAnnotationProcessor.java
private void validateParameters(TypeElement annotationElement, ExecutableElement method, ImmutableMap<String, Member> members, ImmutableMap<String, Parameter> parameters, ImmutableMap<String, AnnotationValue> defaultValues) { boolean error = false; for (String memberName : members.keySet()) { if (!parameters.containsKey(memberName) && !defaultValues.containsKey(memberName)) { reportError(method,//from w w w . j a va 2 s . c om "@AutoAnnotation method needs a parameter with name '%s' and type %s" + " corresponding to %s.%s, which has no default value", memberName, members.get(memberName).getType(), annotationElement, memberName); error = true; } } if (error) { throw new AbortProcessingException(); } }
From source file:google.registry.dns.writer.clouddns.CloudDnsWriter.java
/** * Get a callback to mutate the zone with the provided {@code desiredRecords}. *//* ww w.java2s . co m*/ @VisibleForTesting Callable<Void> getMutateZoneCallback( final ImmutableMap<String, ImmutableSet<ResourceRecordSet>> desiredRecords) { return new Callable<Void>() { @Override public Void call() throws IOException, ZoneStateException { // Fetch all existing records for names that this writer is trying to modify Builder<ResourceRecordSet> existingRecords = new Builder<>(); for (String domainName : desiredRecords.keySet()) { List<ResourceRecordSet> existingRecordsForDomain = getResourceRecordsForDomain(domainName); existingRecords.addAll(existingRecordsForDomain); // Fetch glue records for in-bailiwick nameservers for (ResourceRecordSet record : existingRecordsForDomain) { if (!record.getType().equals("NS")) { continue; } for (String hostName : record.getRrdatas()) { if (hostName.endsWith(domainName) && !hostName.equals(domainName)) { existingRecords.addAll(getResourceRecordsForDomain(hostName)); } } } } // Flatten the desired records into one set. Builder<ResourceRecordSet> flattenedDesiredRecords = new Builder<>(); for (ImmutableSet<ResourceRecordSet> records : desiredRecords.values()) { flattenedDesiredRecords.addAll(records); } // Delete all existing records and add back the desired records updateResourceRecords(flattenedDesiredRecords.build(), existingRecords.build()); return null; } }; }
From source file:com.facebook.presto.metadata.Signature.java
@Nullable public Map<String, Type> bindTypeParameters(Type returnType, List<? extends Type> types, boolean allowCoercion, TypeManager typeManager) {/*from w ww . ja v a 2 s. co m*/ Map<String, Type> boundParameters = new HashMap<>(); ImmutableMap.Builder<String, TypeParameter> builder = ImmutableMap.builder(); for (TypeParameter parameter : typeParameters) { builder.put(parameter.getName(), parameter); } ImmutableMap<String, TypeParameter> parameters = builder.build(); if (!matchAndBind(boundParameters, parameters, this.returnType, returnType, allowCoercion, typeManager)) { return null; } if (!matchArguments(boundParameters, parameters, argumentTypes, types, allowCoercion, variableArity, typeManager)) { return null; } checkState(boundParameters.keySet().equals(parameters.keySet()), "%s matched arguments %s, but type parameters %s are still unbound", this, types, Sets.difference(parameters.keySet(), boundParameters.keySet())); return boundParameters; }