List of usage examples for com.google.common.collect BiMap containsValue
boolean containsValue(Object value);
From source file:blue.lapis.pore.converter.type.material.DurabilityConverter.java
@SuppressWarnings({ "rawtypes", "unchecked" }) // I can't parameterize this either; it scares the compiler private static <T extends VariantData<U, T, ?>, U extends CatalogType> T getItemData(ItemStack item, Class<T> type, BiMap<U, Integer> map) { int damage = item.getDurability(); if (!map.containsValue(damage)) { throw new UnsupportedOperationException(); }//from w w w .ja v a 2 s . com // no idea why a typecast is necessary here but excluding it makes javac angry @SuppressWarnings("RedundantCast") T data = (T) Pore.getGame().getRegistry().createItemBuilder() .itemType(MaterialConverter.asItem(item.getType())).quantity(1).build().getOrCreate(type).get(); data.type().set(map.inverse().get(damage)); return data; }
From source file:fi.hsl.parkandride.back.RequestLogDao.java
private static Set<String> difference(Set<String> toPersist, BiMap<Long, String> alreadyPersisted) { return toPersist.stream().filter(val -> !alreadyPersisted.containsValue(val)).collect(toSet()); }
From source file:gr.forth.ics.swkm.model2.diff.DiffUtils.java
static RdfNode mapNodeToAnotherModel(Resource node, Model m, BiMap<String, String> namespaceMap) { RdfNode mappedNode = null;/*from w ww . ja va2s . co m*/ if (namespaceMap.containsKey(node.getUri().getNamespace())) { Uri u = new Uri(namespaceMap.get(node.getUri().getNamespace()), node.getUri().getLocalName()); if (m.mapResource(u).hasTriples()) { mappedNode = m.mapResource(u); } } else if (namespaceMap.containsValue(node.getUri().getNamespace())) { Uri u = new Uri(namespaceMap.inverse().get(node.getUri().getNamespace()), node.getUri().getLocalName()); if (m.mapResource(u).hasTriples()) { mappedNode = m.mapResource(u); } } else { if (m.mapResource(node.getIdentifier()).hasTriples()) { mappedNode = m.mapResource(node.getIdentifier()); } } return mappedNode; }
From source file:org.datacleaner.job.JaxbJobWriter.java
private static String getColumnId(InputColumn<?> inputColumn, BiMap<InputColumn<?>, String> columnMappings) { if (inputColumn == null) { throw new IllegalArgumentException("InputColumn cannot be null"); }//from www. j a v a 2 s.co m String id = columnMappings.get(inputColumn); if (id == null) { final String baseColumnId = getBaseColumnId(inputColumn); id = baseColumnId; int addition = 1; while (columnMappings.containsValue(id)) { addition++; id = baseColumnId + addition; } columnMappings.put(inputColumn, id); } return id; }
From source file:org.ambraproject.wombat.config.site.SiteSet.java
/** * Build a map representing the one-to-one relationship between journal keys and journal names. * <p/>/*w ww .jav a 2s . c o m*/ * As a side effect, validates that the relationship actually is one-to-one -- that is, that multiple sites have the * same journal key if and only if they have the same journal name. It is easier to obey this constraint if the {@code * journalKey} and {@code journalName} config values are always set in the {@code journal.yaml} or {@code * journal.json} file of the same theme, which should be a parent of all themes belonging to that journal. * * @param sites the set of all sites being served * @return a map between journal keys and journal names * @throws IllegalArgumentException if two sites with the same journal key have unequal journal names or if two sites * with the same journal name have unequal journal keys */ private static ImmutableBiMap<String, String> buildJournalKeysToNames(Set<Site> sites) { Multimap<String, Site> keysToSites = groupByJournalKey(sites); BiMap<String, String> keysToNames = HashBiMap.create(keysToSites.keySet().size()); for (Map.Entry<String, Collection<Site>> entry : keysToSites.asMap().entrySet()) { String journalKey = entry.getKey(); Iterator<Site> siteIterator = entry.getValue().iterator(); String journalName = siteIterator.next().getJournalName(); while (siteIterator.hasNext()) { String nextJournalName = siteIterator.next().getJournalName(); if (!journalName.equals(nextJournalName)) { String message = String.format("Inconsistent journal names with key=%s: %s; %s", journalKey, journalName, nextJournalName); throw new IllegalArgumentException(message); } } if (keysToNames.containsValue(journalName)) { String message = String.format("Overloaded journal name (%s) for keys: %s; %s", journalName, journalKey, keysToNames.inverse().get(journalName)); throw new IllegalArgumentException(message); } keysToNames.put(journalKey, journalName); } return ImmutableBiMap.copyOf(keysToNames); }
From source file:org.opencb.opencga.storage.mongodb.variant.MongoDBVariantStoragePipeline.java
/** * Check if the samples from the selected file can be loaded. * Check if the samples from the selected file can be loaded. * <p>/*from ww w.j av a 2 s . c o m*/ * MongoDB storage plugin is not able to load batches of samples in a unordered way. * A batch of samples is a group of samples of any size. It may be composed of one or several VCF files, depending * on whether it is split by region (horizontally) or not. * All the files from the same batch must be loaded, before loading the next batch. If a new batch of * samples begins to be loaded, it won't be possible to load other files from previous batches * <p> * The StudyConfiguration must be complete, with all the indexed files, and samples in files. * Provided StudyConfiguration won't be modified * Requirements: * - All samples in file must be or loaded or not loaded * - If all samples loaded, must match (same order and samples) with the last loaded file. * * @param studyConfiguration StudyConfiguration from the selected study * @param fileId File to load * @return Returns if this file represents a new batch of samples * @throws StorageEngineException If there is any unaccomplished requirement */ public static boolean checkCanLoadSampleBatch(final StudyConfiguration studyConfiguration, int fileId) throws StorageEngineException { LinkedHashSet<Integer> sampleIds = studyConfiguration.getSamplesInFiles().get(fileId); if (!sampleIds.isEmpty()) { boolean allSamplesRepeated = true; boolean someSamplesRepeated = false; BiMap<String, Integer> indexedSamples = StudyConfiguration.getIndexedSamples(studyConfiguration); for (Integer sampleId : sampleIds) { if (!indexedSamples.containsValue(sampleId)) { allSamplesRepeated = false; } else { someSamplesRepeated = true; } } if (allSamplesRepeated) { ArrayList<Integer> indexedFiles = new ArrayList<>(studyConfiguration.getIndexedFiles()); if (!indexedFiles.isEmpty()) { int lastIndexedFile = indexedFiles.get(indexedFiles.size() - 1); //Check that are the same samples in the same order if (!new ArrayList<>(studyConfiguration.getSamplesInFiles().get(lastIndexedFile)) .equals(new ArrayList<>(sampleIds))) { //ERROR if (studyConfiguration.getSamplesInFiles().get(lastIndexedFile).containsAll(sampleIds)) { throw new StorageEngineException("Unable to load this batch. Wrong samples order"); //TODO: Should it care? } else { throw new StorageEngineException( "Unable to load this batch. Another sample batch has been loaded already."); } } //Ok, the batch of samples matches with the last loaded batch of samples. return false; // This is NOT a new batch of samples } } else if (someSamplesRepeated) { throw new StorageEngineException("There was some already indexed samples, but not all of them. " + "Unable to load in Storage-MongoDB"); } } return true; // This is a new batch of samples }
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);//w w w .ja v a 2s .c o 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:org.eclipse.xtext.xtext.generator.parser.antlr.KeywordHelper.java
private BiMap<CharSequence, String> createKeywordMap(Grammar grammar) { List<ParserRule> parserRules = GrammarUtil.allParserRules(grammar); List<EnumRule> enumRules = GrammarUtil.allEnumRules(grammar); Iterator<EObject> iter = Iterators.concat(EcoreUtil.<EObject>getAllContents(parserRules), EcoreUtil.<EObject>getAllContents(enumRules)); Iterator<Keyword> filtered = Iterators.filter(iter, Keyword.class); Iterator<String> transformed = Iterators.transform(filtered, new Function<Keyword, String>() { @Override/*from w w w .j a v a 2 s.c o m*/ public String apply(Keyword from) { return from.getValue(); } }); TreeSet<String> treeSet = Sets.newTreeSet(new Comparator<String>() { @Override public int compare(String o1, String o2) { if (o1.length() == o2.length()) return o1.compareTo(o2); return Integer.valueOf(o1.length()).compareTo(Integer.valueOf(o2.length())); } }); Iterators.addAll(treeSet, transformed); BiMap<CharSequence, String> result = HashBiMap.create(); for (String s : treeSet) { CharSequence key = createKey(s); String readableName = toAntlrTokenIdentifier(s); if (result.containsValue(readableName)) { int i = 1; String next = readableName + "_" + i; while (result.containsValue(next)) { i++; next = readableName + "_" + i; } readableName = next; } result.put(key, readableName); } return result; }
From source file:org.eclipse.emf.compare.match.update.Updater.java
/** * Adds to oldValues the elements from newValues which are do not already have an equivalent. The elements * are added at the correct location.//from ww w .j a v a 2s .c om * <p> * The ELists we are are containment ELists, so adding an element from one to the other modifies the * source list, messing the index computation. We do this in two passes: compute which elements are * missing and the locations they should be inserted in into a simple array, and then apply the necessary * changes. */ private void addMissingElements(EList<EObject> oldValues, EList<EObject> newValues, BiMap<EObject, EObject> matches) { EObject[] missing = new EObject[newValues.size()]; for (int i = 0; i < newValues.size(); i++) { EObject newValue = newValues.get(i); boolean isMissingElement = !matches.containsValue(newValue); if (isMissingElement) { missing[i] = newValue; } } for (int i = 0; i < missing.length; i++) { if (missing[i] != null) { oldValues.add(i, missing[i]); } } }
From source file:edu.umd.cs.psl.evaluation.debug.CmdDebugger.java
private void printGroundKernels(Collection<GroundKernel> evidences) { BiMap<Integer, Atom> biatomHandles = HashBiMap.create(); int counter = 1; for (GroundKernel e : evidences) { String str = printGroundKernels(e); StringBuilder dep = new StringBuilder(); dep.append("--> Affected Atoms: "); Collection<Atom> atoms = e.getAtoms(); for (Atom a : atoms) { int atomNr = -1; if (biatomHandles.containsValue(a)) { atomNr = biatomHandles.inverse().get(a); } else { atomNr = counter;//from www.j a va2 s . co m counter++; biatomHandles.put(atomNr, a); } str.replace(a.toString(), a.toString() + " [" + atomNr + "]"); dep.append(AtomPrinter.atomDetails(a)).append(" [" + atomNr + "]").append(" , "); } println(str); println(dep.toString()); } atomHandles = biatomHandles; }