List of usage examples for com.google.common.collect TreeMultimap create
public static <K extends Comparable, V extends Comparable> TreeMultimap<K, V> create()
From source file:com.b2international.snowowl.snomed.datastore.converter.SnomedConceptConverter.java
private void expandAncestors(List<SnomedConcept> results, Set<String> conceptIds, String key, boolean stated) { if (!expand().containsKey(key)) { return;//from ww w . jav a 2s.c o m } final Options expandOptions = expand().get(key, Options.class); final boolean direct = checkDirect(expandOptions); final Multimap<String, String> ancestorsByDescendant = TreeMultimap.create(); final LongToStringFunction toString = new LongToStringFunction(); for (SnomedConcept concept : results) { final long[] parentIds = stated ? concept.getStatedParentIds() : concept.getParentIds(); if (parentIds != null) { for (long parent : parentIds) { if (IComponent.ROOT_IDL != parent) { ancestorsByDescendant.put(concept.getId(), toString.apply(parent)); } } } if (!direct) { final long[] ancestorIds = stated ? concept.getStatedAncestorIds() : concept.getAncestorIds(); if (ancestorIds != null) { for (long ancestor : ancestorIds) { if (IComponent.ROOT_IDL != ancestor) { ancestorsByDescendant.put(concept.getId(), toString.apply(ancestor)); } } } } } final int limit = getLimit(expandOptions); final Collection<String> componentIds = newHashSet(ancestorsByDescendant.values()); if (limit > 0 && !componentIds.isEmpty()) { final SnomedConcepts ancestors = SnomedRequests.prepareSearchConcept().all().filterByActive(true) .filterByIds(componentIds).setLocales(locales()) .setExpand(expandOptions.get("expand", Options.class)).build().execute(context()); final Map<String, SnomedConcept> ancestorsById = newHashMap(); ancestorsById.putAll(Maps.uniqueIndex(ancestors, ID_FUNCTION)); for (SnomedConcept concept : results) { final Collection<String> ancestorIds = ancestorsByDescendant.get(concept.getId()); final List<SnomedConcept> conceptAncestors = FluentIterable.from(ancestorIds).limit(limit) .transform(Functions.forMap(ancestorsById)).toList(); final SnomedConcepts ancestorConcepts = new SnomedConcepts(conceptAncestors, null, null, limit, ancestorIds.size()); if (stated) { concept.setStatedAncestors(ancestorConcepts); } else { concept.setAncestors(ancestorConcepts); } } } else { for (SnomedConcept concept : results) { final Collection<String> ancestorIds = ancestorsByDescendant.get(concept.getId()); final SnomedConcepts ancestors = new SnomedConcepts(limit, ancestorIds.size()); if (stated) { concept.setStatedAncestors(ancestors); } else { concept.setAncestors(ancestors); } } } }
From source file:com.android.tools.idea.updater.configure.SdkUpdaterConfigPanel.java
private void loadPackages(RepositoryPackages packages) { Multimap<AndroidVersion, UpdatablePackage> platformPackages = TreeMultimap.create(); Set<UpdatablePackage> toolsPackages = Sets.newTreeSet(); for (UpdatablePackage info : packages.getConsolidatedPkgs().values()) { RepoPackage p = info.getRepresentative(); TypeDetails details = p.getTypeDetails(); if (details instanceof DetailsTypes.ApiDetailsType) { platformPackages.put(((DetailsTypes.ApiDetailsType) details).getAndroidVersion(), info); } else {// www . ja v a 2s. c om toolsPackages.add(info); } } // TODO: when should we show this? //myChannelLink.setVisible(myHasPreview && !myIncludePreview); myPlatformComponentsPanel.setPackages(platformPackages); myToolComponentsPanel.setPackages(toolsPackages); }
From source file:com.github.healthonnet.search.SynonymExpandingExtendedDismaxQParserPlugin.java
/** * Given the synonymAnalyzer, returns a list of all alternate queries expanded from the original user query. * /*from ww w. j a va 2 s .c o m*/ * @param synonymAnalyzer * @param solrParams * @return */ private List<Query> generateSynonymQueries(Analyzer synonymAnalyzer, SolrParams solrParams) { String origQuery = getQueryStringFromParser(); int queryLen = origQuery.length(); // TODO: make the token stream reusable? TokenStream tokenStream = synonymAnalyzer.tokenStream(Const.IMPOSSIBLE_FIELD_NAME, new StringReader(origQuery)); SortedSetMultimap<Integer, TextInQuery> startPosToTextsInQuery = TreeMultimap.create(); boolean constructPhraseQueries = solrParams.getBool(Params.SYNONYMS_CONSTRUCT_PHRASES, false); boolean bag = solrParams.getBool(Params.SYNONYMS_BAG, false); List<String> synonymBag = new ArrayList<>(); try { tokenStream.reset(); while (tokenStream.incrementToken()) { CharTermAttribute term = tokenStream.getAttribute(CharTermAttribute.class); OffsetAttribute offsetAttribute = tokenStream.getAttribute(OffsetAttribute.class); TypeAttribute typeAttribute = tokenStream.getAttribute(TypeAttribute.class); if (!typeAttribute.type().equals("shingle")) { // ignore shingles; we only care about synonyms and the original text // TODO: filter other types as well String termToAdd = term.toString(); if (typeAttribute.type().equals("SYNONYM")) { synonymBag.add(termToAdd); } // Don't quote sibgle term term synonyms if (constructPhraseQueries && typeAttribute.type().equals("SYNONYM") && termToAdd.contains(" ")) { // Don't Quote when original is already surrounded by quotes if (offsetAttribute.startOffset() == 0 || offsetAttribute.endOffset() == queryLen || origQuery.charAt(offsetAttribute.startOffset() - 1) != '"' || origQuery.charAt(offsetAttribute.endOffset()) != '"') { // make a phrase out of the synonym termToAdd = new StringBuilder(termToAdd).insert(0, '"').append('"').toString(); } } if (!bag) { // create a graph of all possible synonym combinations, // e.g. dog bite, hound bite, dog nibble, hound nibble, etc. TextInQuery textInQuery = new TextInQuery(termToAdd, offsetAttribute.startOffset(), offsetAttribute.endOffset()); startPosToTextsInQuery.put(offsetAttribute.startOffset(), textInQuery); } } } tokenStream.end(); } catch (IOException e) { throw new RuntimeException("uncaught exception in synonym processing", e); } finally { try { tokenStream.close(); } catch (IOException e) { throw new RuntimeException("uncaught exception in synonym processing", e); } } List<String> alternateQueries = synonymBag; if (!bag) { // use a graph rather than a bag List<List<TextInQuery>> sortedTextsInQuery = new ArrayList<>(startPosToTextsInQuery.values().size()); sortedTextsInQuery.addAll(startPosToTextsInQuery.asMap().values().stream().map(ArrayList::new) .collect(Collectors.toList())); // have to use the start positions and end positions to figure out all possible combinations alternateQueries = buildUpAlternateQueries(solrParams, sortedTextsInQuery); } // save for debugging purposes expandedSynonyms = alternateQueries; return createSynonymQueries(solrParams, alternateQueries); }
From source file:org.commoncrawl.util.CompressedURLFPList.java
public static void validateURLFPFlagSerializationOneSubDomain() { TreeMultimap<Integer, URLFP> sourceMap = TreeMultimap.create(); TreeMultimap<Integer, URLFP> destMap = TreeMultimap.create(); ;/*from w ww. j a v a2 s.c o m*/ ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); Builder firstBuilder = new Builder(FLAG_ARCHIVE_SEGMENT_ID | FLAG_SERIALIZE_URLFP_FLAGS); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "0", 1, 255); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "1", 2, 255); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "2", 3, 255); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "3", 4, 0); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "4", 5, 0); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "5", 6, 0); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "6", 7, 255); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "7", 8, 255); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "8", 9, 255); addMapToBuilder(firstBuilder, sourceMap); try { // flush to byte stream ... firstBuilder.flush(byteStream); // now set up to read the stream ByteArrayInputStream inputStream = new ByteArrayInputStream(byteStream.toByteArray(), 0, byteStream.size()); Reader reader = new Reader(inputStream); while (reader.hasNext()) { URLFP fp = reader.next(); destMap.put(fp.getRootDomainHash(), fp); } reader.close(); Assert.assertTrue(sourceMap.equals(destMap)); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.commoncrawl.util.CompressedURLFPListV2.java
public static void validateURLFPFlagSerializationOneSubDomain() { TreeMultimap<Long, URLFPV2> sourceMap = TreeMultimap.create(); TreeMultimap<Long, URLFPV2> destMap = TreeMultimap.create(); ;/*from w w w . j av a 2 s. com*/ ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); Builder firstBuilder = new Builder(FLAG_ARCHIVE_SEGMENT_ID | FLAG_SERIALIZE_URLFP_FLAGS); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "0", 1, 255); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "1", 2, 255); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "2", 3, 255); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "3", 4, 0); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "4", 5, 0); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "5", 6, 0); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "6", 7, 255); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "7", 8, 255); insertURLFPItem(sourceMap, DOMAIN_1_SUBDOMAIN_1_URL_1 + "8", 9, 255); addMapToBuilder(firstBuilder, sourceMap); try { // flush to byte stream ... firstBuilder.flush(byteStream); // now set up to read the stream ByteArrayInputStream inputStream = new ByteArrayInputStream(byteStream.toByteArray(), 0, byteStream.size()); Reader reader = new Reader(inputStream); while (reader.hasNext()) { URLFPV2 fp = reader.next(); destMap.put(fp.getRootDomainHash(), fp); } reader.close(); Assert.assertTrue(sourceMap.equals(destMap)); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.commoncrawl.util.CompressedURLFPList.java
public static void validateURLFPFlagSerializationRootDomain() { TreeMultimap<Integer, URLFP> sourceMap = TreeMultimap.create(); TreeMultimap<Integer, URLFP> destMap = TreeMultimap.create(); ;// ww w. j a v a 2 s . c om ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); Builder firstBuilder = new Builder(FLAG_ARCHIVE_SEGMENT_ID | FLAG_SERIALIZE_URLFP_FLAGS); for (int i = 0; i < 12; ++i) { insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "0_" + i, 1, (255 | (65535 << 16))); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "1_" + i, 2, (255 | (65535 << 16))); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "2_" + i, 3, (255 | (65535 << 16))); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "3_" + i, 4, 0); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "4_" + i, 5, 0); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "5_" + i, 6, 0); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "6_" + i, 7, (255 | (65535 << 16))); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "7_" + i, 8, 255); } insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "8", 8, 255); addMapToBuilder(firstBuilder, sourceMap); try { // flush to byte stream ... firstBuilder.flush(byteStream); // now set up to read the stream ByteArrayInputStream inputStream = new ByteArrayInputStream(byteStream.toByteArray(), 0, byteStream.size()); Reader reader = new Reader(inputStream); while (reader.hasNext()) { URLFP fp = reader.next(); destMap.put(fp.getRootDomainHash(), fp); } reader.close(); Assert.assertTrue(sourceMap.equals(destMap)); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.commoncrawl.util.CompressedURLFPListV2.java
public static void validateURLFPFlagSerializationRootDomain() { TreeMultimap<Long, URLFPV2> sourceMap = TreeMultimap.create(); TreeMultimap<Long, URLFPV2> destMap = TreeMultimap.create(); ;/*from w w w . ja v a 2 s . c o m*/ ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); Builder firstBuilder = new Builder(FLAG_ARCHIVE_SEGMENT_ID | FLAG_SERIALIZE_URLFP_FLAGS); for (int i = 0; i < 12; ++i) { insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "0_" + i, 1, (255 | (65535 << 16))); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "1_" + i, 2, (255 | (65535 << 16))); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "2_" + i, 3, (255 | (65535 << 16))); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "3_" + i, 4, 0); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "4_" + i, 5, 0); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "5_" + i, 6, 0); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "6_" + i, 7, (255 | (65535 << 16))); insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "7_" + i, 8, 255); } insertURLFPItem(sourceMap, DOMAIN_2_SUBDOMAIN_1_URL_1 + "8", 8, 255); addMapToBuilder(firstBuilder, sourceMap); try { // flush to byte stream ... firstBuilder.flush(byteStream); // now set up to read the stream ByteArrayInputStream inputStream = new ByteArrayInputStream(byteStream.toByteArray(), 0, byteStream.size()); Reader reader = new Reader(inputStream); while (reader.hasNext()) { URLFPV2 fp = reader.next(); destMap.put(fp.getRootDomainHash(), fp); } reader.close(); Assert.assertTrue(sourceMap.equals(destMap)); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.commoncrawl.util.CompressedURLFPList.java
public static void validateURLFPFlagSerializationMultipleSubDomains() { TreeMultimap<Integer, URLFP> sourceMap = TreeMultimap.create(); TreeMultimap<Integer, URLFP> destMap = TreeMultimap.create(); ;/*w ww . j a v a2s.c om*/ ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); Builder firstBuilder = new Builder(FLAG_ARCHIVE_SEGMENT_ID | FLAG_SERIALIZE_URLFP_FLAGS); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_1_URL_1 + "0", 1, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_2_URL_1 + "1", 2, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_1_URL_1 + "2", 3, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_2_URL_1 + "3", 4, 0); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_1_URL_1 + "4", 1, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_2_URL_1 + "5", 2, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_1_URL_1 + "6", 3, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_2_URL_1 + "7", 4, 0); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_1_URL_1 + "8", 1, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_2_URL_1 + "9", 2, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_1_URL_1 + "10", 3, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_2_URL_1 + "11", 4, 0); addMapToBuilder(firstBuilder, sourceMap); try { // flush to byte stream ... firstBuilder.flush(byteStream); // now set up to read the stream ByteArrayInputStream inputStream = new ByteArrayInputStream(byteStream.toByteArray(), 0, byteStream.size()); Reader reader = new Reader(inputStream); while (reader.hasNext()) { URLFP fp = reader.next(); destMap.put(fp.getRootDomainHash(), fp); } reader.close(); Assert.assertTrue(sourceMap.equals(destMap)); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.commoncrawl.util.CompressedURLFPListV2.java
public static void validateURLFPFlagSerializationMultipleSubDomains() { TreeMultimap<Long, URLFPV2> sourceMap = TreeMultimap.create(); TreeMultimap<Long, URLFPV2> destMap = TreeMultimap.create(); ;/* w w w . ja va2 s . c om*/ ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); Builder firstBuilder = new Builder(FLAG_ARCHIVE_SEGMENT_ID | FLAG_SERIALIZE_URLFP_FLAGS); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_1_URL_1 + "0", 1, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_2_URL_1 + "1", 2, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_1_URL_1 + "2", 3, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_2_URL_1 + "3", 4, 0); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_1_URL_1 + "4", 1, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_2_URL_1 + "5", 2, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_1_URL_1 + "6", 3, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_2_URL_1 + "7", 4, 0); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_1_URL_1 + "8", 1, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_2_URL_1 + "9", 2, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_1_URL_1 + "10", 3, 255); insertURLFPItem(sourceMap, DOMAIN_3_SUBDOMAIN_2_URL_1 + "11", 4, 0); addMapToBuilder(firstBuilder, sourceMap); try { // flush to byte stream ... firstBuilder.flush(byteStream); // now set up to read the stream ByteArrayInputStream inputStream = new ByteArrayInputStream(byteStream.toByteArray(), 0, byteStream.size()); Reader reader = new Reader(inputStream); while (reader.hasNext()) { URLFPV2 fp = reader.next(); destMap.put(fp.getRootDomainHash(), fp); } reader.close(); Assert.assertTrue(sourceMap.equals(destMap)); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.zimbra.cs.account.accesscontrol.RightManager.java
/** * generates two files in the output directory * * {right}-expanded.xml: the root combo right fully expanded * {right}-ui.xml: all UI covered by the root combo right * * @param outputDir/* w w w. j a v a 2 s . c om*/ * @throws ServiceException * @throws IOException */ private void genAdminDocs(String outputDir) throws ServiceException, IOException { if (!outputDir.endsWith("/")) { outputDir = outputDir + "/"; } List<AdminRight> rootRights = ImmutableList.of(Admin.R_adminConsoleRights); for (AdminRight right : rootRights) { Multimap<UI, Right> uiMap = TreeMultimap.create(); /* * output the rights XML. This XML has the root combo right expanded * down to each atom(preset or attrs) right */ Document document = DocumentHelper.createDocument(); Element rightsRoot = document.addElement(E_ROOT); genAdminDocByRight(rightsRoot, right, uiMap); writeXML(outputDir + right.getName() + "-expanded.xml", document); /* * output the UI XML. This XML contains one entry for each UI, sorted by * the description of the UI. */ document = DocumentHelper.createDocument(); Element uiRoot = document.addElement(E_ROOT); genAdminDocByUI(uiRoot, uiMap); writeXML(outputDir + right.getName() + "-ui.xml", document); } }