List of usage examples for java.util.function Function identity
static <T> Function<T, T> identity()
From source file:de.whs.poodle.repositories.StatisticsRepository.java
public Map<Integer, Statistic> getExerciseToStatisticMapForWorksheet(int studentId, int worksheetId) { @SuppressWarnings("unchecked") List<Statistic> statistics = em .createNativeQuery("SELECT s.* FROM worksheet ws " + "JOIN chapter c ON c.worksheet_id = ws.id " + "JOIN chapter_to_exercise ce ON ce.chapter_id = c.id " + "JOIN exercise e ON ce.exercise_id = e.id " + "JOIN v_statistic s ON s.exercise_root_id = e.root_id " + "WHERE ws.id = :worksheetId AND s.student_id = :studentId", Statistic.class) .setParameter("worksheetId", worksheetId).setParameter("studentId", studentId).getResultList(); return statistics.stream().collect(Collectors.toMap(Statistic::getExerciseRootId, Function.identity())); }
From source file:org.openlmis.fulfillment.web.util.BasicOrderDtoBuilder.java
private Map<UUID, UserDto> getUsers(List<Order> orders) { Set<UUID> userIds = orders.stream().map(Order::getCreatedById).collect(Collectors.toSet()); return userReferenceDataService.findByIds(userIds).stream() .collect(Collectors.toMap(BaseDto::getId, Function.identity())); }
From source file:org.jamocha.languages.common.RuleConditionProcessor.java
public static CopyWithMetaInformation copyDeeplyUsingNewECsAndFactVariables( final ConditionalElement<ECLeaf> child, final Collection<EquivalenceClass> equivalenceClasses) { final HashBiMap<EquivalenceClass, EquivalenceClass> oldToNewEC = HashBiMap.create(equivalenceClasses .stream().collect(toMap(java.util.function.Function.identity(), EquivalenceClass::new))); for (final Map.Entry<EquivalenceClass, EquivalenceClass> entry : oldToNewEC.entrySet()) { final EquivalenceClass oldEC = entry.getKey(); final EquivalenceClass newEC = entry.getValue(); oldEC.getEqualParentEquivalenceClasses().stream().map(oldToNewEC::get) .forEach(newEC::addEqualParentEquivalenceClass); }//ww w. j ava 2 s. com // collect all fact variables contained in this child final List<SingleFactVariable> deepFactVariables = DeepFactVariableCollector.collect(child); // copy all fact variables contained in this child while making them point at the // newly created equivalence classes final HashBiMap<SingleFactVariable, SingleFactVariable> oldToNewFV = HashBiMap .create(deepFactVariables.stream().collect(toMap(Function.identity(), (final SingleFactVariable fv) -> new SingleFactVariable(fv, oldToNewEC)))); // replace the old FVs in the new ECs by the new FVs for (final Iterator<EquivalenceClass> ecIter = oldToNewEC.values().iterator(); ecIter.hasNext();) { final EquivalenceClass newEC = ecIter.next(); newEC.getFactVariables().removeIf(negate(deepFactVariables::contains)); newEC.getSlotVariables().removeIf(sv -> !deepFactVariables.contains(sv.getFactVariable())); if (newEC.getElementCount() == 0) { ecIter.remove(); continue; } newEC.getFactVariables().replaceAll(oldToNewFV::get); newEC.getSlotVariables() .replaceAll(sv -> oldToNewFV.get(sv.getFactVariable()).getSlots().get(sv.getSlot())); } final ConditionalElement<ECLeaf> copy = child.accept(new CEECReplacer(oldToNewEC, oldToNewFV)).getResult(); // remove all equivalence classes not occurring in the filters and only consisting of a single constant xor a // single functional expression final Set<EquivalenceClass> usedECs = copy.accept(new DeepECCollector()).getEquivalenceClasses(); oldToNewEC.values().removeIf(ec -> !usedECs.contains(ec) && ec.getElementCount() == 1 && !(ec.getConstantExpressions().isEmpty() && ec.getFunctionalExpressions().isEmpty())); return new CopyWithMetaInformation(copy, oldToNewEC, oldToNewFV); }
From source file:io.syndesis.dao.DeploymentDescriptorTest.java
@Test public void thereShouldBeNoDuplicateMavenCoordinates() { final Map<String, Long> coordinatesWithCount = StreamSupport.stream(deployment.spliterator(), true) .filter(data -> "connector".equals(data.get("kind").asText())) .flatMap(/*from www . j a va 2 s .c o m*/ connector -> StreamSupport.stream(connector.get("data").get("actions").spliterator(), true)) .map(action -> action.get("camelConnectorGAV").asText()) .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); final Map<String, Long> multipleCoordinates = coordinatesWithCount.entrySet().stream() .filter(e -> e.getValue() > 1).collect(Collectors.toMap(Entry::getKey, Entry::getValue)); assertThat(multipleCoordinates).as("Expected connector GAV coordinates to be unique").isEmpty(); }
From source file:com.haulmont.cuba.core.sys.dbupdate.ScriptScanner.java
protected Map<String, ScriptResource> findResourcesByUrlPattern(ResourcePatternResolver resourceResolver, String urlPattern) throws IOException { try {//from w w w . ja va 2 s .c o m return Arrays.stream(resourceResolver.getResources(urlPattern)).map(ScriptResource::new) .collect(Collectors.toMap(ScriptResource::getName, Function.identity())); } catch (FileNotFoundException e) { //just return empty map return Collections.emptyMap(); } }
From source file:org.apache.samza.sql.runner.SamzaSqlApplicationConfig.java
public SamzaSqlApplicationConfig(Config staticConfig, List<String> inputSystemStreams, List<String> outputSystemStreams) { ioResolver = createIOResolver(staticConfig); this.outputSystemStreams = new LinkedList<>(outputSystemStreams); // There could be duplicate streams across different queries. Let's dedupe them. Set<String> inputSystemStreamSet = new HashSet<>(inputSystemStreams); Set<String> outputSystemStreamSet = new HashSet<>(outputSystemStreams); // Let's get the output system stream configs before input system stream configs. This is to account for // table descriptor that could be both input and output. Please note that there could be only one // instance of table descriptor and writable table is a readable table but vice versa is not true. outputSystemStreamConfigsBySource = outputSystemStreamSet.stream() .collect(Collectors.toMap(Function.identity(), x -> ioResolver.fetchSinkInfo(x))); inputSystemStreamConfigBySource = inputSystemStreamSet.stream() .collect(Collectors.toMap(Function.identity(), src -> ioResolver.fetchSourceInfo(src))); Map<String, SqlIOConfig> systemStreamConfigsBySource = new HashMap<>(inputSystemStreamConfigBySource); systemStreamConfigsBySource.putAll(outputSystemStreamConfigsBySource); Set<SqlIOConfig> systemStreamConfigs = new HashSet<>(systemStreamConfigsBySource.values()); relSchemaProvidersBySource = systemStreamConfigs.stream() .collect(Collectors.toMap(SqlIOConfig::getSource, x -> initializePlugin("RelSchemaProvider", x.getRelSchemaProviderName(), staticConfig, CFG_FMT_REL_SCHEMA_PROVIDER_DOMAIN, (o, c) -> ((RelSchemaProviderFactory) o).create(x.getSystemStream(), c)))); samzaRelConvertersBySource = systemStreamConfigs.stream().collect(Collectors.toMap(SqlIOConfig::getSource, x -> initializePlugin("SamzaRelConverter", x.getSamzaRelConverterName(), staticConfig, CFG_FMT_SAMZA_REL_CONVERTER_DOMAIN, (o, c) -> ((SamzaRelConverterFactory) o) .create(x.getSystemStream(), relSchemaProvidersBySource.get(x.getSource()), c)))); samzaRelTableKeyConvertersBySource = systemStreamConfigs.stream().filter(SqlIOConfig::isRemoteTable) .collect(Collectors.toMap(SqlIOConfig::getSource, x -> initializePlugin("SamzaRelTableKeyConverter", x.getSamzaRelTableKeyConverterName(), staticConfig, CFG_FMT_SAMZA_REL_TABLE_KEY_CONVERTER_DOMAIN, (o, c) -> ((SamzaRelTableKeyConverterFactory) o).create(x.getSystemStream(), c)))); udfResolver = createUdfResolver(staticConfig); udfMetadata = udfResolver.getUdfs(); metadataTopicPrefix = staticConfig.get(CFG_METADATA_TOPIC_PREFIX, DEFAULT_METADATA_TOPIC_PREFIX); processSystemEvents = staticConfig.getBoolean(CFG_SQL_PROCESS_SYSTEM_EVENTS, true); windowDurationMs = staticConfig.getLong(CFG_GROUPBY_WINDOW_DURATION_MS, DEFAULT_GROUPBY_WINDOW_DURATION_MS); }
From source file:com.thinkbiganalytics.feedmgr.sla.DefaultServiceLevelAgreementService.java
@Override public List<com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement> getServiceLevelAgreements() { accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_SERVICE_LEVEL_AGREEMENTS); //find all as a Service account List<com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement> agreementsList = this.metadataAccess .read(() -> {//from www.j av a 2 s . c o m List<com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement> agreements = feedSlaProvider .findAllAgreements(); if (agreements != null) { return serviceLevelAgreementTransform.transformFeedServiceLevelAgreements(agreements); } return new ArrayList<>(0); }, MetadataAccess.SERVICE); if (accessController.isEntityAccessControlled()) { Map<String, com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement> serviceLevelAgreementMap = agreementsList .stream() .collect(Collectors.toMap( com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement::getId, Function.identity())); //filter out those feeds user doesnt have access to List<com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement> entityAccessControlledSlas = this.metadataAccess .read(() -> { List<com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement> agreements = feedSlaProvider .findAllAgreements(); if (agreements != null) { List<com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement> serviceLevelAgreements = serviceLevelAgreementTransform .transformFeedServiceLevelAgreements(agreements); return serviceLevelAgreements.stream() .filter(agreement -> serviceLevelAgreementMap.get(agreement.getId()) .getFeedsCount() == agreement.getFeedsCount()) .collect(Collectors.toList()); } return new ArrayList<>(0); }); return entityAccessControlledSlas; } else { return agreementsList; } }
From source file:alfio.repository.TicketFieldRepository.java
default Map<String, TicketFieldValue> findAllByTicketIdGroupedByName(int id) { return findAllByTicketId(id).stream() .collect(Collectors.toMap(TicketFieldValue::getName, Function.identity())); }
From source file:org.apache.samza.tools.benchmark.AbstractSamzaBench.java
Config convertToSamzaConfig(Properties props) { Map<String, String> propsValue = props.stringPropertyNames().stream() .collect(Collectors.toMap(Function.identity(), props::getProperty)); return new MapConfig(propsValue); }
From source file:org.kitodo.production.forms.dataeditor.FieldedMetadataTableRow.java
/** * The method for building the meta-data table. *//* w ww . j a v a 2s .c om*/ private void createMetadataTable() { // the existing meta-data is passed to the rule set, which sorts it Map<Metadata, String> metadataWithKeys = addLabels(metadata).parallelStream() .collect(Collectors.toMap(Function.identity(), Metadata::getKey)); List<MetadataViewWithValuesInterface<Metadata>> tableData = metadataView .getSortedVisibleMetadata(metadataWithKeys, additionallySelectedFields); rows.clear(); hiddenMetadata = Collections.emptyList(); for (MetadataViewWithValuesInterface<Metadata> rowData : tableData) { Optional<MetadataViewInterface> optionalMetadataView = rowData.getMetadata(); Collection<Metadata> values = rowData.getValues(); if (optionalMetadataView.isPresent()) { MetadataViewInterface metadataView = optionalMetadataView.get(); if (metadataView.isComplex()) { rows.add(createMetadataGroupPanel((ComplexMetadataViewInterface) metadataView, values)); } else { rows.add(createMetadataEntryEdit((SimpleMetadataViewInterface) metadataView, values)); } } else { hiddenMetadata = values; } } }