private StateMachine(Builder builder) { this.keys = ImmutableList.copyOf(builder.states); ImmutableMap.Builder<String, State> mapBuilder = ImmutableMap.builder(); for (String stateKey : builder.states) { List<Transition> outTransitions = builder.outTransitions.get(stateKey); State state = new State(stateKey, outTransitions.toArray(new Transition[outTransitions.size()])); mapBuilder.put(stateKey, state); } byKey = mapBuilder.build(); }
private static Map<RuleDefinitionDto, Rule> buildRulesByRuleDefinitionDto(DbClient dbClient, DbSession dbSession) { List<RuleDefinitionDto> dtos = dbClient.ruleDao().selectAllDefinitions(dbSession); Set<RuleKey> ruleKeys = dtos.stream().map(RuleDefinitionDto::getKey).collect(toSet(dtos.size())); ListMultimap<Integer, RuleParamDto> ruleParamsByRuleId = retrieveRuleParameters(dbClient, dbSession, ruleKeys); Map<RuleDefinitionDto, Rule> rulesByDefinition = new HashMap<>(dtos.size()); for (RuleDefinitionDto definition : dtos) { rulesByDefinition.put(definition, toRule(definition, ruleParamsByRuleId.get(definition.getId()))); } return ImmutableMap.copyOf(rulesByDefinition); }
public Set<String> getPushedPredicates(RelNode operator, int pos) { if (!this.registryPushedPredicates.containsKey(operator)) { for (int i = 0; i < operator.getInputs().size(); i++) { this.registryPushedPredicates.get(operator).add(Sets.<String>newHashSet()); } } return this.registryPushedPredicates.get(operator).get(pos); }
protected void assertGet(K key, Collection<V> values) { assertEqualInOrder(values, multimap().get(key)); if (!values.isEmpty()) { assertEqualInOrder(values, multimap().asMap().get(key)); assertFalse(multimap().isEmpty()); } else { assertNull(multimap().asMap().get(key)); } assertEquals(values.size(), multimap().get(key).size()); assertEquals(values.size() > 0, multimap().containsKey(key)); assertEquals(values.size() > 0, multimap().keySet().contains(key)); assertEquals(values.size() > 0, multimap().keys().contains(key)); } }
@Override public synchronized Optional<CommandMapping> get(String alias, @Nullable CommandSource source) { List<CommandMapping> results = this.commands.get(alias.toLowerCase()); if (results.size() == 1) { return Optional.of(results.get(0)); } else if (results.size() == 0) { return Optional.empty(); } else { return this.disambiguatorFunc.disambiguate(source, alias, results); } }
List<Rules.Active> completeShow(DbSession dbSession, OrganizationDto organization, RuleDefinitionDto rule) { List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByRuleId(dbSession, organization, rule.getId()); Map<Integer, ActiveRuleKey> activeRuleIdsByKey = new HashMap<>(); for (OrgActiveRuleDto activeRuleDto : activeRules) { activeRuleIdsByKey.put(activeRuleDto.getId(), activeRuleDto.getKey()); } List<Integer> activeRuleIds = activeRules.stream().map(ActiveRuleDto::getId).collect(Collectors.toList()); List<ActiveRuleParamDto> activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, activeRuleIds); ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = ArrayListMultimap.create(activeRules.size(), 10); for (ActiveRuleParamDto activeRuleParamDto : activeRuleParams) { ActiveRuleKey activeRuleKey = activeRuleIdsByKey.get(activeRuleParamDto.getActiveRuleId()); activeRuleParamsByActiveRuleKey.put(activeRuleKey, activeRuleParamDto); } return activeRules.stream() .map(activeRule -> buildActiveRuleResponse(activeRule, activeRuleParamsByActiveRuleKey.get(activeRule.getKey()))) .collect(Collectors.toList()); }
private void createTask(TaskSpecification specification) { if (specification.getType() == LEAF) { runningTasks.put(specification, new LeafTask( taskExecutor, specification, new TaskId(specification.getName(), 0, runningTasks.get(specification).size() + completedTasks.get(specification).size()))); } else { runningTasks.put(specification, new IntermediateTask( taskExecutor, specification, new TaskId(specification.getName(), 0, runningTasks.get(specification).size() + completedTasks.get(specification).size()))); } }
@Override public Map<String, String> getParams() { return parameters.keyValues.keySet().stream() .collect(Collectors.toMap( Function.identity(), key -> parameters.keyValues.get(key).get(0), (v1, v2) -> { throw new IllegalStateException(String.format("Duplicate key '%s' in request", v1)); }, LinkedHashMap::new)); }
Set<String> favoriteUuids = favoriteDtos.stream().map(ComponentDto::uuid).collect(MoreCollectors.toSet(favoriteDtos.size())); Comparator<ComponentDto> favoriteComparator = Comparator.comparing(c -> favoriteUuids.contains(c.uuid()) ? -1 : +1); Comparator<ComponentDto> comparator = favoriteComparator.thenComparing(ComponentDto::name); List<ComponentDto> componentsOfThisQualifier = componentsPerQualifier.get(q); List<ComponentHit> hits = componentsOfThisQualifier .stream() .map(ComponentHit::new) .collect(MoreCollectors.toList(limit)); int totalHits = componentsOfThisQualifier.size(); return new ComponentHitsPerQualifier(q, hits, totalHits); })).build();
private void extractObjectAndFields(final List<Identifier> listIdentifiers, final String method, final String definingType) { final List<String> strings = listIdentifiers.stream().map(id -> id.getValue()).collect(Collectors.toList()); int flsIndex = Collections.lastIndexOfSubList(strings, Arrays.asList(RESERVED_KEYS_FLS)); if (flsIndex != -1) { String objectTypeName = strings.get(flsIndex + RESERVED_KEYS_FLS.length); if (!typeToDMLOperationMapping.get(definingType + ":" + objectTypeName).contains(method)) { typeToDMLOperationMapping.put(definingType + ":" + objectTypeName, method); } } }
private String describeMissingWithPairing( Pairing pairing, Correspondence.ExceptionStore exceptions) { List<String> messages = newArrayList(); for (Object key : pairing.pairedKeysToExpectedValues.keySet()) { E missing = pairing.pairedKeysToExpectedValues.get(key); List<A> extras = pairing.pairedKeysToActualValues.get(key); messages.add( lenientFormat( "is missing an element that corresponds to <%s> (but did have elements <%s> with " + "matching key %s)", missing, formatExtras(missing, extras, exceptions), key)); } if (!pairing.unpairedExpectedValues.isEmpty()) { messages.add( describeMissingWithoutPairing("corresponds to", pairing.unpairedExpectedValues) + " (without matching keys)"); } if (messages.size() > 1) { messages.set(messages.size() - 1, "and " + messages.get(messages.size() - 1)); } return Joiner.on(", ").join(messages); }