Java Code Examples for com.google.common.collect.Maps#toMap()
The following examples show how to use
com.google.common.collect.Maps#toMap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupByMemoryResultSetMerger.java From sharding-jdbc-1.5.1 with Apache License 2.0 | 6 votes |
private void initForFirstGroupByValue(final ResultSet resultSet, final GroupByValue groupByValue, final Map<GroupByValue, MemoryResultSetRow> dataMap, final Map<GroupByValue, Map<AggregationSelectItem, AggregationUnit>> aggregationMap) throws SQLException { if (!dataMap.containsKey(groupByValue)) { dataMap.put(groupByValue, new MemoryResultSetRow(resultSet)); } if (!aggregationMap.containsKey(groupByValue)) { Map<AggregationSelectItem, AggregationUnit> map = Maps.toMap(selectStatement.getAggregationSelectItems(), new Function<AggregationSelectItem, AggregationUnit>() { @Override public AggregationUnit apply(final AggregationSelectItem input) { return AggregationUnitFactory.create(input.getType()); } }); aggregationMap.put(groupByValue, map); } }
Example 2
Source File: GuavaFunctionalExamplesUnitTest.java From tutorials with MIT License | 6 votes |
/** * - see: http://code.google.com/p/guava-libraries/issues/detail?id=56 */ @Test public final void whenMapIsBackedBySetAndFunction_thenCorrect() { final Function<Integer, Integer> powerOfTwo = new Function<Integer, Integer>() { @Override public final Integer apply(final Integer input) { return (int) Math.pow(input, 2); } }; final Set<Integer> lowNumbers = Sets.newHashSet(2, 3, 4); final Map<Integer, Integer> numberToPowerOfTwoMuttable = Maps.asMap(lowNumbers, powerOfTwo); final Map<Integer, Integer> numberToPowerOfTwoImuttable = Maps.toMap(lowNumbers, powerOfTwo); assertThat(numberToPowerOfTwoMuttable.get(2), equalTo(4)); assertThat(numberToPowerOfTwoImuttable.get(2), equalTo(4)); }
Example 3
Source File: ModelRegistry.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public Object get(ModelPath path) { ModelCreator modelCreator = creators.get(path); Map<String, Object> inputs = Maps.toMap(modelCreator.getInputPaths(), new Function<String, Object>() { public Object apply(String inputPath) { return get(ModelPath.path(inputPath)); } }); Object result = modelCreator.create(inputs); Set<ModelPath> promisedPaths = getPromisedPaths(); for (ModelPath modelPath : promisedPaths) { if (path.isDirectChild(modelPath)) { closeChild(result, modelPath); } } return result; }
Example 4
Source File: MemoryGroupByAggregationTest.java From hop with Apache License 2.0 | 6 votes |
@Test @Ignore public void testNullMin() throws Exception { variables.setVariable( Const.HOP_AGGREGATION_MIN_NULL_IS_VALUED, "Y" ); addColumn( new ValueMetaInteger( "intg" ), null, 0L, 1L, -1L ); addColumn( new ValueMetaString( "str" ), "A", null, "B", null ); aggregates = Maps.toMap( ImmutableList.of( "min", "max" ), Functions.forMap( default_aggregates ) ); RowMetaAndData output = runTransform(); assertThat( output.getInteger( "intg_min" ), nullValue() ); assertThat( output.getInteger( "intg_max" ), is( 1L ) ); assertThat( output.getString( "str_min", null ), nullValue() ); assertThat( output.getString( "str_max", "invalid" ), is( "B" ) ); }
Example 5
Source File: MemoryGroupByAggregationTest.java From hop with Apache License 2.0 | 6 votes |
@Test public void testNullMin() throws Exception { variables.setVariable( Const.HOP_AGGREGATION_MIN_NULL_IS_VALUED, "Y" ); addColumn( new ValueMetaInteger( "intg" ), null, 0L, 1L, -1L ); addColumn( new ValueMetaString( "str" ), "A", null, "B", null ); aggregates = Maps.toMap( ImmutableList.of( "min", "max" ), Functions.forMap( default_aggregates ) ); RowMetaAndData output = runTransform(); assertThat( output.getInteger( "intg_min" ), nullValue() ); assertThat( output.getInteger( "intg_max" ), is( 1L ) ); assertThat( output.getString( "str_min", null ), nullValue() ); assertThat( output.getString( "str_max", "invalid" ), is( "B" ) ); }
Example 6
Source File: DatabaseShardManager.java From presto with Apache License 2.0 | 5 votes |
private Map<String, Integer> toNodeIdMap(Collection<ShardInfo> shards) { Set<String> identifiers = shards.stream() .map(ShardInfo::getNodeIdentifiers) .flatMap(Collection::stream) .collect(toSet()); return Maps.toMap(identifiers, this::getOrCreateNodeId); }
Example 7
Source File: PlanBuilder.java From presto with Apache License 2.0 | 5 votes |
public TopNNode topN(long count, List<Symbol> orderBy, TopNNode.Step step, PlanNode source) { return new TopNNode( idAllocator.getNextId(), source, count, new OrderingScheme( orderBy, Maps.toMap(orderBy, Functions.constant(SortOrder.ASC_NULLS_FIRST))), step); }
Example 8
Source File: PlanBuilder.java From presto with Apache License 2.0 | 5 votes |
public SortNode sort(List<Symbol> orderBy, PlanNode source) { return new SortNode( idAllocator.getNextId(), source, new OrderingScheme( orderBy, Maps.toMap(orderBy, Functions.constant(SortOrder.ASC_NULLS_FIRST))), false); }
Example 9
Source File: SingularityDeployKey.java From Singularity with Apache License 2.0 | 5 votes |
public static Map<SingularityPendingTask, SingularityDeployKey> fromPendingTasks( Collection<SingularityPendingTask> pendingTasks ) { return Maps.toMap( pendingTasks, new Function<SingularityPendingTask, SingularityDeployKey>() { @Override public SingularityDeployKey apply(@Nonnull SingularityPendingTask input) { return SingularityDeployKey.fromPendingTask(input); } } ); }
Example 10
Source File: GroupByStreamMergedResult.java From shardingsphere with Apache License 2.0 | 5 votes |
private boolean aggregateCurrentGroupByRowAndNext() throws SQLException { boolean result = false; Map<AggregationProjection, AggregationUnit> aggregationUnitMap = Maps.toMap( selectStatementContext.getProjectionsContext().getAggregationProjections(), input -> AggregationUnitFactory.create(input.getType(), input instanceof AggregationDistinctProjection)); while (currentGroupByValues.equals(new GroupByValue(getCurrentQueryResult(), selectStatementContext.getGroupByContext().getItems()).getGroupValues())) { aggregate(aggregationUnitMap); cacheCurrentRow(); result = super.next(); if (!result) { break; } } setAggregationValueToCurrentRow(aggregationUnitMap); return result; }
Example 11
Source File: AllocationTokenCustomLogic.java From nomulus with Apache License 2.0 | 5 votes |
/** Performs additional custom logic for performing domain checks using a token. */ public ImmutableMap<InternetDomainName, String> checkDomainsWithToken( ImmutableList<InternetDomainName> domainNames, AllocationToken token, String clientId, DateTime now) { // Do nothing. return Maps.toMap(domainNames, k -> ""); }
Example 12
Source File: AllocationTokenFlowUtilsTest.java From nomulus with Apache License 2.0 | 5 votes |
@Override public ImmutableMap<InternetDomainName, String> checkDomainsWithToken( ImmutableList<InternetDomainName> domainNames, AllocationToken tokenEntity, String clientId, DateTime now) { return Maps.toMap(domainNames, domain -> domain.toString().contains("bunny") ? "fufu" : ""); }
Example 13
Source File: ConfigHelper.java From hop with Apache License 2.0 | 4 votes |
public Map<String, String> asMap() { checkState( keys != null && values != null && keys.size() == values.size() ); return Maps.toMap( keys, key -> values.get( keys.indexOf( key ) ) ); }
Example 14
Source File: JCacheGuiceTest.java From caffeine with Apache License 2.0 | 4 votes |
@Override public Map<Integer, Integer> loadAll(Iterable<? extends Integer> keys) { return Maps.toMap(ImmutableSet.copyOf(keys), this::load); }
Example 15
Source File: FakeRuleAnalysisGraph.java From buck with Apache License 2.0 | 4 votes |
@Override public ImmutableMap<RuleAnalysisKey, RuleAnalysisResult> getAll(Set<RuleAnalysisKey> lookupKeys) { return Maps.toMap(lookupKeys, mappingFunc::apply); }
Example 16
Source File: QaServiceImpl.java From exonum-java-binding with Apache License 2.0 | 4 votes |
private <K, V> Map<K, V> toMap(MapIndex<K, V> mapIndex) { return Maps.toMap(mapIndex.keys(), mapIndex::get); }
Example 17
Source File: TestKitTest.java From exonum-java-binding with Apache License 2.0 | 4 votes |
private static <K, V> Map<K, V> toMap(MapIndex<K, V> mapIndex) { return Maps.toMap(mapIndex.keys(), mapIndex::get); }
Example 18
Source File: ProctorController.java From proctor with Apache License 2.0 | 4 votes |
/** * set spring Model attribute for view * * @return view spring name */ private String getArtifactForView(final Model model, final Environment branch, final ProctorView view) { final TestMatrixVersion testMatrix = getCurrentMatrix(branch); final TestMatrixDefinition testMatrixDefinition; if (testMatrix == null || testMatrix.getTestMatrixDefinition() == null) { testMatrixDefinition = new TestMatrixDefinition(); } else { testMatrixDefinition = testMatrix.getTestMatrixDefinition(); } model.addAttribute("branch", branch); model.addAttribute("session", SessionViewModel.builder() .setUseCompiledCSS(getConfiguration().isUseCompiledCSS()) .setUseCompiledJavaScript(getConfiguration().isUseCompiledJavaScript()) // todo get the appropriate js compile / non-compile url .build()); model.addAttribute("testMatrixVersion", testMatrix); final Set<String> testNames = testMatrixDefinition.getTests().keySet(); final Map<String, List<Revision>> allHistories = getAllHistories(branch); final Map<String, Long> updatedTimeMap = Maps.toMap(testNames, testName -> { final Date updatedDate = getUpdatedDate(allHistories, testName); if (updatedDate != null) { return updatedDate.getTime(); } else { return FALLBACK_UPDATED_TIME; } }); model.addAttribute("updatedTimeMap", updatedTimeMap); final String errorMessage = "Apparently not impossible exception generating JSON"; try { final String testMatrixJson = OBJECT_MAPPER.writer(new MinimalPrettyPrinter()).writeValueAsString(testMatrixDefinition); model.addAttribute("testMatrixDefinition", testMatrixJson); final Map<String, Map<String, String>> colors = Maps.newHashMap(); for (final Entry<String, TestDefinition> entry : testMatrixDefinition.getTests().entrySet()) { final Map<String, String> testColors = Maps.newHashMap(); for (final TestBucket bucket : entry.getValue().getBuckets()) { final long hashedBucketName = Hashing.md5().newHasher().putString(bucket.getName(), Charsets.UTF_8).hash().asLong(); final int color = ((int) (hashedBucketName & 0x00FFFFFFL)) | 0x00808080; // convert a hash of the bucket to a color, but keep it light testColors.put(bucket.getName(), Integer.toHexString(color)); } colors.put(entry.getKey(), testColors); } model.addAttribute("colors", colors); return view.getName(); } catch (final IOException e) { LOGGER.error(errorMessage, e); model.addAttribute("exception", toString(e)); } model.addAttribute("error", errorMessage); return ProctorView.ERROR.getName(); }
Example 19
Source File: SingularityDeployKey.java From Singularity with Apache License 2.0 | 4 votes |
public static Map<SingularityPendingDeploy, SingularityDeployKey> fromPendingDeploys( Collection<SingularityPendingDeploy> pendingDeploys ) { return Maps.toMap(pendingDeploys, FROM_PENDING_TO_DEPLOY_KEY); }
Example 20
Source File: SettingComponentBindings.java From intellij with Apache License 2.0 | 4 votes |
static SettingComponentBindings create(List<ConfigurableSetting<?, ?>> settings) { return new SettingComponentBindings(Maps.toMap(settings, Binding::new)); }