public IdentityProviderRepository(List<IdentityProvider> identityProviders) { this.providersByKey.putAll(FluentIterable.from(identityProviders).uniqueIndex(ToKey.INSTANCE)); }
public ReportMetricValidatorImpl(ScannerMetrics scannerMetrics) { this.metricByKey = FluentIterable.from(scannerMetrics.getMetrics()).uniqueIndex(MetricToKey.INSTANCE); }
private Map<String, ComponentDto> searchReferenceComponentsById(DbSession dbSession, List<ComponentDto> components) { List<String> referenceComponentUUids = components.stream() .map(ComponentDto::getCopyResourceUuid) .filter(Objects::nonNull) .collect(MoreCollectors.toList(components.size())); if (referenceComponentUUids.isEmpty()) { return emptyMap(); } return FluentIterable.from(dbClient.componentDao().selectByUuids(dbSession, referenceComponentUUids)) .uniqueIndex(ComponentDto::uuid); }
@Override public void start() { DbSession dbSession = dbClient.openSession(false); try { List<MetricDto> metricList = dbClient.metricDao().selectEnabled(dbSession); this.metricsByKey = from(metricList).transform(MetricDtoToMetric.INSTANCE).uniqueIndex(MetricToKey.INSTANCE); this.metricsById = from(metricList).transform(MetricDtoToMetric.INSTANCE).uniqueIndex(MetricToId.INSTANCE); } finally { dbSession.close(); } }
public void testUniqueIndex() { ImmutableMap<Integer, String> expected = ImmutableMap.of(3, "two", 5, "three", 4, "four"); ImmutableMap<Integer, String> index = FluentIterable.from(asList("two", "three", "four")) .uniqueIndex( new Function<String, Integer>() { @Override public Integer apply(String input) { return input.length(); } }); assertEquals(expected, index); }
private static Map<String, RuleParamDto> paramsByKey(List<RuleParamDto> params) { return FluentIterable.from(params).uniqueIndex(RuleParamToKey.INSTANCE); }
public void testUniqueIndex_duplicateKey() { try { ImmutableMap<Integer, String> unused = FluentIterable.from(asList("one", "two", "three", "four")) .uniqueIndex( new Function<String, Integer>() { @Override public Integer apply(String input) { return input.length(); } }); fail(); } catch (IllegalArgumentException expected) { } }
private static Map<Condition, ConditionStatus> createStatusPerCondition(Iterable<Condition> conditions, Iterable<EvaluatedCondition> evaluatedConditions) { Map<Condition, EvaluatedCondition> evaluatedConditionPerCondition = from(evaluatedConditions) .uniqueIndex(EvaluatedConditionToCondition.INSTANCE); ImmutableMap.Builder<Condition, ConditionStatus> builder = ImmutableMap.builder(); for (Condition condition : conditions) { EvaluatedCondition evaluatedCondition = evaluatedConditionPerCondition.get(condition); if (evaluatedCondition == null) { builder.put(condition, NO_VALUE_STATUS); } else { builder.put(condition, create(toEvaluationStatus(evaluatedCondition.getLevel()), evaluatedCondition.getActualValue())); } } return builder.build(); }
public void testUniqueIndex_nullValue() { try { ImmutableMap<Object, Integer> unused = fluent(1, null, 2) .uniqueIndex( new Function<Integer, Object>() { @Override public Object apply(@Nullable Integer input) { return String.valueOf(input); } }); fail(); } catch (NullPointerException expected) { } }
private Multimap<ActiveRuleDto, ActiveRuleParamDto> getActiveRuleParamsByActiveRule(DbSession dbSession, OrganizationDto organization, RuleDto customRule) { List<OrgActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRuleId(dbSession, organization, customRule.getId()); Map<Integer, OrgActiveRuleDto> activeRuleById = from(activeRuleDtos).uniqueIndex(ActiveRuleDto::getId); List<Integer> activeRuleIds = Lists.transform(activeRuleDtos, ActiveRuleDto::getId); List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds); return from(activeRuleParamDtos) .index(new ActiveRuleParamToActiveRule(activeRuleById)); }
@Override public void accept(@Nonnull ActiveRuleDto activeRuleDto) { Map<String, ActiveRuleParamDto> activeRuleParamByKey = from(activeRuleParams.get(activeRuleDto)) .uniqueIndex(ActiveRuleParamDto::getKey); ActiveRuleParamDto activeRuleParamDto = activeRuleParamByKey.get(ruleParamDto.getName()); if (activeRuleParamDto != null) { dbClient.activeRuleDao().updateParam(dbSession, activeRuleParamDto.setValue(ruleParamDto.getDefaultValue())); } else { dbClient.activeRuleDao().insertParam(dbSession, activeRuleDto, ActiveRuleParamDto.createFor(ruleParamDto).setValue(ruleParamDto.getDefaultValue())); } } }
public void testUniqueIndex_nullKey() { try { fluent(1, 2, 3).uniqueIndex(Functions.constant(null)); fail(); } catch (NullPointerException expected) { } }
private Map<CDOID, CDORevisionDelta> getRevisionDeltas(final CDORevisionDelta[] revisionDeltas) { return FluentIterable .from(ImmutableList.copyOf(revisionDeltas)) .uniqueIndex(new Function<CDORevisionDelta, CDOID>() { @Override public CDOID apply(final CDORevisionDelta input) { return input.getID(); } }); }
@Override public void start() { DbSession dbSession = dbClient.openSession(false); try { List<MetricDto> metricList = dbClient.metricDao().selectEnabled(dbSession); this.metricsByKey = from(metricList).transform(MetricDtoToMetric.INSTANCE).uniqueIndex(MetricToKey.INSTANCE); this.metricsById = from(metricList).transform(MetricDtoToMetric.INSTANCE).uniqueIndex(MetricToId.INSTANCE); } finally { dbSession.close(); } }
private List<CeTask> loadTasks(DbSession dbSession, List<CeQueueDto> dtos) { Set<String> componentUuids = dtos.stream() .map(CeQueueDto::getComponentUuid) .filter(Objects::nonNull) .collect(Collectors.toSet()); Map<String, ComponentDto> componentDtoByUuid = from(dbClient.componentDao() .selectByUuids(dbSession, componentUuids)) .uniqueIndex(ComponentDto::uuid); return dtos.stream() .map(new CeQueueDtoToCeTask(defaultOrganizationProvider.get().getUuid(), componentDtoByUuid)::apply) .collect(MoreCollectors.toList(dtos.size())); }
private static Map<String, ReflectionRelationship> computeRelationships(AccelerationDetails details) { if (details.getReflectionRelationshipsList() == null) { return ImmutableMap.of(); } return FluentIterable.from(details.getReflectionRelationshipsList()) .uniqueIndex(input -> input.getReflection().getId().getId()); }
private static void setPatterns(Suite current, Suite pattern) { if (pattern != null) { final ImmutableMap<String, Test> tests = FluentIterable.from(current.getTests()) .uniqueIndex(TEST_TO_MAP); updateComment(current, pattern); for (Test patternTest : pattern.getTests()) { if (tests.containsKey(patternTest.getName())) { mergeTest(tests.get(patternTest.getName()), patternTest); } } } }
public static SharedDataMap create(List<SharedData> sharedDataList, FragmentHandle fragmentHandle) { Map<Key,SharedData> map = FluentIterable.from(sharedDataList) .filter(s -> s.getMajorFragmentId() == fragmentHandle.getMajorFragmentId()) .uniqueIndex(s -> new Key(s.getOperatorId(), s.getName())); return new SharedDataMap(map); }
@Override public void accept(@Nonnull ActiveRuleDto activeRuleDto) { Map<String, ActiveRuleParamDto> activeRuleParamByKey = from(activeRuleParams.get(activeRuleDto)) .uniqueIndex(ActiveRuleParamDto::getKey); ActiveRuleParamDto activeRuleParamDto = activeRuleParamByKey.get(ruleParamDto.getName()); if (activeRuleParamDto != null) { dbClient.activeRuleDao().updateParam(dbSession, activeRuleParamDto.setValue(ruleParamDto.getDefaultValue())); } else { dbClient.activeRuleDao().insertParam(dbSession, activeRuleDto, ActiveRuleParamDto.createFor(ruleParamDto).setValue(ruleParamDto.getDefaultValue())); } } }
public void testUniqueIndex_nullKey() { try { fluent(1, 2, 3).uniqueIndex(Functions.constant(null)); fail(); } catch (NullPointerException expected) { } }