List of usage examples for com.google.common.collect ImmutableMap keySet
public ImmutableSet<K> keySet()
From source file:org.nuxeo.ecm.core.storage.dbs.DBSCachingRepository.java
@Override public List<State> readStates(List<String> ids) { ImmutableMap<String, State> statesMap = cache.getAllPresent(ids); List<String> idsToRetrieve = new ArrayList<>(ids); idsToRetrieve.removeAll(statesMap.keySet()); // Read missing states from repository List<State> states = repository.readStates(idsToRetrieve); // Cache them states.forEach(this::putInCache); // Add previous cached one states.addAll(statesMap.values());/* ww w . j a v a 2 s . c o m*/ // Sort them states.sort(Comparator.comparing(state -> state.get(KEY_ID).toString(), Ordering.explicit(ids))); return states; }
From source file:org.mule.module.oauth2.AbstractOAuthAuthorizationTestCase.java
private void configureWireMockToExpectTokenPathRequestForClientCredentialsGrantTypeWithMapResponse( String accessToken, ImmutableMap customParameters) { customParameters = new ImmutableMap.Builder().putAll(customParameters) .put(OAuthConstants.ACCESS_TOKEN_PARAMETER, accessToken) .put(OAuthConstants.EXPIRES_IN_PARAMETER, EXPIRES_IN).build(); final ImmutableMap.Builder bodyParametersMapBuilder = new ImmutableMap.Builder(); for (Object customParameterName : customParameters.keySet()) { bodyParametersMapBuilder.put(customParameterName, customParameters.get(customParameterName)); }/*from w w w.jav a2 s . co m*/ final String body = HttpParser.encodeString("UTF-8", bodyParametersMapBuilder.build()); wireMockRule.stubFor(post(urlEqualTo(TOKEN_PATH)).willReturn(aResponse().withBody(body) .withHeader(HttpHeaders.Names.CONTENT_TYPE, HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED))); }
From source file:de.faustedition.genesis.lines.VerseStatisticsResource.java
@Get("json") public Representation chartData() { final List<Map<String, Object>> chartData = Lists.newLinkedList(); final ImmutableMap<String, MaterialUnit> documentIndex = Maps.uniqueIndex(verseStatistics.keySet(), new Function<MaterialUnit, String>() { @Override/* www . ja v a2 s . c o m*/ public String apply(@Nullable MaterialUnit input) { return input.toString() + " [" + input.node.getId() + "]"; } }); for (String documentDesc : Ordering.natural().immutableSortedCopy(documentIndex.keySet())) { final List<Map<String, Object>> intervals = Lists.newLinkedList(); for (VerseInterval interval : Ordering.from(VerseManager.INTERVAL_COMPARATOR) .immutableSortedCopy(verseStatistics.get(documentIndex.get(documentDesc)))) { intervals.add(new ModelMap().addAttribute("start", Math.max(from, interval.getStart())) .addAttribute("end", Math.min(to, interval.getEnd()))); } chartData.add(new ModelMap().addAttribute("sigil", documentDesc.substring(0, documentDesc.indexOf('['))) /*.addAttribute("transcript", documentIndex.get(documentDesc).node.getId())*/ .addAttribute("source", ((Document) documentIndex.get(documentDesc)).getSource().toString()) .addAttribute("intervals", intervals)); } return jsonRepresentationFactory.map(chartData, false); }
From source file:org.gradle.model.dsl.internal.spike.ScopeVisitor.java
private void addCreator(String path, ClosureExpression creator) { final ImmutableMap<String, String> referenceAliasesMap = ImmutableMap.copyOf(referenceAliases); ReferenceExtractor extractor = new ReferenceExtractor(sourceUnit, referenceAliasesMap); Iterators.removeIf(creator.getVariableScope().getReferencedLocalVariablesIterator(), new Predicate<Variable>() { public boolean apply(Variable variable) { return referenceAliasesMap.keySet().contains(variable.getName()); }//from w ww. ja v a 2 s . c o m }); creator.getCode().visit(extractor); statementGenerator.addCreator(path, creator, extractor.getReferencedPaths()); }
From source file:org.apache.atlas.typesystem.persistence.ReferenceableInstance.java
public ReferenceableInstance(Id id, String dataTypeName, AtlasSystemAttributes systemAttributes, FieldMapping fieldMapping, boolean[] nullFlags, boolean[] explicitSets, boolean[] bools, byte[] bytes, short[] shorts, int[] ints, long[] longs, float[] floats, double[] doubles, BigDecimal[] bigDecimals, BigInteger[] bigIntegers, Date[] dates, String[] strings, ImmutableList<Object>[] arrays, ImmutableMap<Object, Object>[] maps, StructInstance[] structs, ReferenceableInstance[] referenceableInstances, Id[] ids, ImmutableMap<String, ITypedStruct> traits) { super(dataTypeName, fieldMapping, nullFlags, explicitSets, bools, bytes, shorts, ints, longs, floats, doubles, bigDecimals, bigIntegers, dates, strings, arrays, maps, structs, referenceableInstances, ids);// w ww .j a v a2 s . co m this.id = id; this.traits = traits; ImmutableList.Builder<String> b = new ImmutableList.Builder<>(); for (String t : traits.keySet()) { b.add(t); } this.traitNames = b.build(); if (systemAttributes == null) { this.systemAttributes = new AtlasSystemAttributes(); } else { this.systemAttributes = systemAttributes; } }
From source file:com.kibana.multitenancy.plugin.KibanaUserReindexAction.java
public void apply(String action, ActionResponse response, ActionListener listener, ActionFilterChain chain) { logger.debug("Response with Action '{}' and class '{}'", action, response.getClass()); if (containsKibanaUserIndex(response)) { if (response instanceof IndexResponse) { final IndexResponse ir = (IndexResponse) response; String index = getIndex(ir); response = new IndexResponse(index, ir.getType(), ir.getId(), ir.getVersion(), ir.isCreated()); //ElasticSearch 2.0 changes to set Shard Info ((IndexResponse) response).setShardInfo(ir.getShardInfo()); } else if (response instanceof GetResponse) { response = new GetResponse(buildNewResult((GetResponse) response)); } else if (response instanceof DeleteResponse) { final DeleteResponse dr = (DeleteResponse) response; String index = getIndex(dr); response = new DeleteResponse(index, dr.getType(), dr.getId(), dr.getVersion(), dr.isFound()); //ElasticSearch 2.0 changes to set Shard Info ((DeleteResponse) response).setShardInfo(dr.getShardInfo()); } else if (response instanceof MultiGetResponse) { final MultiGetResponse mgr = (MultiGetResponse) response; MultiGetItemResponse[] responses = new MultiGetItemResponse[mgr.getResponses().length]; int index = 0; for (MultiGetItemResponse item : mgr.getResponses()) { GetResponse itemResponse = item.getResponse(); Failure itemFailure = item.getFailure(); GetResponse getResponse = (itemResponse != null) ? new GetResponse(buildNewResult(itemResponse)) : null;/*from w w w. j a v a 2 s . com*/ Failure failure = (itemFailure != null) ? buildNewFailure(itemFailure) : null; responses[index] = new MultiGetItemResponse(getResponse, failure); index++; } response = new MultiGetResponse(responses); } else if (response instanceof GetFieldMappingsResponse) { final GetFieldMappingsResponse gfmResponse = (GetFieldMappingsResponse) response; ImmutableMap<String, ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>>> mappings = gfmResponse .mappings(); String index = ""; for (String key : mappings.keySet()) { index = key; if (isKibanaUserIndex(index)) { index = kibanaIndex; } } BytesStreamOutput bso = new BytesStreamOutput(); try { MappingResponseRemapper remapper = new MappingResponseRemapper(); remapper.updateMappingResponse(bso, index, mappings); //Sushant:ElsaticSearch 2.0 Breaking changes //BytesStreamInput input = new BytesStreamInput(bso.bytes()); //response.readFrom(input); response.readFrom(bso.bytes().streamInput()); } catch (IOException e) { logger.error("Error while rewriting GetFieldMappingsResponse", e); } } } chain.proceed(action, response, listener); }
From source file:org.commoncrawl.mapred.pipelineV3.domainmeta.crawlstats.RankAndCrawlStatsJoinStep.java
@Override public void runStep(Path outputPathLocation) throws IOException { Path phase1Output = JobBuilder.tempDir(getConf(), OUTPUT_DIR_NAME + "-Phase1"); // ok output crawl stats by root domain JobConf job = new JobBuilder(getDescription() + "-Phase1", getConf()) .input(getOutputDirForStep(DNSAndCrawlStatsJoinStep.class)).inputIsSeqFile() .mapper(Phase1Mapper.class).keyValue(TextBytes.class, TextBytes.class).output(phase1Output) .outputIsSeqFile().numReducers(CrawlEnvironment.NUM_DB_SHARDS / 2).build(); JobClient.runJob(job);//from w ww. j a v a2s .c o m ImmutableMap<Path, String> step2InputMapping = new ImmutableMap.Builder<Path, String>() .put(phase1Output, TAG_CRAWLSTATS) .put(getOutputDirForStep(JoinQuantcastAndDomainRankStep.class), TAG_RANKDATA).build(); job = new JobBuilder(getDescription() + " - step 2", getConf()).inputIsSeqFile() .inputs(ImmutableList.copyOf(step2InputMapping.keySet())) .mapperKeyValue(TextBytes.class, JoinValue.class).outputKeyValue(TextBytes.class, TextBytes.class) .mapper(JoinByTextSortByTagMapper.class).reducer(Phase2Reducer.class, false) .partition(JoinByTextSortByTagMapper.Partitioner.class) .numReducers(CrawlEnvironment.NUM_DB_SHARDS / 2).outputIsSeqFile().output(outputPathLocation) .build(); JoinMapper.setPathToTagMapping(step2InputMapping, job); JobClient.runJob(job); }
From source file:io.fabric8.elasticsearch.plugin.KibanaUserReindexAction.java
@Override public void apply(String action, ActionResponse response, @SuppressWarnings("rawtypes") ActionListener listener, ActionFilterChain chain) {/*from www . j av a 2s . c o m*/ if (enabled) { logger.debug("Response with Action '{}' and class '{}'", action, response.getClass()); if (containsKibanaUserIndex(response)) { if (response instanceof IndexResponse) { final IndexResponse ir = (IndexResponse) response; String index = getIndex(ir); ShardInfo shardInfo = ir.getShardInfo(); response = new IndexResponse(index, ir.getType(), ir.getId(), ir.getVersion(), ir.isCreated()); ((IndexResponse) response).setShardInfo(shardInfo); } else if (response instanceof GetResponse) { response = new GetResponse(buildNewResult((GetResponse) response)); } else if (response instanceof DeleteResponse) { final DeleteResponse dr = (DeleteResponse) response; String index = getIndex(dr); ShardInfo shardInfo = dr.getShardInfo(); response = new DeleteResponse(index, dr.getType(), dr.getId(), dr.getVersion(), dr.isFound()); ((DeleteResponse) response).setShardInfo(shardInfo); } else if (response instanceof MultiGetResponse) { final MultiGetResponse mgr = (MultiGetResponse) response; MultiGetItemResponse[] responses = new MultiGetItemResponse[mgr.getResponses().length]; int index = 0; for (MultiGetItemResponse item : mgr.getResponses()) { GetResponse itemResponse = item.getResponse(); Failure itemFailure = item.getFailure(); GetResponse getResponse = (itemResponse != null) ? new GetResponse(buildNewResult(itemResponse)) : null; Failure failure = (itemFailure != null) ? buildNewFailure(itemFailure) : null; responses[index] = new MultiGetItemResponse(getResponse, failure); index++; } response = new MultiGetResponse(responses); } else if (response instanceof GetFieldMappingsResponse) { final GetFieldMappingsResponse gfmResponse = (GetFieldMappingsResponse) response; ImmutableMap<String, ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>>> mappings = gfmResponse .mappings(); String index = ""; for (String key : mappings.keySet()) { index = key; if (isKibanaUserIndex(index)) { index = kibanaIndex; } } BytesStreamOutput bso = new BytesStreamOutput(); try { MappingResponseRemapper remapper = new MappingResponseRemapper(); remapper.updateMappingResponse(bso, index, mappings); ByteBuffer buffer = ByteBuffer.wrap(bso.bytes().toBytes()); ByteBufferStreamInput input = new ByteBufferStreamInput(buffer); response.readFrom(input); } catch (IOException e) { logger.error("Error while rewriting GetFieldMappingsResponse", e); } } } } chain.proceed(action, response, listener); }
From source file:org.apache.bigtop.datagenerators.locations.LocationReader.java
public ImmutableList<Location> readData() throws FileNotFoundException { ImmutableMap<String, Double> incomes = readIncomeData(getResource(LocationConstants.INCOMES_FILE)); ImmutableMap<String, Long> populations = readPopulationData(getResource(LocationConstants.POPULATION_FILE)); ImmutableMap<String, ZipcodeLocationRecord> coordinates = readCoordinates( getResource(LocationConstants.COORDINATES_FILE)); Set<String> zipcodeSubset = new HashSet<String>(incomes.keySet()); zipcodeSubset.retainAll(populations.keySet()); zipcodeSubset.retainAll(coordinates.keySet()); List<Location> table = new Vector<Location>(); for (String zipcode : zipcodeSubset) { Location record = new Location(zipcode, coordinates.get(zipcode).coordinates, coordinates.get(zipcode).city, coordinates.get(zipcode).state, incomes.get(zipcode), populations.get(zipcode)); table.add(record);/*from w ww.jav a 2 s .c o m*/ } return ImmutableList.copyOf(table); }
From source file:org.apache.flume.plugins.KafkaSink.java
@Override public void configure(Context context) { this.context = context; ImmutableMap<String, String> props = context.getParameters(); // base: producer.sinks.r //??Flume-Agentflume-conf.properties??: //bin/flume-ng agent --conf conf --conf-file conf/flume-conf.properties --name producer //--name, ??producerproducer.sinks.r parameters = new Properties(); for (String key : props.keySet()) { String value = props.get(key); this.parameters.put(key, value); }//from w w w . j av a 2 s . c o m }