List of usage examples for com.google.common.collect ImmutableMap get
V get(Object key);
From source file:se.sics.caracaldb.global.DefaultPolicy.java
private void switchOperationBalance(LUTWorkingBuffer lut, Address topAddr, Address bottomAddr, ImmutableMap<Address, Stats.Report> stats) { Stats.Report topRep = stats.get(topAddr); //Stats.Report bottomRep = stats.get(bottomAddr); Map<Address, Integer> ids = lut.lut.getIdsForAddresses(ImmutableSet.of(topAddr, bottomAddr)); for (Key k : topRep.topKOps) { Integer repGroupId = lut.getRepGroup(k); if (repGroupId == null) { continue; }/* ww w . ja v a 2s. c om*/ Integer[] repGroup = lut.getRepSet(repGroupId); int topPos = LookupTable.positionInSet(repGroup, ids.get(topAddr)); int bottomPos = LookupTable.positionInSet(repGroup, ids.get(bottomAddr)); if (bottomPos < 0) { // new address is not already part of the replication group Integer[] newRepGroup = Arrays.copyOf(repGroup, repGroup.length); newRepGroup[topPos] = ids.get(bottomAddr); lut.findGroupOrAddNew(k, newRepGroup); return; } } // if all of the topKOps vNodes already share a group with the bottomAddr there's nothing we can do }
From source file:hmi.facegraphics.HMIFaceController.java
/** * NOTE: this function should be called in some synchronisation; to ensure that the values are not changed during the copy method! *///from w w w .j a v a 2 s . c o m public synchronized void copy() { if (glHead != null) { // send the new MPEG4 configuration for (FAP fap : MPEG4.getFAPs().values()) { Integer value = currentConfig.getValue(fap.getIndex()); if (value == null) continue; glHead.getDeformer(fap).setValue(value); } glHead.deformWhenScheduled(); } ImmutableMap<String, Float> desiredMorphTargets = morphTargetHandler.getDesiredMorphTargets(); String[] targetNames = new String[desiredMorphTargets.size()]; float[] targetWeights = new float[desiredMorphTargets.size()]; int i = 0; for (String targetName : desiredMorphTargets.keySet()) { targetNames[i] = targetName; targetWeights[i] = desiredMorphTargets.get(targetName); i++; } theGLScene.setMorphTargets(targetNames, targetWeights); }
From source file:com.sourceclear.headlines.impl.CspDirectives.java
private String formatDirectives(ImmutableMap<String, ImmutableList<String>> directives) { // In the case of an empty map return the empty string: if (directives.isEmpty()) { return ""; }/*from w w w . ja va 2 s. co m*/ 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.toString().trim()); } return sb.toString().trim(); }
From source file:com.wealdtech.hawk.HawkServer.java
/** * Authenticate a request using Hawk./*from w ww .jav a 2s . co m*/ * @param credentials the Hawk credentials against which to authenticate * @param uri the URI of the request * @param method the method of the request * @param authorizationHeaders the Hawk authentication headers * @param hash the hash of the body, if available * @param hasBody <code>true</code> if the request has a body, <code>false</code> if not */ public void authenticate(final HawkCredentials credentials, final URI uri, final String method, final ImmutableMap<String, String> authorizationHeaders, final String hash, final boolean hasBody) { // Ensure that the required fields are present checkNotNull(authorizationHeaders.get(HEADER_TS), "The timestamp was not supplied"); checkNotNull(authorizationHeaders.get(HEADER_NONCE), "The nonce was not supplied"); checkNotNull(authorizationHeaders.get(HEADER_ID), "The id was not supplied"); checkNotNull(authorizationHeaders.get(HEADER_MAC), "The mac was not supplied"); if ((this.configuration.getPayloadValidation().equals(PayloadValidation.MANDATORY)) && (hasBody)) { checkNotNull(authorizationHeaders.get("hash"), "The payload hash was not supplied"); checkNotNull(hash, "The payload hash could not be calculated"); } // Ensure that the timestamp passed in is within suitable bounds confirmTimestampWithinBounds(authorizationHeaders.get(HEADER_TS)); // Ensure that this is not a replay of a previous request confirmUniqueNonce(authorizationHeaders.get(HEADER_NONCE) + authorizationHeaders.get(HEADER_TS) + authorizationHeaders.get(HEADER_ID)); // Ensure that the MAC is correct final String mac = Hawk.calculateMAC(credentials, Hawk.AuthType.HEADER, Long.valueOf(authorizationHeaders.get(HEADER_TS)), uri, authorizationHeaders.get(HEADER_NONCE), method, hash, authorizationHeaders.get(HEADER_EXT), authorizationHeaders.get(HEADER_APP), authorizationHeaders.get(HEADER_DLG)); if (!timeConstantEquals(mac, authorizationHeaders.get(HEADER_MAC))) { throw new DataError.Authentication("The MAC in the request does not match the server-calculated MAC"); } }
From source file:com.google.devtools.build.lib.remote.RemoteSpawnRunner.java
private Command buildCommand(List<String> arguments, ImmutableMap<String, String> environment) { Command.Builder command = Command.newBuilder(); command.addAllArgv(arguments);// w w w . j ava 2 s . 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:com.facebook.buck.rules.coercer.DefaultConstructorArgMarshaller.java
@Override public <T> T populateWithConfiguringAttributes(CellPathResolver cellPathResolver, ProjectFilesystem filesystem, SelectorListResolver selectorListResolver, SelectableConfigurationContext configurationContext, BuildTarget buildTarget, Class<T> dtoClass, ImmutableSet.Builder<BuildTarget> declaredDeps, ImmutableMap<String, ?> attributes) throws CoerceFailedException { Pair<Object, Function<Object, T>> dtoAndBuild = CoercedTypeCache.instantiateSkeleton(dtoClass, buildTarget); ImmutableMap<String, ParamInfo> allParamInfo = CoercedTypeCache.INSTANCE.getAllParamInfo(typeCoercerFactory, dtoClass);// www .jav a 2s. c o m for (ParamInfo info : allParamInfo.values()) { Object attribute = attributes.get(info.getName()); if (attribute == null) { continue; } Object attributeWithSelectableValue = createCoercedAttributeWithSelectableValue(cellPathResolver, filesystem, buildTarget, buildTarget.getTargetConfiguration(), info, attribute); Object configuredAttributeValue = configureAttributeValue(configurationContext, selectorListResolver, buildTarget, info.getName(), attributeWithSelectableValue); if (configuredAttributeValue != null) { info.setCoercedValue(dtoAndBuild.getFirst(), configuredAttributeValue); } } T dto = dtoAndBuild.getSecond().apply(dtoAndBuild.getFirst()); collectDeclaredDeps(cellPathResolver, allParamInfo.get("deps"), declaredDeps, dto); return dto; }
From source file:com.facebook.buck.apple.toolchain.AbstractProvisioningProfileStore.java
public Optional<ProvisioningProfileMetadata> getBestProvisioningProfile(String bundleID, ApplePlatform platform, Optional<ImmutableMap<String, NSObject>> entitlements, Optional<? extends Iterable<CodeSignIdentity>> identities, StringBuffer diagnosticsBuffer) { Optional<String> prefix; ImmutableList.Builder<String> lines = ImmutableList.builder(); if (entitlements.isPresent()) { prefix = ProvisioningProfileMetadata.prefixFromEntitlements(entitlements.get()); } else {/*from w w w . j a v a2s . c o m*/ prefix = Optional.empty(); } int bestMatchLength = -1; Optional<ProvisioningProfileMetadata> bestMatch = Optional.empty(); lines.add(String.format("Looking for a provisioning profile for bundle ID %s", bundleID)); boolean atLeastOneMatch = false; for (ProvisioningProfileMetadata profile : getProvisioningProfiles()) { Pair<String, String> appID = profile.getAppID(); LOG.debug("Looking at provisioning profile " + profile.getUUID() + "," + appID); if (!prefix.isPresent() || prefix.get().equals(appID.getFirst())) { String profileBundleID = appID.getSecond(); boolean match; if (profileBundleID.endsWith("*")) { // Chop the ending * if wildcard. profileBundleID = profileBundleID.substring(0, profileBundleID.length() - 1); match = bundleID.startsWith(profileBundleID); } else { match = (bundleID.equals(profileBundleID)); } if (!match) { LOG.debug("Ignoring non-matching ID for profile " + profile.getUUID() + ". Expected: " + profileBundleID + ", actual: " + bundleID); continue; } atLeastOneMatch = true; if (!profile.getExpirationDate().after(new Date())) { String message = "Ignoring expired profile " + profile.getUUID() + ": " + profile.getExpirationDate(); LOG.debug(message); lines.add(message); continue; } Optional<String> platformName = platform.getProvisioningProfileName(); if (platformName.isPresent() && !profile.getPlatforms().contains(platformName.get())) { String message = "Ignoring incompatible platform " + platformName.get() + " for profile " + profile.getUUID(); LOG.debug(message); lines.add(message); continue; } // Match against other keys of the entitlements. Otherwise, we could potentially select // a profile that doesn't have all the needed entitlements, causing a error when // installing to device. // // For example: get-task-allow, aps-environment, etc. if (entitlements.isPresent()) { ImmutableMap<String, NSObject> entitlementsDict = entitlements.get(); ImmutableMap<String, NSObject> profileEntitlements = profile.getEntitlements(); for (Entry<String, NSObject> entry : entitlementsDict.entrySet()) { NSObject profileEntitlement = profileEntitlements.get(entry.getKey()); if (!(FORCE_INCLUDE_ENTITLEMENTS.contains(entry.getKey()) || matchesOrArrayIsSubsetOf(entry.getValue(), profileEntitlement))) { match = false; String profileEntitlementString = getStringFromNSObject(profileEntitlement); String entryValueString = getStringFromNSObject(entry.getValue()); String message = "Profile " + profile.getProfilePath().getFileName() + " (" + profile.getUUID() + ") with bundleID " + profile.getAppID().getSecond() + " correctly matches. However there is a mismatched entitlement " + entry.getKey() + ";" + System.lineSeparator() + "value is: " + profileEntitlementString + "but expected: " + entryValueString; LOG.debug(message); lines.add(message); } } } // Reject any certificate which we know we can't sign with the supplied identities. ImmutableSet<HashCode> validFingerprints = profile.getDeveloperCertificateFingerprints(); if (match && identities.isPresent() && !validFingerprints.isEmpty()) { match = false; for (CodeSignIdentity identity : identities.get()) { Optional<HashCode> fingerprint = identity.getFingerprint(); if (fingerprint.isPresent() && validFingerprints.contains(fingerprint.get())) { match = true; break; } } if (!match) { String message = "Ignoring profile " + profile.getUUID() + " because it can't be signed with any valid identity in the current keychain."; LOG.debug(message); lines.add(message); continue; } } if (match && profileBundleID.length() > bestMatchLength) { bestMatchLength = profileBundleID.length(); bestMatch = Optional.of(profile); } } } if (!atLeastOneMatch) { lines.add(String.format("No provisioning profile matching the bundle ID %s was found", bundleID)); } LOG.debug("Found provisioning profile " + bestMatch); ImmutableList<String> diagnostics = lines.build(); diagnosticsBuffer.append(Joiner.on("\n").join(diagnostics)); return bestMatch; }
From source file:mod.steamnsteel.structure.StructureDefinitionBuilder.java
/** * Define what each character represents within the block map * @param representation char to unlocalized block name map * @exception NullPointerException thrown if block doesn't exist. *//*www . ja va 2s . c om*/ public void assignBlockDefinitions(ImmutableMap<Character, String> representation) { Builder<Character, IBlockState> builder = ImmutableMap.builder(); for (final Character c : representation.keySet()) { final String blockName = representation.get(c); final Block block = Block.getBlockFromName(blockName); checkNotNull(block, "assignBlockDefinitions.Block does not exist " + blockName); builder.put(c, block.getDefaultState()); } //default builder.put(' ', Blocks.air.getDefaultState()); builder.put('-', StructureRegistry.generalNull); repBlock = builder.build(); }
From source file:org.jclouds.location.suppliers.ZoneToRegionToProviderOrJustProvider.java
@Override public Set<? extends Location> get() { Builder<Location> locations = buildJustProviderOrRegions(); ImmutableMap<String, Location> idToLocation = uniqueIndex(locations.build(), new Function<Location, String>() { @Override//from w ww . j a v a 2 s. c o m public String apply(Location from) { return from.getId(); } }); if (zoneToRegion.size() == 1) return locations.build(); for (String zone : zoneToRegion.keySet()) { Location parent = idToLocation.get(zoneToRegion.get(zone)); LocationBuilder builder = new LocationBuilder().scope(LocationScope.ZONE).id(zone).description(zone) .parent(parent); if (isoCodesById.containsKey(zone)) builder.iso3166Codes(isoCodesById.get(zone)); // be cautious.. only inherit iso codes if the parent is a region // regions may be added dynamically, and we prefer to inherit an // empty set of codes from a region, then a provider, whose code // are likely hard-coded. else if (parent.getScope() == LocationScope.REGION) builder.iso3166Codes(parent.getIso3166Codes()); locations.add(builder.build()); } return locations.build(); }
From source file:com.google.gerrit.metrics.dropwizard.DropWizardMetricMaker.java
private synchronized void define(String name, Description desc) { if (descriptions.containsKey(name)) { ImmutableMap<String, String> annotations = descriptions.get(name); if (!desc.getAnnotations().get(Description.DESCRIPTION) .equals(annotations.get(Description.DESCRIPTION))) { throw new IllegalStateException(String.format("metric %s already defined", name)); }//from w w w.j a v a 2 s . co m } else { descriptions.put(name, desc.getAnnotations()); } }