List of usage examples for com.google.common.collect Multimaps index
public static <K, V> ImmutableListMultimap<K, V> index(Iterator<V> values, Function<? super V, K> keyFunction)
From source file:org.eclipse.xtend.core.validation.XtendValidator.java
@Check public void checkMultipleAnnotations(final XtendAnnotationTarget annotationTarget) { if (annotationTarget.getAnnotations().size() <= 1 || !isRelevantAnnotationTarget(annotationTarget)) { return;//from ww w. j a v a2 s. c o m } ImmutableListMultimap<String, XAnnotation> groupByIdentifier = Multimaps .index(annotationTarget.getAnnotations(), new Function<XAnnotation, String>() { @Override public String apply(XAnnotation input) { return input.getAnnotationType().getIdentifier(); } }); for (String qName : groupByIdentifier.keySet()) { ImmutableList<XAnnotation> sameType = groupByIdentifier.get(qName); if (sameType.size() > 1) { JvmType type = sameType.get(0).getAnnotationType(); if (type instanceof JvmAnnotationType && !type.eIsProxy() && !annotationLookup.isRepeatable((JvmAnnotationType) type)) { for (XAnnotation xAnnotation : sameType) { error("Multiple annotations of non-repeatable type @" + xAnnotation.getAnnotationType().getSimpleName() + ". Only annotation types marked @Repeatable can be used multiple times at one target.", xAnnotation, XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, INSIGNIFICANT_INDEX, ANNOTATION_MULTIPLE); } } } } }
From source file:org.apache.omid.transaction.SnapshotFilterImpl.java
static ImmutableList<Collection<Cell>> groupCellsByColumnFilteringShadowCellsAndFamilyDeletion( List<Cell> rawCells) { Predicate<Cell> shadowCellAndFamilyDeletionFilter = new Predicate<Cell>() { @Override/* w ww .j a va 2 s .c om*/ public boolean apply(Cell cell) { boolean familyDeletionMarkerCondition = CellUtils.isFamilyDeleteCell(cell); return cell != null && !CellUtils.isShadowCell(cell) && !familyDeletionMarkerCondition; } }; Function<Cell, ColumnWrapper> cellToColumnWrapper = new Function<Cell, ColumnWrapper>() { @Override public ColumnWrapper apply(Cell cell) { return new ColumnWrapper(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell)); } }; return Multimaps.index(Iterables.filter(rawCells, shadowCellAndFamilyDeletionFilter), cellToColumnWrapper) .asMap().values().asList(); }
From source file:edu.harvard.med.screensaver.model.screens.Screen.java
/** * @return a SortedSet of LibraryPlates. The library property will be null if the AssayPlate was not screened, but has * had data loaded./*from w w w . j a v a 2s . com*/ */ @Transient public SortedSet<LibraryPlate> getLibraryPlatesScreened() { Multimap<Integer, AssayPlate> index = Multimaps.index( Iterables.filter(getAssayPlates(), AssayPlate.IsScreened), new Function<AssayPlate, Integer>() { @Override public Integer apply(AssayPlate p) { return p.getPlateNumber(); } }); SortedSet<LibraryPlate> libraryPlates = Sets.newTreeSet(); for (Integer plateNumber : index.keySet()) { AssayPlate firstAssayPlate = Iterables.get(index.get(plateNumber), 0); Library library = null; if (firstAssayPlate.getPlateScreened() != null) { library = firstAssayPlate.getPlateScreened().getCopy().getLibrary(); } libraryPlates.add(new LibraryPlate(plateNumber, library, Sets.newHashSet(index.get(plateNumber)))); } return libraryPlates; }
From source file:org.apache.hadoop.hdfs.server.namenode.JournalSet.java
/** * Return a manifest of what finalized edit logs are available. All available * edit logs are returned starting from the transaction id passed. If * 'fromTxId' falls in the middle of a log, that log is returned as well. * /* w ww . java 2 s. c o m*/ * @param fromTxId Starting transaction id to read the logs. * @return RemoteEditLogManifest object. */ public synchronized RemoteEditLogManifest getEditLogManifest(long fromTxId) { // Collect RemoteEditLogs available from each FileJournalManager List<RemoteEditLog> allLogs = Lists.newArrayList(); for (JournalAndStream j : journals) { if (j.getManager() instanceof FileJournalManager) { FileJournalManager fjm = (FileJournalManager) j.getManager(); try { allLogs.addAll(fjm.getRemoteEditLogs(fromTxId, false)); } catch (Throwable t) { LOG.warn("Cannot list edit logs in " + fjm, t); } } } // Group logs by their starting txid ImmutableListMultimap<Long, RemoteEditLog> logsByStartTxId = Multimaps.index(allLogs, RemoteEditLog.GET_START_TXID); long curStartTxId = fromTxId; List<RemoteEditLog> logs = Lists.newArrayList(); while (true) { ImmutableList<RemoteEditLog> logGroup = logsByStartTxId.get(curStartTxId); if (logGroup.isEmpty()) { // we have a gap in logs - for example because we recovered some old // storage directory with ancient logs. Clear out any logs we've // accumulated so far, and then skip to the next segment of logs // after the gap. SortedSet<Long> startTxIds = Sets.newTreeSet(logsByStartTxId.keySet()); startTxIds = startTxIds.tailSet(curStartTxId); if (startTxIds.isEmpty()) { break; } else { if (LOG.isDebugEnabled()) { LOG.debug("Found gap in logs at " + curStartTxId + ": " + "not returning previous logs in manifest."); } logs.clear(); curStartTxId = startTxIds.first(); continue; } } // Find the one that extends the farthest forward RemoteEditLog bestLog = Collections.max(logGroup); logs.add(bestLog); // And then start looking from after that point curStartTxId = bestLog.getEndTxId() + 1; } RemoteEditLogManifest ret = new RemoteEditLogManifest(logs); if (LOG.isDebugEnabled()) { LOG.debug("Generated manifest for logs since " + fromTxId + ":" + ret); } return ret; }
From source file:io.airlift.drift.codec.metadata.AbstractThriftMetadataBuilder.java
/** * Assigns all fields an id if possible. Fields are grouped by name and for each group, if there * is a single id, all fields in the group are assigned this id. If the group has multiple ids, * an error is reported./*from www . j av a 2s . c o m*/ */ protected final Set<String> inferThriftFieldIds() { Set<String> fieldsWithConflictingIds = new HashSet<>(); // group fields by explicit name or by name extracted from field, method or property Multimap<String, FieldMetadata> fieldsByExplicitOrExtractedName = Multimaps.index(fields, FieldMetadata::getOrExtractThriftFieldName); inferThriftFieldIds(fieldsByExplicitOrExtractedName, fieldsWithConflictingIds); // group fields by name extracted from field, method or property // this allows thrift name to be set explicitly without having to duplicate the name on getters and setters // todo should this be the only way this works? Multimap<String, FieldMetadata> fieldsByExtractedName = Multimaps.index(fields, FieldMetadata::extractName); inferThriftFieldIds(fieldsByExtractedName, fieldsWithConflictingIds); return fieldsWithConflictingIds; }
From source file:com.facebook.swift.codec.metadata.AbstractThriftMetadataBuilder.java
/** * Assigns all fields an id if possible. Fields are grouped by name and for each group, if there * is a single id, all fields in the group are assigned this id. If the group has multiple ids, * an error is reported.// ww w .ja v a2 s . c o m */ protected final Set<String> inferThriftFieldIds() { Set<String> fieldsWithConflictingIds = new HashSet<>(); // group fields by explicit name or by name extracted from field, method or property Multimap<String, FieldMetadata> fieldsByExplicitOrExtractedName = Multimaps.index(fields, getOrExtractThriftFieldName()); inferThriftFieldIds(fieldsByExplicitOrExtractedName, fieldsWithConflictingIds); // group fields by name extracted from field, method or property // this allows thrift name to be set explicitly without having to duplicate the name on getters and setters // todo should this be the only way this works? Multimap<String, FieldMetadata> fieldsByExtractedName = Multimaps.index(fields, extractThriftFieldName()); inferThriftFieldIds(fieldsByExtractedName, fieldsWithConflictingIds); return fieldsWithConflictingIds; }
From source file:org.apache.omid.transaction.SnapshotFilterImpl.java
static ImmutableList<Collection<Cell>> groupCellsByColumnFilteringShadowCells(List<Cell> rawCells) { Predicate<Cell> shadowCellFilter = new Predicate<Cell>() { @Override/*ww w. jav a 2 s .c o m*/ public boolean apply(Cell cell) { return cell != null && !CellUtils.isShadowCell(cell); } }; Function<Cell, ColumnWrapper> cellToColumnWrapper = new Function<Cell, ColumnWrapper>() { @Override public ColumnWrapper apply(Cell cell) { return new ColumnWrapper(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell)); } }; return Multimaps.index(Iterables.filter(rawCells, shadowCellFilter), cellToColumnWrapper).asMap().values() .asList(); }
From source file:com.yahoo.omid.transaction.TTable.java
static ImmutableList<Collection<Cell>> groupCellsByColumnFilteringShadowCells(List<Cell> rawCells) { Predicate<Cell> shadowCellFilter = new Predicate<Cell>() { @Override/*w ww. ja va 2 s .co m*/ public boolean apply(Cell cell) { return !CellUtils.isShadowCell(cell); } }; Function<Cell, ColumnWrapper> cellToColumnWrapper = new Function<Cell, ColumnWrapper>() { @Override public ColumnWrapper apply(Cell cell) { return new ColumnWrapper(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell)); } }; return Multimaps.index(Iterables.filter(rawCells, shadowCellFilter), cellToColumnWrapper).asMap().values() .asList(); }
From source file:com.facebook.swift.codec.metadata.ThriftStructMetadataBuilder.java
private Iterable<ThriftFieldMetadata> buildFieldInjections() { Multimap<Optional<Short>, FieldMetadata> fieldsById = Multimaps.index(fields, getThriftFieldId()); return Iterables.transform(fieldsById.asMap().values(), new Function<Collection<FieldMetadata>, ThriftFieldMetadata>() { @Override/* w w w. ja va2s .co m*/ public ThriftFieldMetadata apply(Collection<FieldMetadata> input) { checkArgument(!input.isEmpty(), "input is empty"); return buildField(input); } }); }
From source file:org.apache.ambari.server.state.ServiceInfo.java
private void validateServiceProperties() { // Verify if there are duplicate service properties by name Multimap<String, ServicePropertyInfo> servicePropsByName = Multimaps.index(getServicePropertyList(), new Function<ServicePropertyInfo, String>() { @Override/*from w w w . j av a 2 s .co m*/ public String apply(ServicePropertyInfo servicePropertyInfo) { return servicePropertyInfo.getName(); } } ); for (String propertyName : servicePropsByName.keySet()) { if (servicePropsByName.get(propertyName).size() > 1) { setValid(false); setErrors("Duplicate service property with name '" + propertyName + "' found in " + getName() + ":" + getVersion() + " service definition !"); } } }