List of usage examples for com.google.common.collect Maps toMap
public static <K, V> ImmutableMap<K, V> toMap(Iterator<K> keys, Function<? super K, V> valueFunction)
From source file:dagger.internal.codegen.SimpleAnnotationMirror.java
private SimpleAnnotationMirror(TypeElement annotationType, Map<String, ? extends AnnotationValue> namedValues) { checkArgument(annotationType.getKind().equals(ElementKind.ANNOTATION_TYPE), "annotationType must be an annotation: %s", annotationType); checkArgument(FluentIterable.from(methodsIn(annotationType.getEnclosedElements())) .transform(element -> element.getSimpleName().toString()).toSet().equals(namedValues.keySet()), "namedValues must have values for exactly the members in %s: %s", annotationType, namedValues); this.annotationType = annotationType; this.namedValues = ImmutableMap.copyOf(namedValues); this.elementValues = Maps.toMap(methodsIn(annotationType.getEnclosedElements()), Functions.compose(Functions.forMap(namedValues), element -> element.getSimpleName().toString())); }
From source file:ninja.leaping.permissionsex.util.PEXProfileCache.java
@Override public ImmutableMap<UUID, Profile> getAllPresent(Iterable<UUID> iterable) { return Maps.toMap(iterable, this::getIfPresent); }
From source file:org.obm.push.utils.ShareAmount.java
public Map<T, Integer> amount(final int amount) { return Maps.newHashMap(Maps.toMap(entries, new Function<T, Integer>() { int amountLeft = amount; int entriesLeft = entries.size(); @Override/* w ww. j av a2 s . com*/ public Integer apply(T entry) { try { int ceiledAverage = ceiledAverage(amountLeft, entriesLeft); if (amountLeft >= ceiledAverage) { amountLeft -= ceiledAverage; return ceiledAverage; } else { int returnValue = amountLeft; amountLeft = 0; return returnValue; } } finally { entriesLeft--; } } })); }
From source file:eu.numberfour.n4js.ui.workingsets.DefaultWorkingSetImpl.java
@Override public IAdaptable[] getElements() { final IProject[] projects = getAllProjects(); if (OTHERS_WORKING_SET_ID.equals(getId())) { // No other working sets are available at all. final WorkingSet[] allWorkingSets = getWorkingSetManager().getAllWorkingSets(); if (allWorkingSets.length == 1) { return projects; } else {//from ww w . ja v a2 s . c om // We have to exclude all those projects that are associatedwith at least one other working set. final FluentIterable<WorkingSet> others = from(asList(allWorkingSets)) .filter(ws -> !OTHERS_WORKING_SET_ID.equals(ws.getId())); // Mapping between non-built-in working sets and their elements. final Map<WorkingSet, Collection<IAdaptable>> elementMapping = Maps.toMap(others, ws -> newHashSet(ws.getElements())); final IProject[] elements = new IProject[projects.length]; int elementCount = 0; for (int i = 0, size = projects.length; i < size; i++) { final IProject project = projects[i]; // If the project is not assigned to any other working set, then assign it to the built-in one. if (!Iterables.any(others, ws -> elementMapping.get(ws).contains(project))) { elements[elementCount++] = project; } } return Arrays.copyOfRange(elements, 0, elementCount); } } else { final IProject[] elements = new IProject[projects.length]; int elementCount = 0; for (int i = 0, size = projects.length; i < size; i++) { final IProject project = projects[i]; if (apply(project)) { elements[elementCount++] = project; } } return Arrays.copyOfRange(elements, 0, elementCount); } }
From source file:com.facebook.presto.sql.planner.assertions.TopNMatcher.java
@Override public MatchResult detailMatches(PlanNode node, PlanNodeCost planNodeCost, Session session, Metadata metadata, SymbolAliases symbolAliases) {/*from w w w . j a v a2s . co m*/ checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName()); TopNNode topNNode = (TopNNode) node; if (topNNode.getCount() != count) { return NO_MATCH; } List<Symbol> expectedOrderBy = orderBySymbols.stream().map(alias -> alias.toSymbol(symbolAliases)) .collect(toImmutableList()); if (!topNNode.getOrderBy().equals(expectedOrderBy)) { return NO_MATCH; } Map<Symbol, SortOrder> expectedOrderings = Maps.toMap(expectedOrderBy, Functions.constant(SortOrder.ASC_NULLS_FIRST)); if (!topNNode.getOrderings().equals(expectedOrderings)) { return NO_MATCH; } return match(); }
From source file:com.facebook.buck.util.randomizedtrial.RandomizedTrial.java
private static <T extends Enum<T> & WithProbability> T selectGroup(String name, Class<T> enumClass, double point) { return selectGroup(name, Maps.toMap(EnumSet.allOf(enumClass), x -> x.getProbability()), point); }
From source file:dagger.internal.codegen.MapBindingExpression.java
MapBindingExpression(ResolvedBindings resolvedBindings, ComponentImplementation componentImplementation, BindingGraph graph, ComponentBindingExpressions componentBindingExpressions, DaggerTypes types, DaggerElements elements) {// w w w . j a va 2s . c o m super(resolvedBindings, componentImplementation); this.binding = (ProvisionBinding) resolvedBindings.contributionBinding(); BindingKind bindingKind = this.binding.kind(); checkArgument(bindingKind.equals(MULTIBOUND_MAP), bindingKind); this.componentBindingExpressions = componentBindingExpressions; this.types = types; this.elements = elements; this.dependencies = Maps.toMap(binding.dependencies(), dep -> graph.contributionBindings().get(dep.key()).contributionBinding()); }
From source file:org.geoserver.security.iride.entity.IrideInfoPersona.java
/** * Constructor./* w w w .ja va 2s .com*/ * * @param role * @param properties */ public IrideInfoPersona(IrideRole role, final Properties properties) { this(role, Maps.toMap(properties.stringPropertyNames(), new Function<String, Object>() { /* * (non-Javadoc) * @see com.google.common.base.Function#apply(java.lang.Object) */ @Override public Object apply(String key) { return properties.getProperty(key); } })); }
From source file:fi.hsl.parkandride.core.service.FacilityHistoryService.java
/** * Deduces the unavailable capacities history for the given date range. * If the unavailable capacities change during the day, the capacity that was * mostly active during the the period of 6 to 10 am. is selected. *///from ww w .j a v a 2s . c o m @TransactionalRead public Map<LocalDate, FacilityCapacity> getCapacityHistory(final long facilityId, final LocalDate start, final LocalDate end) { final List<FacilityCapacityHistory> capacityHistory = facilityHistoryRepository .getCapacityHistory(facilityId, start, end); // Fall back to current unavailable capacities final Facility facility = facilityRepository.getFacility(facilityId); final FacilityCapacityHistory identity = new FacilityCapacityHistory(null, null, null, Optional.ofNullable(facility.builtCapacity).orElse(emptyMap()), Optional.ofNullable(facility.unavailableCapacities).orElse(emptyList())); return Maps.toMap(dateRangeClosed(start, end), date -> new FacilityCapacity(findEntryForDate(capacityHistory, date, identity))); }
From source file:com.dangdang.ddframe.rdb.sharding.merger.groupby.GroupByStreamResultSetMerger.java
private boolean aggregateCurrentGroupByRowAndNext() throws SQLException { boolean result = false; Map<AggregationSelectItem, AggregationUnit> aggregationUnitMap = Maps.toMap( selectStatement.getAggregationSelectItems(), new Function<AggregationSelectItem, AggregationUnit>() { @Override//w w w . ja v a2 s . c o m public AggregationUnit apply(final AggregationSelectItem input) { return AggregationUnitFactory.create(input.getType()); } }); while (currentGroupByValues.equals( new GroupByValue(getCurrentResultSet(), selectStatement.getGroupByItems()).getGroupValues())) { aggregate(aggregationUnitMap); cacheCurrentRow(); result = super.next(); if (!result) { break; } } setAggregationValueToCurrentRow(aggregationUnitMap); return result; }