List of usage examples for com.google.common.collect Maps uniqueIndex
public static <K, V> ImmutableMap<K, V> uniqueIndex(Iterator<V> values, Function<? super V, K> keyFunction)
From source file:org.basepom.mojo.propertyhelper.beans.PropertyGroup.java
public Map<String, String> getProperties() { return ImmutableMap.copyOf(Maps.transformValues( Maps.uniqueIndex(Arrays.asList(properties), getNameFunction()), getValueFunction())); }
From source file:com.siemens.sw360.datahandler.common.Moderator.java
protected Set<Attachment> updateAttachments(Set<Attachment> attachments, Set<Attachment> attachmentAdditions, Set<Attachment> attachmentDeletions) { if (attachments == null) { attachments = new HashSet<>(); }/*w w w .jav a 2s . com*/ Map<String, Attachment> attachmentMap = Maps.uniqueIndex(attachments, Attachment::getAttachmentContentId); if (attachmentAdditions != null) { for (Attachment update : attachmentAdditions) { String id = update.getAttachmentContentId(); if (attachmentMap.containsKey(id)) { Attachment actual = attachmentMap.get(id); for (Attachment._Fields field : Attachment._Fields.values()) { if (update.isSet(field)) { actual.setFieldValue(field, update.getFieldValue(field)); } } } else { attachments.add(update); } } } Map<String, Attachment> additionsMap = attachmentAdditions != null ? Maps.uniqueIndex(attachmentAdditions, Attachment::getAttachmentContentId) : new HashMap<>(); if (attachmentDeletions != null) { for (Attachment delete : attachmentDeletions) { if (!additionsMap.containsKey(delete.getAttachmentContentId())) { attachments.remove(delete); } } } return attachments; }
From source file:org.polarsys.reqcycle.traceability.storage.vars.VarManager.java
private static Map<String, Variable> getAllVars() { List<IConfigurationElement> elements = Arrays .asList(Platform.getExtensionRegistry().getConfigurationElementsFor(Activator.PLUGIN_ID, EXT_ID)); Iterable<Variable> vars = Iterables .filter(Iterables.transform(elements, new Function<IConfigurationElement, Variable>() { @Override/*from w w w.j a va 2 s .c o m*/ public Variable apply(IConfigurationElement arg0) { try { return (Variable) arg0.createExecutableExtension("instance"); } catch (CoreException e) { } return null; } }), Predicates.notNull()); return Maps.uniqueIndex(vars, new Function<Variable, String>() { @Override public String apply(Variable arg0) { return arg0.getLabel(); } }); }
From source file:com.urswolfer.intellij.plugin.gerrit.ui.GerritSelectRevisionInfoColumn.java
@Nullable @Override/*from w w w .jav a 2 s . co m*/ public TableCellEditor getEditor(final ChangeInfo changeInfo) { ComboBoxTableRenderer<String> editor = createComboBoxTableRenderer(changeInfo); editor.addCellEditorListener(new CellEditorListener() { @Override public void editingStopped(ChangeEvent e) { ComboBoxTableRenderer cellEditor = (ComboBoxTableRenderer) e.getSource(); String value = (String) cellEditor.getCellEditorValue(); Iterable<Pair<String, RevisionInfo>> pairs = Iterables.transform(changeInfo.revisions.entrySet(), MAP_ENTRY_TO_PAIR); Map<String, Pair<String, RevisionInfo>> map = Maps.uniqueIndex(pairs, getRevisionLabelFunction(changeInfo)); Pair<String, RevisionInfo> pair = map.get(value); selectedRevisions.put(changeInfo.changeId, pair.getFirst()); } @Override public void editingCanceled(ChangeEvent e) { } }); return editor; }
From source file:com.urswolfer.intellij.plugin.gerrit.ui.changesbrowser.CommitDiffBuilder.java
public List<Change> getDiff() throws VcsException { baseChanges = Maps.uniqueIndex(changesProvider.provide(base), GET_CHANGED_FILE_PATH); changes = Maps.uniqueIndex(changesProvider.provide(commit), GET_CHANGED_FILE_PATH); addedFiles();//from w w w . j av a2 s . c om changedFiles(); removedFiles(); return Lists.newArrayList(Iterables.filter(diff, Predicates.not(CONTAINS_NO_CHANGE))); }
From source file:com.b2international.snowowl.snomed.core.domain.constraint.SnomedDependencyPredicate.java
@Override public DependencyPredicate applyChangesTo(final ConceptModelComponent existingModel) { final DependencyPredicate updatedModel = (existingModel instanceof DependencyPredicate) ? (DependencyPredicate) existingModel : createModel();//from w w w. jav a2 s . c om updatedModel.setActive(isActive()); updatedModel.setAuthor(getAuthor()); /* * We will update this list in place; on an existing instance, it will be already populated by some predicates, * on a new instance, it is completely empty. */ final List<ConceptModelPredicate> updatedModelChildren = updatedModel.getChildren(); // Index predicate keys by list position final Map<String, Integer> existingPredicatesByIdx = newHashMap(); for (int i = 0; i < updatedModelChildren.size(); i++) { final ConceptModelPredicate existingPredicate = updatedModelChildren.get(i); existingPredicatesByIdx.put(existingPredicate.getUuid(), i); } // Index new predicates by key final Map<String, SnomedPredicate> updatedPredicates = newHashMap( Maps.uniqueIndex(children, SnomedPredicate::getId)); // Iterate backwards over the list so that removals don't mess up the the list index map for (int j = updatedModelChildren.size() - 1; j >= 0; j--) { final ConceptModelPredicate existingPredicate = updatedModelChildren.get(j); final String uuid = existingPredicate.getUuid(); // Consume entries from "updatedPredicates" by using remove(Object key) final SnomedPredicate updatedPredicate = updatedPredicates.remove(uuid); // Was there a child with the same key? If not, remove the original from the list, if it is still there, update in place if (updatedPredicate == null) { updatedModelChildren.remove(j); } else { updatedModelChildren.set(j, updatedPredicate.applyChangesTo(existingPredicate)); } } // Remaining entries in "updatedPredicates" are new; add them to the end of the list for (final SnomedPredicate newChild : updatedPredicates.values()) { updatedModelChildren.add(newChild.applyChangesTo(newChild.createModel())); } updatedModel.setEffectiveTime(EffectiveTimes.toDate(getEffectiveTime())); updatedModel.setGroupRule(getGroupRule()); updatedModel.setOperator(getDependencyOperator()); updatedModel.setUuid(getId()); return updatedModel; }
From source file:controllers.api.IndicesApiController.java
public Result indexInfo(String indexName) { try {//from ww w. j av a 2s. c om final List<Index> indexes = indexService.all(); final ImmutableMap<String, Index> map = Maps.uniqueIndex(indexes, new Function<Index, String>() { @Nullable @Override public String apply(Index input) { return input.getName(); } }); final Index index = map.get(indexName); if (index == null) { return notFound(); } final String currentTarget = indexService.getDeflectorInfo().currentTarget; return ok(views.html.partials.indices.index_info.render(currentTarget, index)); } catch (APIException | IOException e) { return internalServerError(); } }
From source file:com.google.security.zynamics.binnavi.Database.cache.NodeCache.java
public void addNodes(final List<INaviViewNode> nodes) { nodeByIdCache.putAll(Maps.uniqueIndex(nodes, new Function<INaviViewNode, Integer>() { @Override//from w ww . ja v a2s . c o m public Integer apply(final INaviViewNode node) { return node.getId(); } })); for (final INaviViewNode node : nodes) { if (node instanceof INaviCodeNode) { final IAddress nodeAddress = ((INaviCodeNode) node).getAddress(); Integer moduleId = null; try { moduleId = ((INaviCodeNode) node).getParentFunction().getModule().getConfiguration().getId(); } catch (final MaybeNullException e) { continue; } if (moduleId != null) { UpdateAddressModuleIdCache(nodeAddress, moduleId, node); } } } }
From source file:org.opentestsystem.delivery.testadmin.service.impl.ParticipationDetailReportServiceImpl.java
@Override public List<TestAdminReport> buildPartipationReport(String instituionMongoId, Map<String, Assessment> assessmentMap, String testStatus, int opportunity) { List<TestAdminReport> detailReportList = new ArrayList<TestAdminReport>(); Set<String> assessmentIds = assessmentMap.keySet(); Sb11Entity institutionEntity = entityService.findById(instituionMongoId, FormatType.INSTITUTION); for (String assessmentId : assessmentIds) { List<EligibleStudent> eligibleStudents = eligibleStudentRepository .findByInstitutionIdAndAssessmentId(institutionEntity.getId(), assessmentId); Map<String, EligibleStudent> eligibleStudentMap = Maps.uniqueIndex(eligibleStudents, STUDENT_GROUP_BY_ID);/*from www . j av a2 s . c om*/ List<TestStatus> studentReports = studentTestRepository.findStudentReport(eligibleStudentMap.keySet(), institutionEntity.getStateAbbreviation(), assessmentId, opportunity, testStatus); Map<String, TestStatus> studentTestReportMap = Maps.uniqueIndex(studentReports, STUDENT_TEST_REPORT_GROUP_BY_ID); if (testStatus == null || testStatus.isEmpty()) { for (Entry<String, EligibleStudent> studentEntry : eligibleStudentMap.entrySet()) { Student student = studentEntry.getValue().getStudent(); TestStatus testReport = studentTestReportMap.get(studentEntry.getKey()); detailReportList.add(populateDetailReport(student, testReport, testStatus, assessmentMap.get(assessmentId), opportunity)); } } else if (testStatus.equals(Status.SCHEDULED.name())) { List<TestStatus> testReports = studentTestRepository.findStudentReport(eligibleStudentMap.keySet(), institutionEntity.getStateAbbreviation(), assessmentId, opportunity, null); Map<String, TestStatus> allTestStatusReport = Maps.uniqueIndex(testReports, STUDENT_TEST_REPORT_GROUP_BY_ID); // First find out the not Scheduled tests for (Entry<String, EligibleStudent> studentEntry : eligibleStudentMap.entrySet()) { if (allTestStatusReport.get(studentEntry.getKey()) == null) { Student student = studentEntry.getValue().getStudent(); detailReportList.add(populateDetailReport(student, null, testStatus, assessmentMap.get(assessmentId), opportunity)); } } addTestReport(assessmentMap, testStatus, detailReportList, assessmentId, eligibleStudentMap, studentTestReportMap, opportunity); } else { addTestReport(assessmentMap, testStatus, detailReportList, assessmentId, eligibleStudentMap, studentTestReportMap, opportunity); } } return detailReportList; }
From source file:org.apache.whirr.actions.ConfigureClusterAction.java
@Override protected void doAction(Map<InstanceTemplate, ClusterActionEvent> eventMap) throws IOException { for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) { ClusterSpec clusterSpec = entry.getValue().getClusterSpec(); Cluster cluster = entry.getValue().getCluster(); StatementBuilder statementBuilder = entry.getValue().getStatementBuilder(); ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec); ComputeService computeService = computeServiceContext.getComputeService(); Credentials credentials = new Credentials(clusterSpec.getClusterUser(), clusterSpec.getPrivateKey()); try {// w w w . j ava 2 s .c o m Map<String, ? extends NodeMetadata> nodesInCluster = getNodesForInstanceIdsInCluster(cluster, computeService); if (LOG.isDebugEnabled()) { LOG.debug("Nodes in cluster: {}", nodesInCluster.values()); } Map<String, ? extends NodeMetadata> nodesToApply = Maps.uniqueIndex( Iterables.filter(nodesInCluster.values(), toNodeMetadataPredicate(clusterSpec, cluster, entry.getKey().getRoles())), getNodeId); LOG.info("Running configuration script on nodes: {}", nodesToApply.keySet()); if (LOG.isDebugEnabled()) LOG.debug("script:\n{}", statementBuilder.render(OsFamily.UNIX)); computeService.runScriptOnNodesMatching(withIds(nodesToApply.keySet()), statementBuilder, RunScriptOptions.Builder.overrideCredentialsWith(credentials)); LOG.info("Configuration script run completed"); } catch (RunScriptOnNodesException e) { // TODO: retry throw new IOException(e); } } }