List of usage examples for com.google.common.collect BiMap put
@Override @Nullable V put(@Nullable K key, @Nullable V value);
From source file:org.cloudsmith.geppetto.pp.dsl.ui.container.PPWorkspaceProjectsStateHelper.java
/** * Returns the best matching project (or null if there is no match) among the projects in the * workspace./*from www . j ava2 s.com*/ * A translation is made from "/" to "-" in the separators in dependencies. (Should be checked elsewhere). * * @param d * @return */ protected IProject getBestMatchingProject(Dependency d) { ModuleName name = d.getName(); if (name == null) return null; // Names with "/" are not allowed name = name.withSeparator('-'); String namepart = name + "-"; BiMap<IProject, Version> candidates = HashBiMap.create(); int len = namepart.length(); for (IProject p : getWorkspaceRoot().getProjects()) { String n = p.getName(); if (n.startsWith(namepart) && n.length() > len && isAccessibleXtextProject(p)) { try { candidates.put(p, Version.create(p.getName().substring(len))); } catch (IllegalArgumentException e) { // Project name does not end with a valid version. Just skip it } } } if (candidates.isEmpty()) return null; VersionRange vr = d.getVersionRequirement(); if (vr == null) vr = VersionRange.ALL_INCLUSIVE; Version best = vr.findBestMatch(candidates.values()); return candidates.inverse().get(best); }
From source file:net.sourcedestination.sai.comparison.matching.MatchingGenerator.java
@SuppressWarnings("unchecked") public static MatchingGenerator createCompleteMatchingGenerator(final FeatureSetCompatibilityChecker fscc, final GraphMatchingHeuristic h) { return (g1, g2) -> { final Multimap<Integer, Integer> possibilities = getNodeMatchingPossibilities(fscc, g1, g2); //put node ID's in an array to insure they remain in the same order List<Integer> nodeIDsTemp = Lists.newArrayList(); g1.getNodeIDs().forEach(n1 -> { if (possibilities.containsKey(n1)) nodeIDsTemp.add(n1);//from w w w . j a v a2 s .co m }); final Integer[] nodeIDs = nodeIDsTemp.toArray(new Integer[nodeIDsTemp.size()]); //create an iterator for the possible complete mappings Iterator<GraphMatching> i = new Iterator<GraphMatching>() { private int[] currentMap = new int[nodeIDs.length]; private GraphMatching nextMatching = nextMatching(); @Override public boolean hasNext() { return nextMatching != null; } @Override public GraphMatching next() { if (nextMatching == null) throw new IllegalStateException("no more matchings left"); GraphMatching currentMatching = nextMatching; nextMatching = nextMatching(); return currentMatching; } public GraphMatching nextMatching() { BiMap<Integer, Integer> nodeMap = null; while (nodeMap == null && currentMap != null) { nodeMap = HashBiMap.create(); //create map object for (int i = 0; i < nodeIDs.length; i++) { int skip = currentMap[i]; // it is assumed the following iterator is deterministic Iterator<Integer> ii = possibilities.get(nodeIDs[i]).iterator(); while (skip > 0) { skip--; ii.next(); } int mapToNode = ii.next(); if (nodeMap.containsValue(mapToNode)) { //don't map two g1 nodes to the same g2 node //nodeMap = null; //break; continue; } nodeMap.put(nodeIDs[i], mapToNode); } //increment to next map: boolean incremented = false; for (int i = 0; i < currentMap.length; i++) { if (currentMap[i] < possibilities.get(nodeIDs[i]).size() - 1) { currentMap[i]++; incremented = true; break; } currentMap[i] = 0; } if (!incremented) currentMap = null; } if (nodeMap == null) return null; return induceEdgeMatching(createBasicNodeMatching(g1, g2, nodeMap), fscc); } }; Iterable<GraphMatching> iterable = () -> i; Stream<GraphMatching> s = StreamSupport.stream(iterable.spliterator(), false); // TODO: determine why there is a syntax error without the reference below // h extends Function<GraphMatching,Double>, but isn't recognized as such // this is also corrected with a cast, but this is shorter return argmax(h::apply, s); }; }
From source file:com.facebook.presto.sql.planner.NodePartitioningManager.java
public NodePartitionMap getNodePartitioningMap(Session session, PartitioningHandle partitioningHandle) { requireNonNull(session, "session is null"); requireNonNull(partitioningHandle, "partitioningHandle is null"); if (partitioningHandle.getConnectorHandle() instanceof SystemPartitioningHandle) { return ((SystemPartitioningHandle) partitioningHandle.getConnectorHandle()).getNodePartitionMap(session, nodeScheduler);//from ww w . ja v a2 s. c o m } ConnectorNodePartitioningProvider partitioningProvider = partitioningProviders .get(partitioningHandle.getConnectorId().get()); checkArgument(partitioningProvider != null, "No partitioning provider for connector %s", partitioningHandle.getConnectorId().get()); Map<Integer, Node> bucketToNode = partitioningProvider.getBucketToNode( partitioningHandle.getTransactionHandle().orElse(null), session.toConnectorSession(), partitioningHandle.getConnectorHandle()); checkArgument(bucketToNode != null, "No partition map %s", partitioningHandle); checkArgument(!bucketToNode.isEmpty(), "Partition map %s is empty", partitioningHandle); int bucketCount = bucketToNode.keySet().stream().mapToInt(Integer::intValue).max().getAsInt() + 1; // safety check for crazy partitioning checkArgument(bucketCount < 1_000_000, "Too many buckets in partitioning: %s", bucketCount); int[] bucketToPartition = new int[bucketCount]; BiMap<Node, Integer> nodeToPartition = HashBiMap.create(); int nextPartitionId = 0; for (Entry<Integer, Node> entry : bucketToNode.entrySet()) { Integer partitionId = nodeToPartition.get(entry.getValue()); if (partitionId == null) { partitionId = nextPartitionId++; nodeToPartition.put(entry.getValue(), partitionId); } bucketToPartition[entry.getKey()] = partitionId; } ToIntFunction<ConnectorSplit> splitBucketFunction = partitioningProvider.getSplitBucketFunction( partitioningHandle.getTransactionHandle().orElse(null), session.toConnectorSession(), partitioningHandle.getConnectorHandle()); checkArgument(splitBucketFunction != null, "No partitioning %s", partitioningHandle); return new NodePartitionMap(nodeToPartition.inverse(), bucketToPartition, split -> splitBucketFunction.applyAsInt(split.getConnectorSplit())); }
From source file:uk.ac.ebi.mdk.domain.matrix.StoichiometricMatrixImpl.java
/** * Assigns the values and sets all reactions reversibility to that present * in the 'other' matrix//from ww w. j a v a 2 s .co m * * @param other * * @return */ public BiMap<Integer, Integer> assign(StoichiometricMatrix<? extends M, ? extends R> other) { // ensure there is enough space this.ensure(getMoleculeCount() + other.getReactionCount(), getReactionCount() + other.getReactionCount()); BiMap<Integer, Integer> map = HashBiMap.create(); /** * Need whole loop as the called to this addReaction(R,M[],T[]) will set * reversible to true (default) leading to clash on checking for * duplicate reactions */ for (int j = 0; j < other.getReactionCount(); j++) { map.put(j, this.addReaction(other.getReaction(j), other.getReactionMolecules(j), other.getReactionValues(j), other.isReversible(j))); } return map; }
From source file:jenjinn.ui.chessboard.ChessBoard.java
private void rotatePoints() { final BiMap<Point2D, Sq> newMap = HashBiMap.create(64); final PointTransform rotate = getRotationTransform(); for (final Point2D p : squareLocations.keySet()) { newMap.put(rotate.transform(p), squareLocations.get(p)); }/* www.j av a 2 s . c om*/ squareLocations = newMap; }
From source file:org.jpmml.evaluator.general_regression.GeneralRegressionModelEvaluator.java
static private BiMap<String, Parameter> parseParameterRegistry(ParameterList parameterList) { BiMap<String, Parameter> result = HashBiMap.create(); if (!parameterList.hasParameters()) { return result; }/*ww w . ja v a2 s. c o m*/ List<Parameter> parameters = parameterList.getParameters(); for (Parameter parameter : parameters) { result.put(parameter.getName(), parameter); } return result; }
From source file:org.apache.calcite.rel.rules.AbstractMaterializedViewRule.java
/** * It will flatten a multimap containing table references to table references, * producing all possible combinations of mappings. Each of the mappings will * be bi-directional.//from w w w . j av a 2s . c o m */ private static List<BiMap<RelTableRef, RelTableRef>> generateTableMappings( Multimap<RelTableRef, RelTableRef> multiMapTables) { final List<BiMap<RelTableRef, RelTableRef>> result = new ArrayList<>(); if (multiMapTables.isEmpty()) { return result; } result.add(HashBiMap.<RelTableRef, RelTableRef>create()); for (Entry<RelTableRef, Collection<RelTableRef>> e : multiMapTables.asMap().entrySet()) { boolean added = false; for (RelTableRef target : e.getValue()) { if (added) { for (BiMap<RelTableRef, RelTableRef> m : result) { final BiMap<RelTableRef, RelTableRef> newM = HashBiMap.<RelTableRef, RelTableRef>create(m); newM.put(e.getKey(), target); result.add(newM); } } else { for (BiMap<RelTableRef, RelTableRef> m : result) { m.put(e.getKey(), target); } added = true; } } // Mapping needs to exist assert added; } return result; }
From source file:org.jpmml.evaluator.general_regression.GeneralRegressionModelEvaluator.java
static private BiMap<FieldName, Predictor> parsePredictorRegistry(PredictorList predictorList) { BiMap<FieldName, Predictor> result = HashBiMap.create(); if (predictorList == null || !predictorList.hasPredictors()) { return result; }/*w w w.ja v a 2 s. c o m*/ List<Predictor> predictors = predictorList.getPredictors(); for (Predictor predictor : predictors) { result.put(predictor.getName(), predictor); } return result; }
From source file:org.eclipse.sirius.common.tools.api.editing.FileStatusPrecommitListener.java
/** * {@inheritDoc}/*w w w . j av a 2 s .co m*/ */ @Override public Command transactionAboutToCommit(final ResourceSetChangeEvent event) throws RollbackException { final boolean defensiveEditValidation = Platform.getPreferencesService().getBoolean( "org.eclipse.sirius.common.ui", CommonPreferencesConstants.PREF_DEFENSIVE_EDIT_VALIDATION, true, //$NON-NLS-1$ null); final Command cmd = super.transactionAboutToCommit(event); if (defensiveEditValidation) { final Set<Resource> changedRes = Sets.newLinkedHashSet(); if (!event.getTransaction().isReadOnly()) { for (org.eclipse.emf.common.notify.Notification notif : Iterables.filter(event.getNotifications(), org.eclipse.emf.common.notify.Notification.class)) { if (notif.getNotifier() instanceof EObject) { final Resource res = ((EObject) notif.getNotifier()).eResource(); if (resourceChange(res, notif)) { changedRes.add(res); } } } } final BiMap<IFile, Resource> files2Validate = HashBiMap.create(); final Iterator<Resource> it = changedRes.iterator(); while (it.hasNext()) { final Resource nextResource = it.next(); final IFile file = WorkspaceSynchronizer.getFile(nextResource); if (file != null && file.isReadOnly()) { files2Validate.put(file, nextResource); } } if (!files2Validate.isEmpty()) { final RollbackException cancelException = new RollbackException( new Status(IStatus.CANCEL, DslCommonPlugin.PLUGIN_ID, Messages.FileStatusPrecommitListener_fileModificationValidationStatus)); final MultiStatus status = new MultiStatus(DslCommonPlugin.PLUGIN_ID, IStatus.ERROR, Messages.FileStatusPrecommitListener_fileModificationValidationStatus, cancelException); if (fileModificationValidators.isEmpty()) { // No extension found, use the default process. status.add(ResourcesPlugin.getWorkspace().validateEdit( files2Validate.keySet().toArray(new IFile[files2Validate.size()]), IWorkspace.VALIDATE_PROMPT)); } else { for (final IFileModificationValidator fileModificationValidator : fileModificationValidators) { final IStatus validationStatus = fileModificationValidator .validateEdit(files2Validate.keySet()); if (validationStatus != null) { status.add(validationStatus); } } } if (!status.isOK()) { throw cancelException; } } } return cmd; }
From source file:com.cloudera.oryx.rdf.computation.local.ReadInputs.java
private int categoricalFromString(int columnNumber, String value) { BiMap<String, Integer> categoryNameToID = columnToCategoryNameToIDMapping.get(columnNumber); if (categoryNameToID == null) { categoryNameToID = HashBiMap.create(); columnToCategoryNameToIDMapping.put(columnNumber, categoryNameToID); }//from w ww . j a v a 2s. c o m Integer mapped = categoryNameToID.get(value); if (mapped != null) { return mapped; } int newCategory = categoryNameToID.size(); categoryNameToID.put(value, newCategory); return newCategory; }