List of usage examples for com.google.common.collect ImmutableMap get
V get(Object key);
From source file:com.facebook.buck.model.macros.MacroFinder.java
/** * Expand macros embedded in a string./*from ww w .j av a2s .c o m*/ * * @param replacers a map of macro names to {@link MacroReplacer} objects used to expand them. * @param blob the input string containing macros to be expanded * @param resolveEscaping whether to drop characters used to escape literal uses of `$(...)` * @return a copy of the input string with all macros expanded */ public static <T> T replace(ImmutableMap<String, MacroReplacer<T>> replacers, String blob, boolean resolveEscaping, MacroCombiner<T> combiner) throws MacroException { // Iterate over all macros found in the string, expanding each found macro. int lastEnd = 0; MacroFinderAutomaton matcher = new MacroFinderAutomaton(blob); while (matcher.hasNext()) { MacroMatchResult matchResult = matcher.next(); // Add everything from the original string since the last match to this one. combiner.addString(blob.substring(lastEnd, matchResult.getStartIndex())); // If the macro is escaped, add the macro text (but omit the escaping backslash) if (matchResult.isEscaped()) { combiner.addString(blob.substring(matchResult.getStartIndex() + (resolveEscaping ? 1 : 0), matchResult.getEndIndex())); } else { // Call the relevant expander and add the expanded value to the string. MacroReplacer<T> replacer = replacers.get(matchResult.getMacroType()); if (replacer == null) { throw new MacroException(String.format("expanding %s: no such macro \"%s\"", blob.substring(matchResult.getStartIndex(), matchResult.getEndIndex()), matchResult.getMacroType())); } try { combiner.add(replacer.replace(matchResult)); } catch (MacroException e) { throw new MacroException(String.format("expanding %s: %s", blob.substring(matchResult.getStartIndex(), matchResult.getEndIndex()), e.getMessage()), e); } } lastEnd = matchResult.getEndIndex(); } // Append the remaining part of the original string after the last match. combiner.addString(blob.substring(lastEnd, blob.length())); return combiner.build(); }
From source file:com.facebook.buck.core.macros.MacroFinder.java
/** * Expand macros embedded in a string.// w w w. j av a 2s. c o m * * @param replacers a map of macro names to {@link MacroReplacer} objects used to expand them. * @param blob the input string containing macros to be expanded * @param resolveEscaping whether to drop characters used to escape literal uses of `$(...)` * @return a copy of the input string with all macros expanded */ public static <T> T replace(ImmutableMap<String, MacroReplacer<T>> replacers, String blob, boolean resolveEscaping, MacroCombiner<T> combiner) throws MacroException { // Iterate over all macros found in the string, expanding each found macro. int lastEnd = 0; MacroFinderAutomaton matcher = new MacroFinderAutomaton(blob); while (matcher.hasNext()) { MacroMatchResult matchResult = matcher.next(); // Add everything from the original string since the last match to this one. combiner.addString(blob.substring(lastEnd, matchResult.getStartIndex())); // If the macro is escaped, add the macro text (but omit the escaping backslash) if (matchResult.isEscaped()) { combiner.addString(blob.substring(matchResult.getStartIndex() + (resolveEscaping ? 1 : 0), matchResult.getEndIndex())); } else { // Call the relevant expander and add the expanded value to the string. MacroReplacer<T> replacer = replacers.get(matchResult.getMacroType()); if (replacer == null) { throw new MacroException(String.format("expanding %s: no such macro \"%s\"", blob.substring(matchResult.getStartIndex(), matchResult.getEndIndex()), matchResult.getMacroType())); } try { combiner.add(replacer.replace(matchResult)); } catch (MacroException e) { throw new MacroException(String.format("expanding %s: %s", blob.substring(matchResult.getStartIndex(), matchResult.getEndIndex()), e.getMessage()), e); } } lastEnd = matchResult.getEndIndex(); } // Append the remaining part of the original string after the last match. combiner.addString(blob.substring(lastEnd)); return combiner.build(); }
From source file:org.apache.rya.indexing.pcj.fluo.client.PcjAdminClient.java
private static String makeUsage(final ImmutableMap<String, PcjAdminClientCommand> commands) { final StringBuilder usage = new StringBuilder(); usage.append("Usage: ").append(PcjAdminClient.class.getSimpleName()) .append(" <command> (<argument> ... )\n"); usage.append("\n"); usage.append("Possible Commands:\n"); // Sort and find the max width of the commands. final List<String> sortedCommandNames = Lists.newArrayList(commands.keySet()); Collections.sort(sortedCommandNames); int maxCommandLength = 0; for (final String commandName : sortedCommandNames) { maxCommandLength = commandName.length() > maxCommandLength ? commandName.length() : maxCommandLength; }/* w w w . jav a 2 s . co m*/ // Add each command to the usage. final String commandFormat = " %-" + (maxCommandLength) + "s - %s\n"; for (final String commandName : sortedCommandNames) { final String commandDescription = commands.get(commandName).getDescription(); usage.append(String.format(commandFormat, commandName, commandDescription)); } return usage.toString(); }
From source file:mod.rankshank.arbitraria.client.item.spraybottle.ModelSprayBottleFluid.java
@Override public IModel process(ImmutableMap<String, String> customData) { Fluid dataFluid = FluidRegistry.getFluid(customData.get("fluid")); return new ModelSprayBottleFluid(this.bottle, this.filler, dataFluid == null ? this.fluid : dataFluid); }
From source file:com.facebook.buck.remoteexecution.RemoteExecutionConsoleLineProvider.java
private int getLocallyBuiltRules(int totalBuildRules, ImmutableMap<State, Integer> actionsPerState) { int remotelyExecutedBuildRules = Objects.requireNonNull(actionsPerState.get(State.ACTION_SUCCEEDED)) + actionsPerState.get(State.ACTION_FAILED); return Math.max(0, totalBuildRules - remotelyExecutedBuildRules); }
From source file:org.graylog2.security.InMemoryRolePermissionResolver.java
@Nonnull public Set<String> resolveStringPermission(String roleId) { final ImmutableMap<String, Role> index = idToRoleIndex.get(); final Role role = index.get(roleId); if (role == null) { log.debug("Unknown role {}, cannot resolve permissions.", roleId); return Collections.emptySet(); }// ww w.j ava2s . c om final Set<String> permissions = role.getPermissions(); if (permissions == null) { log.debug("Role {} has no permissions assigned, cannot resolve permissions.", roleId); return Collections.emptySet(); } return permissions; }
From source file:com.jejking.hh.nord.gazetteer.osm.poi.IsOsmFeaturePointOfInterest.java
private boolean hasInterestingValue(ImmutableMap<String, ImmutableSet<String>> map, Map<String, String> props, String tagInterestingIfNamed) { return map.get(tagInterestingIfNamed).isEmpty() || map.get(tagInterestingIfNamed).contains(props.get(tagInterestingIfNamed)); }
From source file:org.eclipse.xtext.example.arithmetics.interpreter.Calculator.java
protected BigDecimal internalEvaluate(FunctionCall e, ImmutableMap<String, BigDecimal> values) { if (e.getFunc() instanceof DeclaredParameter) { return values.get(e.getFunc().getName()); }/*from w w w . j a v a2s .c o m*/ Definition d = (Definition) e.getFunc(); Map<String, BigDecimal> params = Maps.newHashMap(); for (int i = 0; i < e.getArgs().size(); i++) { DeclaredParameter declaredParameter = d.getArgs().get(i); BigDecimal evaluate = evaluate(e.getArgs().get(i), values); params.put(declaredParameter.getName(), evaluate); } return evaluate(d.getExpr(), ImmutableMap.copyOf(params)); }
From source file:com.baasbox.controllers.User.java
@With({ AdminCredentialWrapFilter.class, ConnectToDBFilter.class }) @BodyParser.Of(BodyParser.Json.class) public static Result signUp() throws JsonProcessingException, IOException { if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method Start"); Http.RequestBody body = request().body(); JsonNode bodyJson = body.asJson();//from w ww.j a v a 2s .c o m if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("signUp bodyJson: " + bodyJson); if (bodyJson == null) return badRequest( "The body payload cannot be empty. Hint: put in the request header Content-Type: application/json"); //check and validate input if (!bodyJson.has("username")) return badRequest("The 'username' field is missing"); if (!bodyJson.has("password")) return badRequest("The 'password' field is missing"); //extract mandatory fields JsonNode nonAppUserAttributes = bodyJson.get(UserDao.ATTRIBUTES_VISIBLE_BY_ANONYMOUS_USER); JsonNode privateAttributes = bodyJson.get(UserDao.ATTRIBUTES_VISIBLE_ONLY_BY_THE_USER); JsonNode friendsAttributes = bodyJson.get(UserDao.ATTRIBUTES_VISIBLE_BY_FRIENDS_USER); JsonNode appUsersAttributes = bodyJson.get(UserDao.ATTRIBUTES_VISIBLE_BY_REGISTERED_USER); String username = (String) bodyJson.findValuesAsText("username").get(0); String password = (String) bodyJson.findValuesAsText("password").get(0); String appcode = (String) ctx().args.get("appcode"); if (privateAttributes != null && privateAttributes.has("email")) { //check if email address is valid if (!Util.validateEmail((String) privateAttributes.findValuesAsText("email").get(0))) return badRequest("The email address must be valid."); } if (StringUtils.isEmpty(password)) return status(422, "The password field cannot be empty"); //try to signup new user ODocument profile = null; try { UserService.signUp(username, password, null, nonAppUserAttributes, privateAttributes, friendsAttributes, appUsersAttributes, false); //due to issue 412, we have to reload the profile profile = UserService.getUserProfilebyUsername(username); } catch (InvalidJsonException e) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("signUp", e); return badRequest("One or more profile sections is not a valid JSON object"); } catch (UserAlreadyExistsException e) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("signUp", e); // Return a generic error message if the username is already in use. return badRequest("Error signing up"); } catch (EmailAlreadyUsedException e) { // Return a generic error message if the email is already in use. if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("signUp", e); return badRequest("Error signing up"); } catch (Throwable e) { BaasBoxLogger.warn("signUp", e); if (Play.isDev()) return internalServerError(ExceptionUtils.getFullStackTrace(e)); else return internalServerError(ExceptionUtils.getMessage(e)); } if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method End"); ImmutableMap<SessionKeys, ? extends Object> sessionObject = SessionTokenProvider.getSessionTokenProvider() .setSession(appcode, username, password); response().setHeader(SessionKeys.TOKEN.toString(), (String) sessionObject.get(SessionKeys.TOKEN)); String result = prepareResponseToJson(profile); ObjectMapper mapper = new ObjectMapper(); result = result.substring(0, result.lastIndexOf("}")) + ",\"" + SessionKeys.TOKEN.toString() + "\":\"" + (String) sessionObject.get(SessionKeys.TOKEN) + "\"}"; JsonNode jn = mapper.readTree(result); return created(jn); }
From source file:io.fabric8.process.fabric.commands.ContainerProcessControllerSupport.java
void doWithAuthentication(String jmxUser, String jmxPassword) throws Exception { {//from ww w .jav a 2s . com ContainerInstallOptions options = ContainerInstallOptions.builder().container(getContainerObject()) .user(jmxUser).password(jmxPassword).build(); ImmutableMap<String, Installation> map = getContainerProcessManager().listInstallationMap(options); for (String id : ids) { Installation installation = map.get(id); if (installation == null) { System.out.println("No such process number: " + id); } else { doControlCommand(installation); } } } }