List of usage examples for com.google.common.collect ImmutableMap get
V get(Object key);
From source file:com.facebook.buck.apple.AppleSdkDiscovery.java
private static boolean buildSdkFromPath(Path sdkDir, AppleSdk.Builder sdkBuilder, ImmutableMap<String, AppleToolchain> xcodeToolchains, Optional<AppleToolchain> defaultToolchain, AppleConfig appleConfig) throws IOException { try (InputStream sdkSettingsPlist = Files.newInputStream(sdkDir.resolve("SDKSettings.plist")); BufferedInputStream bufferedSdkSettingsPlist = new BufferedInputStream(sdkSettingsPlist)) { NSDictionary sdkSettings;/*from w w w .j a va 2s .c om*/ try { sdkSettings = (NSDictionary) PropertyListParser.parse(bufferedSdkSettingsPlist); } catch (PropertyListFormatException | ParseException | SAXException e) { LOG.error(e, "Malformatted SDKSettings.plist. Skipping SDK path %s.", sdkDir); return false; } catch (ParserConfigurationException e) { throw new IOException(e); } String name = sdkSettings.objectForKey("CanonicalName").toString(); String version = sdkSettings.objectForKey("Version").toString(); NSDictionary defaultProperties = (NSDictionary) sdkSettings.objectForKey("DefaultProperties"); Optional<ImmutableList<String>> toolchains = appleConfig.getToolchainsOverrideForSDKName(name); boolean foundToolchain = false; if (!toolchains.isPresent()) { NSArray settingsToolchains = (NSArray) sdkSettings.objectForKey("Toolchains"); if (settingsToolchains != null) { toolchains = Optional.of(Arrays.stream(settingsToolchains.getArray()).map(Object::toString) .collect(MoreCollectors.toImmutableList())); } } if (toolchains.isPresent()) { for (String toolchainId : toolchains.get()) { AppleToolchain toolchain = xcodeToolchains.get(toolchainId); if (toolchain != null) { foundToolchain = true; sdkBuilder.addToolchains(toolchain); } else { LOG.debug("Specified toolchain %s not found for SDK path %s", toolchainId, sdkDir); } } } if (!foundToolchain && defaultToolchain.isPresent()) { foundToolchain = true; sdkBuilder.addToolchains(defaultToolchain.get()); } if (!foundToolchain) { LOG.warn("No toolchains found and no default toolchain. Skipping SDK path %s.", sdkDir); return false; } else { NSString platformName = (NSString) defaultProperties.objectForKey("PLATFORM_NAME"); ApplePlatform applePlatform = ApplePlatform.of(platformName.toString()); sdkBuilder.setName(name).setVersion(version).setApplePlatform(applePlatform); ImmutableList<String> architectures = validArchitecturesForPlatform(applePlatform, sdkDir); sdkBuilder.addAllArchitectures(architectures); return true; } } catch (NoSuchFileException e) { LOG.warn(e, "Skipping SDK at path %s, no SDKSettings.plist found", sdkDir); return false; } }
From source file:com.isotrol.impe3.pms.core.obj.PortalObject.java
List<SetFilterDTO> getSetFilterDTOs() { ImmutableMap<String, SetFilterValue> filters = setFilters.get(); final List<SetFilterDTO> list = Lists.newArrayListWithCapacity(filters.size()); if (filters.isEmpty()) { return list; }/*from www .ja v a 2s. c om*/ for (String set : Ordering.natural().sortedCopy(filters.keySet())) { SetFilterValue v = filters.get(set); SetFilterDTO dto = new SetFilterDTO(); dto.setName(set); dto.setType(v.getType()); dto.setDescription(v.getDescription()); list.add(dto); } return list; }
From source file:com.android.builder.shrinker.Shrinker.java
private void processChangedClassFile(File classFile, Map<ShrinkType, KeepRules> keepRules, ImmutableMap<ShrinkType, Set<T>> modifiedClasses) throws IOException { // TODO: Use the visitor API to save memory. ClassNode classNode = readClassNode(classFile); T klass = mGraph.getClassReference(classNode.name); for (ShrinkType shrinkType : keepRules.keySet()) { // If the class is in the output, it needs to be rewritten, to reflect changes. if (mGraph.isReachable(klass, shrinkType)) { modifiedClasses.get(shrinkType).add(klass); }/*from ww w . ja v a 2 s . c om*/ } Set<T> oldMembers = mGraph.getMethods(klass); //noinspection unchecked - ASM doesn't use generics. for (MethodNode methodNode : (List<MethodNode>) classNode.methods) { T method = mGraph.getMemberReference(classNode.name, methodNode.name, methodNode.desc); if (!oldMembers.contains(method)) { throw todo("added method"); } else { Set<Dependency<T>> oldDeps = mGraph.getDependencies(method); Set<Dependency<T>> currentDeps = getDependencies(methodNode); for (Dependency<T> addedDep : Sets.difference(currentDeps, oldDeps)) { mGraph.addDependency(method, addedDep.target, addedDep.type); for (ShrinkType shrinkType : keepRules.keySet()) { if (mGraph.isReachable(method, shrinkType)) { incrementCounter(addedDep.target, addedDep.type, shrinkType); } } } for (Dependency<T> removedDep : Sets.difference(oldDeps, currentDeps)) { mGraph.removeDependency(method, removedDep); for (ShrinkType shrinkType : keepRules.keySet()) { if (mGraph.isReachable(method, shrinkType)) { decrementCounter(removedDep.target, removedDep.type, shrinkType, modifiedClasses); } } } // Keep only unprocessed members, so we know which ones were deleted. oldMembers.remove(method); } } // TODO: process fields if (!oldMembers.isEmpty()) { throw todo("deleted member"); } }
From source file:edu.mit.streamjit.impl.distributed.StreamJitAppManager.java
/** * Setup the headchannel and tailchannel. * // w w w. ja v a 2s . co m * @param cfg * @param bufferMap * @param headToken * @param tailToken */ private void setupHeadTail(Map<Token, TCPConnectionInfo> conInfoMap, ImmutableMap<Token, Buffer> bufferMap, Token headToken, Token tailToken) { TCPConnectionInfo headconInfo = conInfoMap.get(headToken); assert headconInfo != null : "No head connection info exists in conInfoMap"; assert headconInfo.getSrcID() == controller.controllerNodeID || headconInfo .getDstID() == controller.controllerNodeID : "Head channel should start from the controller. " + headconInfo; if (!bufferMap.containsKey(headToken)) throw new IllegalArgumentException("No head buffer in the passed bufferMap."); headChannel = new HeadChannel(bufferMap.get(headToken), controller.getConProvider(), headconInfo, "headChannel - " + headToken.toString(), 0); TCPConnectionInfo tailconInfo = conInfoMap.get(tailToken); assert tailconInfo != null : "No tail connection info exists in conInfoMap"; assert tailconInfo.getSrcID() == controller.controllerNodeID || tailconInfo .getDstID() == controller.controllerNodeID : "Tail channel should ends at the controller. " + tailconInfo; if (!bufferMap.containsKey(tailToken)) throw new IllegalArgumentException("No tail buffer in the passed bufferMap."); tailChannel = new TailChannel(bufferMap.get(tailToken), controller.getConProvider(), tailconInfo, "tailChannel - " + tailToken.toString(), 0, 1000); }
From source file:com.facebook.buck.artifact_cache.AbstractAsynchronousCache.java
private void doMultiCheck(ImmutableMap<RuleKey, ClaimedFetchRequest> ruleKeyToRequest) { try {/*from ww w . j a va 2 s . c om*/ ImmutableMap<RuleKey, CacheResult> ruleKeyToResult = multiContainsImpl(ruleKeyToRequest.keySet()) .getCacheResults(); for (Map.Entry<RuleKey, CacheResult> result : ruleKeyToResult.entrySet()) { CacheResult cacheResult = result.getValue(); ClaimedFetchRequest claimedFetchRequest = ruleKeyToRequest.get(result.getKey()); if (claimedFetchRequest == null) { LOG.verbose("Recived cache result for not requested rule key."); continue; } if (!cacheResult.getType().isSuccess()) { // If rule key is not present in the cache, there is no point in trying to download // it. claimedFetchRequest.setResult(cacheResult); } else { // Otherwise reschedule it. It will be added to the fetch queue and it will be picked // by fetching thread. claimedFetchRequest.reschedule(); } } } catch (IOException e) { String msg = String.format("multicheck(<%s>): %s: %s", Joiner.on(", ").join(ruleKeyToRequest.keySet()), e.getClass().getName(), e.getMessage()); // Some of these might already be fulfilled. That's fine, this set() call will just be // ignored. for (ClaimedFetchRequest request : ruleKeyToRequest.values()) { request.setResult(CacheResult.error(name, mode, msg)); } } }
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,/* w ww. j a v a 2 s . com*/ "@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:se.sics.caracaldb.global.LookupTable.java
private void generateInitialVirtuals(ByteBuffer schemaId) { ImmutableMap<String, String> meta = schemas.metaData.get(schemaId); //String rfactorS = meta.getOrDefault("rfactor", "3"); String rfactorS = J6.orDefault(meta.get("rfactor"), "3"); Integer rfactor = Integer.parseInt(rfactorS); //String vnodesS = meta.getOrDefault("vnodes", "1"); String vnodesS = J6.orDefault(meta.get("vnodes"), "1"); long vnodes = Long.parseLong(vnodesS); //String forceMasterS = meta.getOrDefault("forceMaster", "false"); String forceMasterS = J6.orDefault(meta.get("forceMaster"), "false"); // it would look so nice in Java8 -.- boolean forceMaster = Boolean.parseBoolean(forceMasterS); // boundary nodes Key start = new Key(schemaId); //Key end = start.inc(); Integer rset = forceMaster ? 0 : findReplicationSetOfSize(rfactor); virtualHostsPut(start, rset);/*from ww w .j a va 2 s. c o m*/ //virtualHostsPut(end, rset); // this mind end up being override by the next schema, but that's ok since we only need it if there is no next schema if (vnodes == 1) { // single vnode needed return; } vnodes--; // account for the initial vnode already created (the end-nodes doesn't count) Set<Key> subkeys = new TreeSet<Key>(); if (vnodes <= UnsignedBytes.MAX_VALUE) { // another byte for subkeys needed int incr = (int) UnsignedBytes.MAX_VALUE / (int) vnodes; int last = 0; int ceiling = (int) UnsignedBytes.MAX_VALUE - incr; while (last < ceiling) { last = last + incr; Key k = start.append(new byte[] { UnsignedBytes.saturatedCast(last) }).get(); subkeys.add(k); } } else if (vnodes <= UnsignedInteger.MAX_VALUE.longValue()) { // another 4 bytes for subkeys needed long incr = UnsignedInteger.MAX_VALUE.longValue() / vnodes; long last = 0; long ceiling = UnsignedInteger.MAX_VALUE.longValue() - incr; while (last < ceiling) { last = last + incr; Key k = start.append(new Key(UnsignedInteger.valueOf(last).intValue())).get(); subkeys.add(k); } } else { // another 8 bytes for subkeys needed (don't support more!) UnsignedLong incr = UnsignedLong.MAX_VALUE.dividedBy(UnsignedLong.valueOf(vnodes)); UnsignedLong last = UnsignedLong.ZERO; UnsignedLong ceiling = UnsignedLong.MAX_VALUE.minus(incr); while (last.compareTo(ceiling) <= 0) { last = last.plus(incr); Key k = start.append(new Key(last.intValue())).get(); subkeys.add(k); } } for (Key subkey : subkeys) { virtualHostsPut(subkey, forceMaster ? 0 : findReplicationSetOfSize(rfactor)); } }
From source file:org.ambud.marauder.sink.MarauderHBaseSink.java
/** * Configure lookup table for serializers supported by the Cluster Sink. A Cluster sink should be able to serialize * anything and everything that comes it's way without any hickups * /*from ww w . j a v a2s .c om*/ * @param immutableMap * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException */ protected void configureSerializerLookupTable(ImmutableMap<String, String> immutableMap) throws ClassNotFoundException, InstantiationException, IllegalAccessException { MarauderEventTypes[] eventTypes = MarauderEventTypes.values(); MarauderBaseSerializer defaultSerializer = (isDisabledRealtimeIdx ? new MarauderGenericSerializer(this, aggregatorTimeWindow) : new MarauderGenericSolrIndexerSerializer(this, aggregatorTimeWindow)); for (MarauderEventTypes eventType : eventTypes) { logger.info("Checking serializer for:" + eventType.name() + " events"); if (immutableMap.containsKey(eventType.getTypeName())) { @SuppressWarnings("unchecked") Class<MarauderBaseSerializer> serializer = (Class<MarauderBaseSerializer>) Class .forName(immutableMap.get(eventType.getTypeName())); MarauderBaseSerializer temp = serializer.newInstance(); temp.setParentSink(this); serializerLookupTable.put(eventType.getTypeName(), temp); logger.info("Found dedicated serializer for:" + eventType.name() + " events"); } else { serializerLookupTable.put(eventType.getTypeName(), defaultSerializer); logger.info("Using generic serializer for:" + eventType.name() + " events"); } } }
From source file:auto.parcel.processor.AutoParcelProcessor.java
private void defineVarsForType(TypeElement type, AutoParcelTemplateVars vars) { Types typeUtils = processingEnv.getTypeUtils(); List<ExecutableElement> methods = new ArrayList<ExecutableElement>(); findLocalAndInheritedMethods(type, methods); determineObjectMethodsToGenerate(methods, vars); ImmutableSet<ExecutableElement> methodsToImplement = methodsToImplement(methods); Set<TypeMirror> types = new TypeMirrorSet(); types.addAll(returnTypesOf(methodsToImplement)); // TypeMirror javaxAnnotationGenerated = getTypeMirror(Generated.class); // types.add(javaxAnnotationGenerated); TypeMirror javaUtilArrays = getTypeMirror(Arrays.class); if (containsArrayType(types)) { // If there are array properties then we will be referencing java.util.Arrays. // Arrange to import it unless that would introduce ambiguity. types.add(javaUtilArrays);/*w ww .j a va 2 s . c o m*/ } BuilderSpec builderSpec = new BuilderSpec(type, processingEnv, errorReporter); Optional<BuilderSpec.Builder> builder = builderSpec.getBuilder(); ImmutableSet<ExecutableElement> toBuilderMethods; if (builder.isPresent()) { types.add(getTypeMirror(BitSet.class)); toBuilderMethods = builder.get().toBuilderMethods(typeUtils, methodsToImplement); } else { toBuilderMethods = ImmutableSet.of(); } vars.toBuilderMethods = FluentIterable.from(toBuilderMethods).transform(SimpleNameFunction.INSTANCE) .toList(); Set<ExecutableElement> propertyMethods = Sets.difference(methodsToImplement, toBuilderMethods); String pkg = TypeSimplifier.packageNameOf(type); TypeSimplifier typeSimplifier = new TypeSimplifier(typeUtils, pkg, types, type.asType()); vars.imports = typeSimplifier.typesToImport(); // vars.generated = typeSimplifier.simplify(javaxAnnotationGenerated); vars.arrays = typeSimplifier.simplify(javaUtilArrays); vars.bitSet = typeSimplifier.simplifyRaw(getTypeMirror(BitSet.class)); ImmutableMap<ExecutableElement, String> methodToPropertyName = methodToPropertyNameMap(propertyMethods); Map<ExecutableElement, String> methodToIdentifier = Maps.newLinkedHashMap(methodToPropertyName); fixReservedIdentifiers(methodToIdentifier); List<Property> props = new ArrayList<Property>(); for (ExecutableElement method : propertyMethods) { String propertyType = typeSimplifier.simplify(method.getReturnType()); String propertyName = methodToPropertyName.get(method); String identifier = methodToIdentifier.get(method); props.add(new Property(propertyName, identifier, method, propertyType, typeSimplifier)); } // If we are running from Eclipse, undo the work of its compiler which sorts methods. eclipseHack().reorderProperties(props); vars.props = props; vars.serialVersionUID = getSerialVersionUID(type); vars.formalTypes = typeSimplifier.formalTypeParametersString(type); vars.actualTypes = TypeSimplifier.actualTypeParametersString(type); vars.wildcardTypes = wildcardTypeParametersString(type); TypeElement parcelable = processingEnv.getElementUtils().getTypeElement("android.os.Parcelable"); vars.parcelable = parcelable != null && processingEnv.getTypeUtils().isAssignable(type.asType(), parcelable.asType()); // Check for @AutoParcel.Builder and add appropriate variables if it is present. if (builder.isPresent()) { builder.get().defineVars(vars, typeSimplifier, methodToPropertyName); } }
From source file:com.aitorvs.autoparcel.internal.codegen.AutoParcelProcessor.java
private MethodSpec generateWriteToParcel(int version, ProcessingEnvironment env, ImmutableList<Property> properties, ImmutableMap<TypeMirror, FieldSpec> typeAdapters) { ParameterSpec dest = ParameterSpec.builder(ClassName.get("android.os", "Parcel"), "dest").build(); ParameterSpec flags = ParameterSpec.builder(int.class, "flags").build(); MethodSpec.Builder builder = MethodSpec.methodBuilder("writeToParcel").addAnnotation(Override.class) .addModifiers(PUBLIC).addParameter(dest).addParameter(flags); // write first the parcelable object version... builder.addCode(Parcelables.writeVersion(version, dest)); // ...then write all the properties for (Property p : properties) { if (p.typeAdapter != null && typeAdapters.containsKey(p.typeAdapter)) { FieldSpec typeAdapter = typeAdapters.get(p.typeAdapter); builder.addCode(Parcelables.writeValueWithTypeAdapter(typeAdapter, p, dest)); } else {/* w ww . ja v a 2 s .c o m*/ builder.addCode(Parcelables.writeValue(p, dest, flags, env.getTypeUtils())); } } return builder.build(); }