List of usage examples for com.google.common.collect ImmutableMap get
V get(Object key);
From source file:com.sourceclear.headlines.util.HeaderBuilder.java
public static String formatDirectives(ImmutableMap<String, ImmutableList<String>> directives) { // In the case of an empty map return the empty string: if (directives.isEmpty()) { return ""; }/* w w w . j a v a2 s .c om*/ StringBuilder sb = new StringBuilder(); // Outer loop - loop through each directive for (String directive : directives.keySet()) { // Don't add a directive if it has zero elements if (directives.get(directive).size() == 0) { continue; } StringBuilder elements = new StringBuilder(); // Inner loop = for each directive build up the element String for (String element : directives.get(directive)) { elements.append(element).append(" "); } if (sb.length() > 0) { sb.append("; "); } sb.append(directive).append(" ").append(elements.append(" ").toString()); } return sb.toString().trim(); }
From source file:com.spectralogic.ds3contractcomparator.print.simpleprinter.Ds3ElementDiffSimplePrinter.java
/** * Prints the changes between two {@link ImmutableList} of {@link Ds3Annotation}. If both lists are * empty, then nothing is printed./*ww w. j av a 2 s. com*/ */ private static void printAnnotations(final ImmutableList<Ds3Annotation> oldAnnotations, final ImmutableList<Ds3Annotation> newAnnotations, final WriterHelper writer, final boolean printAllAnnotations) { if (isEmpty(oldAnnotations) && isEmpty(newAnnotations)) { //do not print empty values return; } writer.append(indent(INDENT + 1)).append("Annotations:").append("\n"); final ImmutableSet<String> annotationNames = getAnnotationNameUnion(oldAnnotations, newAnnotations); final ImmutableMap<String, Ds3Annotation> oldParamMap = toAnnotationMap(oldAnnotations); final ImmutableMap<String, Ds3Annotation> newParamMap = toAnnotationMap(newAnnotations); annotationNames.stream() .filter((annotationName) -> shouldPrintAnnotation(annotationName, printAllAnnotations)) .forEach(name -> printAnnotationDiff(oldParamMap.get(name), newParamMap.get(name), writer)); }
From source file:dagger.internal.codegen.AnnotationMirrors.java
static ImmutableList<TypeMirror> getAttributeAsListOfTypes(AnnotationMirror annotationMirror, String attributeName) {// www .j a va 2 s .c om checkNotNull(annotationMirror); checkNotNull(attributeName); ImmutableMap<String, AnnotationValue> valueMap = simplifyAnnotationValueMap( getAnnotationValuesWithDefaults(annotationMirror)); ImmutableList.Builder<TypeMirror> builder = ImmutableList.builder(); @SuppressWarnings("unchecked") // that's the whole point of this method List<? extends AnnotationValue> typeValues = (List<? extends AnnotationValue>) valueMap.get(attributeName) .getValue(); for (AnnotationValue typeValue : typeValues) { builder.add((TypeMirror) typeValue.getValue()); } return builder.build(); }
From source file:com.google.javascript.jscomp.AccessControlUtils.java
/** * Returns the effective visibility of the given property. This can differ * from the property's declared visibility if the property is inherited from * a superclass, or if the file's {@code @fileoverview} JsDoc specifies * a default visibility./*from w ww .j a va 2 s . c om*/ * * @param property The property to compute effective visibility for. * @param referenceType The JavaScript type of the property. * @param fileVisibilityMap A map of {@code @fileoverview} visibility * annotations, used to compute the property's default visibility. * @param codingConvention The coding convention in effect (if any), * used to determine whether the property is private by lexical convention * (example: trailing underscore). */ static Visibility getEffectivePropertyVisibility(Node property, ObjectType referenceType, ImmutableMap<StaticSourceFile, Visibility> fileVisibilityMap, @Nullable CodingConvention codingConvention) { String propertyName = property.getLastChild().getString(); StaticSourceFile definingSource = getDefiningSource(property, referenceType, propertyName); Visibility fileOverviewVisibility = fileVisibilityMap.get(definingSource); Node parent = property.getParent(); boolean isOverride = parent.getJSDocInfo() != null && parent.isAssign() && parent.getFirstChild() == property; ObjectType objectType = getObjectType(referenceType, isOverride, propertyName); if (isOverride) { Visibility overridden = getOverriddenPropertyVisibility(objectType, propertyName); return getEffectiveVisibilityForOverriddenProperty(overridden, fileOverviewVisibility, propertyName, codingConvention); } else { return getEffectiveVisibilityForNonOverriddenProperty(property, objectType, fileOverviewVisibility, codingConvention); } }
From source file:com.facebook.buck.cxx.CxxPlatforms.java
public static CxxPlatform getConfigDefaultCxxPlatform(CxxBuckConfig cxxBuckConfig, ImmutableMap<Flavor, CxxPlatform> cxxPlatformsMap, CxxPlatform systemDefaultCxxPlatform) { CxxPlatform defaultCxxPlatform;/*from ww w .j a v a2 s .co m*/ Optional<String> defaultPlatform = cxxBuckConfig.getDefaultPlatform(); if (defaultPlatform.isPresent()) { defaultCxxPlatform = cxxPlatformsMap.get(ImmutableFlavor.of(defaultPlatform.get())); if (defaultCxxPlatform == null) { LOG.warn("Couldn't find default platform %s, falling back to system default", defaultPlatform.get()); } else { LOG.debug("Using config default C++ platform %s", defaultCxxPlatform); return defaultCxxPlatform; } } else { LOG.debug("Using system default C++ platform %s", systemDefaultCxxPlatform); } return systemDefaultCxxPlatform; }
From source file:com.google.devtools.build.lib.remote.CachedLocalSpawnRunner.java
private static Command buildCommand(List<String> arguments, ImmutableMap<String, String> environment) { Command.Builder command = Command.newBuilder(); command.addAllArgv(arguments);//from w ww .ja va2s . co m // Sorting the environment pairs by variable name. TreeSet<String> variables = new TreeSet<>(environment.keySet()); for (String var : variables) { command.addEnvironmentBuilder().setVariable(var).setValue(environment.get(var)); } return command.build(); }
From source file:it.unibz.krdb.obda.owlrefplatform.core.dagjgrapht.EquivalencesDAGImpl.java
public static <T> EquivalencesDAGImpl<T> reduce(EquivalencesDAGImpl<T> source, SimpleDirectedGraph<Equivalences<T>, DefaultEdge> target) { ImmutableMap.Builder<T, Equivalences<T>> vertexIndexBuilder = new ImmutableMap.Builder<>(); for (Equivalences<T> tSet : target.vertexSet()) { for (T s : source.getVertex(tSet.getRepresentative())) if (tSet.contains(s)) vertexIndexBuilder.put(s, tSet); }// w ww . j av a2 s . c o m ImmutableMap<T, Equivalences<T>> vertexIndex = vertexIndexBuilder.build(); // create induced edges in the target graph for (Equivalences<T> sSet : source) { Equivalences<T> tSet = vertexIndex.get(sSet.getRepresentative()); for (Equivalences<T> sSetSub : source.getDirectSub(sSet)) { Equivalences<T> tSetSub = vertexIndex.get(sSetSub.getRepresentative()); target.addEdge(tSetSub, tSet); } } return new EquivalencesDAGImpl<>(null, target, vertexIndex, source.vertexIndex); }
From source file:com.google.devtools.build.android.XmlResourceValues.java
static XmlResourceValue parsePublic(XMLEventReader eventReader, StartElement start, Namespaces.Collector namespacesCollector) throws XMLStreamException { namespacesCollector.collectFrom(start); // The tag should be unary. if (!isEndTag(eventReader.peek(), start.getName())) { throw new XMLStreamException(String.format("<public> tag should be unary %s", start), start.getLocation());/*from ww w . j a v a2s. co m*/ } // The tag should have a valid type attribute, and optionally an id attribute. ImmutableMap<String, String> attributes = ImmutableMap.copyOf(parseTagAttributes(start)); String typeAttr = attributes.get(SdkConstants.ATTR_TYPE); ResourceType type; if (typeAttr != null) { type = ResourceType.getEnum(typeAttr); if (type == null || type == ResourceType.PUBLIC) { throw new XMLStreamException(String.format("<public> tag has invalid type attribute %s", start), start.getLocation()); } } else { throw new XMLStreamException(String.format("<public> tag missing type attribute %s", start), start.getLocation()); } String idValueAttr = attributes.get(SdkConstants.ATTR_ID); Optional<Integer> id = Optional.absent(); if (idValueAttr != null) { try { id = Optional.of(Integer.decode(idValueAttr)); } catch (NumberFormatException e) { throw new XMLStreamException(String.format("<public> has invalid id number %s", start), start.getLocation()); } } if (attributes.size() > 2) { throw new XMLStreamException(String.format("<public> has unexpected attributes %s", start), start.getLocation()); } return PublicXmlResourceValue.create(type, id); }
From source file:com.facebook.buck.apple.ApplePlatforms.java
public static AppleCxxPlatform getAppleCxxPlatformForBuildTarget( FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain, CxxPlatform defaultCxxPlatform, ImmutableMap<Flavor, AppleCxxPlatform> platformFlavorsToAppleCxxPlatforms, BuildTarget target, Optional<FatBinaryInfo> fatBinaryInfo) { AppleCxxPlatform appleCxxPlatform;/*from ww w .j a v a 2s . com*/ if (fatBinaryInfo.isPresent()) { appleCxxPlatform = fatBinaryInfo.get().getRepresentativePlatform(); } else { CxxPlatform cxxPlatform = getCxxPlatformForBuildTarget(cxxPlatformFlavorDomain, defaultCxxPlatform, target); appleCxxPlatform = platformFlavorsToAppleCxxPlatforms.get(cxxPlatform.getFlavor()); if (appleCxxPlatform == null) { throw new HumanReadableException("%s: Apple bundle requires an Apple platform, found '%s'", target, cxxPlatform.getFlavor().getName()); } } return appleCxxPlatform; }
From source file:com.telefonica.iot.cygnus.management.MetricsHandlers.java
/** * Deletes metrics from all the given sources and sinks. * @param sources/*ww w . j a v a 2 s . com*/ * @param sinks */ private static void deleteMetrics(ImmutableMap<String, SourceRunner> sources, ImmutableMap<String, SinkRunner> sinks) { if (sources != null) { for (String key : sources.keySet()) { Source source; HTTPSourceHandler handler; try { SourceRunner sr = sources.get(key); source = sr.getSource(); Field f = source.getClass().getDeclaredField("handler"); f.setAccessible(true); handler = (HTTPSourceHandler) f.get(source); } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) { LOGGER.error("There was a problem when getting a sink. Details: " + e.getMessage()); continue; } // try catch if (handler instanceof CygnusHandler) { CygnusHandler ch = (CygnusHandler) handler; ch.setServiceMetrics(new CygnusMetrics()); } // if } // for } // if if (sinks != null) { for (String key : sinks.keySet()) { Sink sink; try { SinkRunner sr = sinks.get(key); SinkProcessor sp = sr.getPolicy(); Field f = sp.getClass().getDeclaredField("sink"); f.setAccessible(true); sink = (Sink) f.get(sp); } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) { LOGGER.error("There was a problem when getting a sink. Details: " + e.getMessage()); continue; } // try catch if (sink instanceof CygnusSink) { CygnusSink cs = (CygnusSink) sink; cs.setServiceMetrics(new CygnusMetrics()); } // if } // for } // if }