List of usage examples for com.google.common.collect ImmutableMap containsKey
@Override public boolean containsKey(@Nullable Object key)
From source file:org.elasticsearch.action.bench.BenchmarkService.java
private final boolean isBenchmarkNode(DiscoveryNode node) { ImmutableMap<String, String> attributes = node.getAttributes(); if (attributes.containsKey("bench")) { String bench = attributes.get("bench"); return Boolean.parseBoolean(bench); }/*from ww w . j a v a2 s.c o m*/ return false; }
From source file:google.registry.tools.server.ListObjectsAction.java
/** * Returns the set of fields to return, aliased or not according to --full_field_names, and * with duplicates eliminated but the ordering otherwise preserved. */// w ww. j ava2s . c o m private ImmutableSet<String> getFieldsToUse(ImmutableSet<T> objects) { // Get the list of fields from the received parameter. List<String> fieldsToUse; if ((fields == null) || !fields.isPresent()) { fieldsToUse = new ArrayList<>(); } else { fieldsToUse = Splitter.on(',').splitToList(fields.get()); // Check whether any field name is the wildcard; if so, use all fields. if (fieldsToUse.contains("*")) { fieldsToUse = getAllAvailableFields(objects); } } // Handle aliases according to the state of the fullFieldNames parameter. final ImmutableMap<String, String> nameMapping = ((fullFieldNames != null) && fullFieldNames.isPresent() && fullFieldNames.get()) ? getFieldAliases() : getFieldAliases().inverse(); return ImmutableSet.copyOf(Iterables.transform(Iterables.concat(getPrimaryKeyFields(), fieldsToUse), new Function<String, String>() { @Override public String apply(String field) { // Rename fields that are in the map according to the map, and leave the others as is. return nameMapping.containsKey(field) ? nameMapping.get(field) : field; } })); }
From source file:com.spectralogic.ds3cli.command.GetBulk.java
private Iterable<Contents> getObjectsByPipe() throws CommandException { final ImmutableMap<String, String> pipedObjectMap = FileUtils.normalizedObjectNames(this.pipedFileNames); final FluentIterable<Contents> objectList = FluentIterable .from(new LazyIterable<>( new GetBucketLoaderFactory(getClient(), this.bucketName, null, null, 100, 5))) .filter(new Predicate<Contents>() { @Override//w w w. j ava 2 s . co m public boolean apply(@Nullable final Contents bulkObject) { return pipedObjectMap.containsKey(bulkObject.getKey()); } }); // look for objects in the piped list not in bucket final FluentIterable<String> objectNameList = FluentIterable.from(objectList) .transform(new Function<Contents, String>() { @Override public String apply(@Nullable final Contents bulkObject) { return bulkObject.getKey(); } }); for (final String object : pipedObjectMap.keySet()) { if (objectNameList.contains(object)) { LOG.info("Restore: {}", object); } else { throw new CommandException("Object: " + object + " not found in bucket"); } } return objectList; }
From source file:com.opengamma.strata.pricer.rate.ImmutableRatesProvider.java
/** * Combines this provider with another.// www . j a v a 2 s .c o m * <p> * If the two providers have curves or time series for the same currency or index, * an {@link IllegalAccessException} is thrown. No attempt is made to combine the * FX providers, instead one is supplied. * * @param other the other rates provider * @param fxProvider the FX rate provider to use * @return the combined provider */ public ImmutableRatesProvider combinedWith(ImmutableRatesProvider other, FxRateProvider fxProvider) { ImmutableRatesProviderBuilder merged = other.toBuilder(); // discount ImmutableMap<Currency, Curve> dscMap1 = discountCurves; ImmutableMap<Currency, Curve> dscMap2 = other.discountCurves; for (Entry<Currency, Curve> entry : dscMap1.entrySet()) { ArgChecker.isTrue(!dscMap2.containsKey(entry.getKey()), "conflict on discount curve, currency '{}' appears twice in the providers", entry.getKey()); merged.discountCurve(entry.getKey(), entry.getValue()); } // forward ImmutableMap<Index, Curve> indexMap1 = indexCurves; ImmutableMap<Index, Curve> indexMap2 = other.indexCurves; for (Entry<Index, Curve> entry : indexMap1.entrySet()) { ArgChecker.isTrue(!indexMap2.containsKey(entry.getKey()), "conflict on index curve, index '{}' appears twice in the providers", entry.getKey()); merged.indexCurve(entry.getKey(), entry.getValue()); } // time series Map<Index, LocalDateDoubleTimeSeries> tsMap1 = timeSeries; Map<Index, LocalDateDoubleTimeSeries> tsMap2 = other.timeSeries; for (Entry<Index, LocalDateDoubleTimeSeries> entry : tsMap1.entrySet()) { ArgChecker.isTrue(!tsMap2.containsKey(entry.getKey()), "conflict on time series, index '{}' appears twice in the providers", entry.getKey()); merged.timeSeries(entry.getKey(), entry.getValue()); } merged.fxRateProvider(fxProvider); return merged.build(); }
From source file:org.sonar.web.it.ProfileGenerator.java
static void generate(Orchestrator orchestrator, String language, String repositoryKey, ImmutableMap<String, ImmutableMap<String, String>> rulesParameters, Set<String> excluded) { try {/*from w ww . java2 s . c o m*/ StringBuilder sb = new StringBuilder().append("<profile>").append("<name>rules</name>") .append("<language>").append(language).append("</language>").append("<alerts>") .append("<alert>").append("<metric>blocker_violations</metric>") .append("<operator>></operator>").append("<warning></warning>").append("<error>0</error>") .append("</alert>").append("<alert>").append("<metric>info_violations</metric>") .append("<operator>></operator>").append("<warning></warning>").append("<error>0</error>") .append("</alert>").append("</alerts>").append("<rules>"); List<String> ruleKeys = Lists.newArrayList(); String json = new HttpRequestFactory(orchestrator.getServer().getUrl()).get("/api/rules/search", ImmutableMap.<String, Object>of("languages", language, "repositories", repositoryKey, "ps", "1000")); @SuppressWarnings("unchecked") List<Map> jsonRules = (List<Map>) ((Map) JSONValue.parse(json)).get("rules"); for (Map jsonRule : jsonRules) { String key = (String) jsonRule.get("key"); ruleKeys.add(key.split(":")[1]); } for (String key : ruleKeys) { if (excluded.contains(key)) { continue; } sb.append("<rule>").append("<repositoryKey>").append(repositoryKey).append("</repositoryKey>") .append("<key>").append(key).append("</key>").append("<priority>INFO</priority>"); if (rulesParameters.containsKey(key)) { sb.append("<parameters>"); for (Map.Entry<String, String> parameter : rulesParameters.get(key).entrySet()) { sb.append("<parameter>").append("<key>").append(parameter.getKey()).append("</key>") .append("<value>").append(parameter.getValue()).append("</value>") .append("</parameter>"); } sb.append("</parameters>"); } sb.append("</rule>"); } sb.append("</rules>").append("</profile>"); File file = File.createTempFile("profile", ".xml"); Files.write(sb, file, Charsets.UTF_8); orchestrator.getServer().restoreProfile(FileLocation.of(file)); file.delete(); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:org.elasticsearch.rest.action.cat.RestNodeAttrsAction.java
private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) { boolean fullId = req.paramAsBoolean("full_id", false); DiscoveryNodes nodes = state.getState().nodes(); Table table = getTableWithHeader(req); for (DiscoveryNode node : nodes) { NodeInfo info = nodesInfo.getNodesMap().get(node.id()); ImmutableMap<String, String> attrs = node.getAttributes(); for (String att : attrs.keySet()) { table.startRow();/* w ww. j a v a 2 s .c o m*/ table.addCell(node.name()); table.addCell(fullId ? node.id() : Strings.substring(node.getId(), 0, 4)); table.addCell(info == null ? null : info.getProcess().getId()); table.addCell(node.getHostName()); table.addCell(node.getHostAddress()); if (node.address() instanceof InetSocketTransportAddress) { table.addCell(((InetSocketTransportAddress) node.address()).address().getPort()); } else { table.addCell("-"); } table.addCell(att); table.addCell(attrs.containsKey(att) ? attrs.get(att) : null); table.endRow(); } } return table; }
From source file:barrysw19.calculon.engine.ChessEngine.java
private List<SearchContext> getScoredMoves(final BitBoard bitBoard, final List<SearchContext> movesFilter) { ImmutableMap<String, SearchContext> movesToAnalyse = Maps.uniqueIndex(movesFilter, SearchContext::getAlgebraicMove); List<FutureTask<SearchContext>> tasks = new ArrayList<>(); for (Iterator<BitBoardMove> moveItr = moveGeneratorFactory.createMoveGenerator(bitBoard); moveItr .hasNext();) {/*w w w . j a va 2 s.com*/ final BitBoardMove move = moveItr.next(); final BitBoard cloneBitBoard = BitBoard.createCopy(bitBoard); final String algebraic = move.getAlgebraic(); if (!movesToAnalyse.isEmpty() && !movesToAnalyse.containsKey(algebraic)) { // LOG.debug("Skipping move {}", algebraic); continue; } FutureTask<SearchContext> scoredMoveFutureTask = new FutureTask<>(() -> { cloneBitBoard.makeMove(move); final SearchContext searchContext = new SearchContext(algebraic); int score = alphaBeta(-BIG_VALUE, BIG_VALUE, depthForSearch, cloneBitBoard, searchContext.descend()); searchContext.setScore(score); LOG.debug("Ran: {}", searchContext); cloneBitBoard.unmakeMove(); return searchContext; }); tasks.add(scoredMoveFutureTask); executorService.submit(scoredMoveFutureTask); } final List<SearchContext> rv = new ArrayList<>(); for (FutureTask<SearchContext> i : tasks) { try { rv.add(i.get()); } catch (InterruptedException | ExecutionException e) { LOG.error("Unexpected exception", e); } } return rv; }
From source file:com.facebook.buck.cli.BuckConfig.java
public ImmutableSet<Pattern> getTempFilePatterns() { final ImmutableMap<String, String> projectConfig = getEntriesForSection("project"); final String tempFilesKey = "temp_files"; ImmutableSet.Builder<Pattern> builder = ImmutableSet.builder(); if (projectConfig.containsKey(tempFilesKey)) { for (String regex : Splitter.on(',').omitEmptyStrings().trimResults() .split(projectConfig.get(tempFilesKey))) { builder.add(Pattern.compile(regex)); }// w w w. ja v a2s.c o m } return builder.build(); }
From source file:edu.mit.streamjit.impl.distributed.StreamJitAppManager.java
/** * Setup the headchannel and tailchannel. * // w ww. j av a 2 s . c om * @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: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 w w w.j a v a 2s . c o m*/ * @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"); } } }