List of usage examples for com.google.common.collect ImmutableMap get
V get(Object key);
From source file:com.facebook.buck.apple.toolchain.AbstractProvisioningProfileMetadata.java
public ImmutableMap<String, NSObject> getMergeableEntitlements() { ImmutableSet<String> includedKeys = ImmutableSet.of("application-identifier", "beta-reports-active", "get-task-allow", "com.apple.developer.aps-environment", "com.apple.developer.team-identifier"); ImmutableMap<String, NSObject> allEntitlements = getEntitlements(); ImmutableMap.Builder<String, NSObject> filteredEntitlementsBuilder = ImmutableMap.builder(); for (String key : allEntitlements.keySet()) { if (includedKeys.contains(key)) { filteredEntitlementsBuilder.put(key, allEntitlements.get(key)); }/* w w w . j a va 2 s . c om*/ } return filteredEntitlementsBuilder.build(); }
From source file:net.minecrell.workbench.tools.mapping.BaseMappings.java
@SuppressWarnings("unchecked") private <T extends Name> ImmutableBiMap<T, T> applyMapped(ImmutableBiMap<T, T> mappings, ImmutableMap<String, BaseName> base, Consumer<T> consumer) { ImmutableBiMap.Builder<T, T> builder = ImmutableBiMap.builder(); mappings.forEach((original, mapped) -> { BaseName name = base.get(mapped.getName()); if (name != null) { T result = (T) mapped.apply(context, name); if (consumer != null) { consumer.accept(result); }/*from w ww . j a v a 2 s .c om*/ builder.put(original, result); } else { builder.put(original, mapped); } }); return builder.build(); }
From source file:com.baasbox.controllers.actions.filters.SessionTokenAccess.java
@Override public boolean setCredential(Context ctx) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("SessionTokenAccess"); //injects the user data & credential into the context String token = ctx.request().getHeader(SessionKeys.TOKEN.toString()); if (StringUtils.isEmpty(token)) token = ctx.request().getQueryString(SessionKeys.TOKEN.toString()); if (token != null) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("Received session token " + token); ImmutableMap<SessionKeys, ? extends Object> sessionData = SessionTokenProvider.getSessionTokenProvider() .getSession(token);//from w ww . j a v a2 s . c o m if (sessionData != null) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("Token identified: "); ctx.args.put("username", sessionData.get(SessionKeys.USERNAME)); ctx.args.put("password", sessionData.get(SessionKeys.PASSWORD)); ctx.args.put("appcode", sessionData.get(SessionKeys.APP_CODE)); ctx.args.put("token", token); if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("username: " + (String) sessionData.get(SessionKeys.USERNAME)); if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("password: <hidden>"); if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("appcode: " + (String) sessionData.get(SessionKeys.APP_CODE)); if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("token: " + token); return true; } else { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("Session Token unknown"); return false; } } else { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("Session Token header is null"); return false; } }
From source file:com.facebook.buck.apple.xcode.ProjectGenerator.java
/** * Once we've generated the target, check if there's already a GID for a * target with the same name in an existing on-disk Xcode project. * * If there is, then re-use that target's GID instead of generating * a new one based on the target's name. *//*from w w w .j av a 2s . c o m*/ private static void setTargetGIDIfNameInMap(PBXTarget target, ImmutableMap<String, String> targetNameToGIDMap) { @Nullable String existingTargetGID = targetNameToGIDMap.get(target.getName()); if (existingTargetGID == null) { return; } if (target.getGlobalID() == null) { target.setGlobalID(existingTargetGID); } else { // We better not have already generated some other GID for this // target. Preconditions.checkState(target.getGlobalID().equals(existingTargetGID)); } }
From source file:com.facebook.buck.apple.CompilationDatabase.java
static AppleSdkPaths selectNewestSimulatorSdk(ImmutableMap<String, AppleSdkPaths> allAppleSdkPaths) { final String prefix = "iphonesimulator"; List<String> iphoneSimulatorVersions = Lists .newArrayList(FluentIterable.from(allAppleSdkPaths.keySet()).filter(new Predicate<String>() { @Override//from w ww . j a va 2 s . c o m public boolean apply(String sdkName) { return sdkName.startsWith(prefix); } }).transform(new Function<String, String>() { @Override public String apply(String sdkName) { return sdkName.substring(prefix.length()); } }).toSet()); if (iphoneSimulatorVersions.isEmpty()) { throw new RuntimeException("No iphonesimulator found in: " + allAppleSdkPaths.keySet()); } Collections.sort(iphoneSimulatorVersions, new VersionStringComparator()); String version = iphoneSimulatorVersions.get(iphoneSimulatorVersions.size() - 1); return Preconditions.checkNotNull(allAppleSdkPaths.get(prefix + version)); }
From source file:org.kiji.scoring.impl.InternalFreshKijiTableReader.java
/** * Filter a map of Fresheners down to only those attached to columns in a given list. Columns * which do not have Fresheners attached will not be reflected in the return value of this * method. An empty return indicates that no Fresheners are attached to the given columns. * * @param columnsToFreshen a list of columns for which to get Fresheners. * @param fresheners a map of all available fresheners. This map will not be modified by this * method./* w ww. j a v a 2s.c om*/ * @return all Fresheners attached to columns in columnsToFresh available in fresheners. */ private static ImmutableMap<KijiColumnName, Freshener> filterFresheners( final ImmutableList<KijiColumnName> columnsToFreshen, final ImmutableMap<KijiColumnName, Freshener> fresheners) { final Map<KijiColumnName, Freshener> collectedFresheners = Maps.newHashMap(); for (KijiColumnName column : columnsToFreshen) { if (column.isFullyQualified()) { final Freshener freshener = fresheners.get(column); if (null != freshener) { collectedFresheners.put(column, freshener); } else { final KijiColumnName family = new KijiColumnName(column.getFamily(), null); final Freshener familyFreshener = fresheners.get(family); if (null != familyFreshener) { collectedFresheners.put(family, familyFreshener); } } } else { for (Map.Entry<KijiColumnName, Freshener> freshenerEntry : fresheners.entrySet()) { if (freshenerEntry.getKey().getFamily().equals(column.getFamily())) { collectedFresheners.put(freshenerEntry.getKey(), freshenerEntry.getValue()); } } } } return ImmutableMap.copyOf(collectedFresheners); }
From source file:com.streamreduce.rest.resource.api.SearchMessageResource.java
/** * * @response.representation.200.doc Search results * @response.representation.200.mediaType application/json * @response.representation.500.doc If a general exception occurs. * @response.representation.404.mediaType text/plain * * @param query// w w w .ja v a2s.c o m * @param resourceName * @param uriInfo * @return the response body */ @POST @Path("{resourceName}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response searchMessagesPassthrough(JSONObject query, @PathParam("resourceName") String resourceName, @Context UriInfo uriInfo) { try { Account currentAccount = securityService.getCurrentUser().getAccount(); ImmutableMap<String, String> queryParameters = ImmutableMap .copyOf(flattenValues(uriInfo.getQueryParameters())); List<SobaMessage> sobaMessages = searchService.searchMessages(currentAccount, resourceName, queryParameters, query); boolean fullText = queryParameters.get("fullText") != null ? Boolean.valueOf(queryParameters.get("fullText")) : false; return Response.ok(SobaMessageResponseDTO.fromSobaMessages(sobaMessages, fullText)).build(); } catch (Exception e) { String errorMessage = "Unable to perform search: " + e.getMessage(); logger.info(errorMessage, e); return error(errorMessage, Response.serverError()); } }
From source file:com.pinterest.pinlater.backends.mysql.MySQLHealthMonitor.java
public synchronized boolean isHealthy(String shardName) { long currentTimeMillis = System.currentTimeMillis(); ImmutableMap<String, ShardState> shardHealthMap = shardHealthMapRef.get(); if (!shardHealthMap.containsKey(shardName)) { LOG.error("Health monitor map doesn't have shard name {}", shardName); return false; }/* w ww .j a va2s . com*/ ShardState shardState = shardHealthMap.get(shardName); if (shardState.isHealthy) { if (shardState.healthSamples.remainingCapacity() == 0 && shardState.numSuccessesInWindow < healthySuccessThreshold) { LOG.info("Marking mysql shard {} unhealthy due to {} successes / 100", shardName, shardState.numSuccessesInWindow); shardState.isHealthy = false; shardState.lastUnhealthyTimestampMillis = currentTimeMillis; } } else if (currentTimeMillis >= shardState.lastUnhealthyTimestampMillis + unhealthyResetPeriodMillis) { LOG.info("Resetting health state for mysql shard {}", shardName); shardState.reset(); } return shardState.isHealthy; }
From source file:com.wealdtech.hawk.HawkServer.java
/** * Authenticate a request using a Hawk bewit. * @param credentials the Hawk credentials against which to authenticate * @param uri the URI of the request//from w w w .j a va 2 s.co m */ public void authenticate(final HawkCredentials credentials, final URI uri) { final String bewit = extractBewit(uri); final ImmutableMap<String, String> bewitFields = splitBewit(bewit); checkNotNull(bewitFields.get(HEADER_ID), "ID missing from bewit"); checkNotNull(bewitFields.get(HEADER_EXPIRY), "Expiry missing from bewit"); checkNotNull(bewitFields.get(HEADER_MAC), "MAC missing from bewit"); checkState((credentials.getKeyId().equals(bewitFields.get(HEADER_ID))), "The id in the bewit is not recognised"); final Long expiry = Long.parseLong(bewitFields.get(HEADER_EXPIRY)); final URI strippedUri = stripBewit(uri); final String calculatedMac = Hawk.calculateMAC(credentials, Hawk.AuthType.BEWIT, expiry, strippedUri, null, null, null, bewitFields.get(HEADER_EXT), null, null); if (!timeConstantEquals(calculatedMac, bewitFields.get(HEADER_MAC))) { throw new DataError.Authentication("The MAC in the request does not match the server-calculated MAC"); } }
From source file:org.sonar.java.checks.HiddenFieldCheck.java
private void isVariableHidingField(VariableTree variableTree) { for (ImmutableMap<String, VariableTree> variables : fields) { if (variables.values().contains(variableTree)) { return; }/*from w w w. j a v a 2 s . c o m*/ String identifier = variableTree.simpleName().name(); VariableTree hiddenVariable = variables.get(identifier); if (!flattenExcludedVariables.contains(variableTree) && hiddenVariable != null && !isInStaticInnerClass(hiddenVariable, variableTree)) { int line = hiddenVariable.firstToken().line(); reportIssue(variableTree.simpleName(), "Rename \"" + identifier + "\" which hides the field declared at line " + line + "."); return; } } }