List of usage examples for com.google.common.collect ListMultimap get
@Override List<V> get(@Nullable K key);
Because the values for a given key may have duplicates and follow the insertion ordering, this method returns a List , instead of the java.util.Collection specified in the Multimap interface.
From source file:exm.stc.ic.opt.DeadCodeEliminator.java
private static String printDepGraph(ListMultimap<Var, Var> dependencyGraph, int indent) { List<Var> keys = new ArrayList<Var>(dependencyGraph.keySet()); Collections.sort(keys);//from ww w .j a v a2s. c o m StringBuilder sb = new StringBuilder(); for (Var key : keys) { for (int i = 0; i < indent; i++) { sb.append(' '); } sb.append(key.name() + " => ["); ICUtil.prettyPrintVarList(sb, dependencyGraph.get(key)); sb.append("]\n"); } return sb.toString(); }
From source file:eus.ixa.ixa.pipe.convert.Convert.java
/** * Aggregates {@code POSDictionary} from a list of words and its postag. * /*from w w w . j a v a 2 s . co m*/ * @param inputLines * the list of words and postag per line * @param tagDict * the POSDictionary to which the lemma dictionary will be added */ private static void addPOSTaggerDict(List<String> inputLines, POSDictionary tagDict) { ListMultimap<String, String> dictMultiMap = ArrayListMultimap.create(); for (String line : inputLines) { String[] lineArray = line.split(" "); if (lineArray.length == 2) { dictMultiMap.put(lineArray[0], lineArray[1]); } } for (String token : dictMultiMap.keySet()) { List<String> tags = dictMultiMap.get(token); if (tags.size() == 1) { tagDict.put(token, tags.toArray(new String[tags.size()])); } } }
From source file:org.kiji.common.flags.FlagParser.java
/** * Parses the flags defined in obj out of args. Prints usage and returns null * if the flags could not be parsed. Otherwise it assigns the flag values to * the fields with @Flag declarations and returns the non-flag arguments. * * @param obj The instance of the class containing flag declarations. * @param args The command-line arguments. * @param out Where to print usage info if there is a parsing error. * @param ignoreUnknownFlags When set, unknown flags behave like non-flag arguments. * * @return The non-flag arguments, or null if the flags were not parsed. * * @throws DuplicateFlagException If there are duplicate flags. * @throws UnrecognizedFlagException When parsing a flag that was not declared. *//*from w w w . j a v a2s . c om*/ public static List<String> init(Object obj, String[] args, PrintStream out, boolean ignoreUnknownFlags) { final List<String> nonFlagArgs = new ArrayList<String>(); final Map<String, FlagSpec> declaredFlags = extractFlagDeclarations(obj); final ListMultimap<String, String> parsedFlags = parseArgs(args, nonFlagArgs, declaredFlags, ignoreUnknownFlags); if (parsedFlags.containsKey("help") && !declaredFlags.containsKey("help")) { printUsage(declaredFlags, out); return null; } try { // Always walk through all command-line flags: for (Map.Entry<String, FlagSpec> entry : declaredFlags.entrySet()) { final String flagName = entry.getKey(); final FlagSpec spec = entry.getValue(); final List<String> values = parsedFlags.get(flagName); if (!values.isEmpty()) { // Flag is specified once or more on the command-line: spec.setValue(values); } else if (!spec.getEnvVar().isEmpty()) { final String envVal = System.getenv(spec.getEnvVar()); if (null != envVal) { // Flag is not specified on the command-line but is set through environment variable: spec.setValue(Lists.newArrayList(envVal)); } } else { // Flag is not specified on the command-line: spec.setValue(Collections.<String>emptyList()); } } } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } return nonFlagArgs; }
From source file:com.zimbra.cs.dav.resource.AddressObject.java
private static void constructContactGroupFromAppleXProps(DavContext ctxt, Account ownerAccount, VCard vcard, Contact existingContact, int folderId) { ListMultimap<String, VCardParamsAndValue> xprops = Contact .decodeUnknownVCardProps(vcard.fields.get(ContactConstants.A_vCardXProps)); String kind = VCardParamsAndValue.getFirstValue(XABSKIND, xprops); if (kind != null && kind.compareTo("group") == 0) { ContactGroup contactGroup;/*from www. j a va 2 s.c o m*/ List<VCardParamsAndValue> xabsmembers = xprops.get(XABSMEMBER); try { if (existingContact == null) { // create contactGroup = ContactGroup.init(); } else { // modify contactGroup = ContactGroup.init(existingContact, true); // remove all the contacts of type CONTACT_REF that belong to the collection same as the group ArrayList<Member> membersToRemove = new ArrayList<Member>(); for (Member member : contactGroup.getMembers()) { if (Member.Type.CONTACT_REF.equals(member.getType())) { ItemId itemId = new ItemId(member.getValue(), existingContact.getAccount().getId()); if (itemId.belongsTo(existingContact.getAccount())) { // make sure member belongs to the same collection as the group. Contact c = getContactByUID(ctxt, itemId.toString(), existingContact.getAccount(), folderId); if (c != null) { membersToRemove.add(member); } } } } for (Member member : membersToRemove) { contactGroup.removeMember(member.getType(), member.getValue()); } } for (VCardParamsAndValue memberProp : xabsmembers) { String member = memberProp.getValue(); if (member.startsWith("urn:uuid:")) { member = member.substring(9); } Contact c = getContactByUID(ctxt, member, ownerAccount, folderId); if (c != null) { // add to the group as a CONTACT_REF ItemId itemId = new ItemId(c); contactGroup.addMember(Member.Type.CONTACT_REF, itemId.toString()); } } vcard.fields.put(ContactConstants.A_type, ContactConstants.TYPE_GROUP); vcard.fields.put(ContactConstants.A_groupMember, contactGroup.encode()); // remove the Apple x-props and preserve the rest. xprops.removeAll(XABSKIND); xprops.removeAll(XABSMEMBER); vcard.fields.put(ContactConstants.A_vCardXProps, Contact.encodeUnknownVCardProps(xprops)); } catch (ServiceException e) { ZimbraLog.dav.debug("can't parse xprop %s", xabsmembers, e); } } }
From source file:org.caleydo.data.importer.tcga.model.ClinicalMapping.java
private static Collection<ClinicalMapping> readAll(String fileName, ListMultimap<String, CategoryProperty<String>> properties) { try (InputStreamReader r = new InputStreamReader( ClinicalMapping.class.getResourceAsStream("/resources/" + fileName))) { List<String> lines = CharStreams.readLines(r); lines.remove(0);// w ww . j a v a2 s. co m Collection<ClinicalMapping> result = new ArrayList<>(); for (String line : lines) { String[] ls = line.split("\t"); ClinicalMapping mapping = new ClinicalMapping(ls[0], ls[1], EDataClass.valueOf(ls[2].toUpperCase()), EDataType.valueOf(ls[3]), Arrays.copyOfRange(ls, 4, ls.length), properties.get(ls[0])); result.add(mapping); } return result; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return Collections.emptyList(); } }
From source file:eus.ixa.ixa.pipe.convert.Convert.java
/** * Generates {@code POSDictionary} from a list of monosemic words and its * postag. form\tab\lemma\tabpostag/*from w ww.jav a 2 s . c om*/ * * @param inputLines * the list of words and postag per line * @return the POSDictionary */ private static POSDictionary getPOSTaggerDict(List<String> inputLines) { POSDictionary posTaggerDict = new POSDictionary(); ListMultimap<String, String> dictMultiMap = ArrayListMultimap.create(); for (String line : inputLines) { String[] lineArray = line.split("\t"); if (lineArray.length == 3) { if (!lineArray[0].contains("<")) { dictMultiMap.put(lineArray[0], lineArray[2]); } } } for (String token : dictMultiMap.keySet()) { List<String> tags = dictMultiMap.get(token); // add only monosemic words if (tags.size() == 1) { posTaggerDict.put(token, tags.toArray(new String[tags.size()])); } } return posTaggerDict; }
From source file:be.fedict.dcat.datagovbe.Drupal.java
/** * Get multiple values from map structure. * //from www . java 2 s. c om * @param map * @param prop * @param lang * @return */ private static List<String> getMany(Map<IRI, ListMultimap<String, String>> map, IRI prop, String lang) { List<String> res = new ArrayList<>(); ListMultimap<String, String> multi = map.get(prop); if (multi != null && !multi.isEmpty()) { List<String> list = multi.get(lang); if (list != null && !list.isEmpty()) { res = list; } } return res; }
From source file:be.fedict.dcat.datagovbe.Drupal.java
/** * Get one value from map structure./*from w ww .j ava2s . c o m*/ * * @param map * @param prop * @param lang * @return */ private static String getOne(Map<IRI, ListMultimap<String, String>> map, IRI prop, String lang) { String res = ""; ListMultimap<String, String> multi = map.get(prop); if (multi != null && !multi.isEmpty()) { List<String> list = multi.get(lang); if (list != null && !list.isEmpty()) { res = list.get(0); } } return res; }
From source file:org.eclipse.sw360.datahandler.common.CommonUtils.java
@NotNull public static Map<String, List<String>> getIdentifierToListOfDuplicates( ListMultimap<String, String> identifierToIds) { Map<String, List<String>> output = new HashMap<>(); for (String identifier : identifierToIds.keySet()) { List<String> ids = identifierToIds.get(identifier); if (ids.size() > 1) { output.put(identifier, ids); }// w w w. j a v a2s. co m } return output; }
From source file:org.nmdp.ngs.variant.vcf.StreamingVcfParser.java
/** * Stream the specified readable.//from w w w. j a v a 2s.c o m * * @param readable readable, must not be null * @param listener event based reader callback, must not be null * @throws IOException if an I/O error occurs */ public static void stream(final Readable readable, final VcfStreamListener listener) throws IOException { checkNotNull(readable); checkNotNull(listener); VcfParser.parse(readable, new VcfParseAdapter() { /** VCF record builder. */ private final VcfRecord.Builder builder = VcfRecord.builder(); /** File format, e.g. <code>VCFv4.2</code>, the only required header field. */ private String fileFormat; /** List of meta-information header lines. */ private List<String> meta = new ArrayList<String>(); /** VCF samples keyed by name. */ private Map<String, VcfSample> samples = new HashMap<String, VcfSample>(); @Override public void lineNumber(final long lineNumber) throws IOException { builder.withLineNumber(lineNumber); } @Override public void meta(final String meta) throws IOException { this.meta.add(meta.trim()); if (meta.startsWith("##fileformat=")) { fileFormat = meta.substring(13).trim(); } else if (meta.startsWith("##SAMPLE=")) { ListMultimap<String, String> values = ArrayListMultimap.create(); String[] tokens = meta.substring(10).split(","); for (String token : tokens) { String[] metaTokens = token.split("="); String key = metaTokens[0]; String[] valueTokens = metaTokens[1].split(";"); for (String valueToken : valueTokens) { values.put(key, valueToken.replace("\"", "").replace(">", "")); } } String id = values.get("ID").get(0); List<String> genomeIds = values.get("Genomes"); List<String> mixtures = values.get("Mixture"); List<String> descriptions = values.get("Description"); List<VcfGenome> genomes = new ArrayList<VcfGenome>(genomeIds.size()); for (int i = 0, size = genomeIds.size(); i < size; i++) { genomes.add(new VcfGenome(genomeIds.get(i), Double.parseDouble(mixtures.get(i)), descriptions.get(i))); } samples.put(id, new VcfSample(id, genomes.toArray(new VcfGenome[0]))); } } @Override public void samples(final String... samples) throws IOException { for (String sample : samples) { // add if missing in meta lines if (!this.samples.containsKey(sample)) { this.samples.put(sample, new VcfSample(sample, new VcfGenome[0])); } } // at end of header lines, notify listener of header listener.header(new VcfHeader(fileFormat, meta)); // ...and samples for (VcfSample sample : this.samples.values()) { listener.sample(sample); } } @Override public void chrom(final String chrom) throws IOException { builder.withChrom(chrom); } @Override public void pos(final long pos) throws IOException { builder.withPos(pos); } @Override public void id(final String... id) throws IOException { builder.withId(id); } @Override public void ref(final String ref) throws IOException { builder.withRef(ref); } @Override public void alt(final String... alt) throws IOException { builder.withAlt(alt); } @Override public void qual(final double qual) throws IOException { builder.withQual(qual); } @Override public void filter(final String... filter) throws IOException { builder.withFilter(filter); } @Override public void info(final String infoId, final String... values) throws IOException { builder.withInfo(infoId, values); } @Override public void format(final String... format) throws IOException { builder.withFormat(format); } @Override public void genotype(final String sampleId, final String formatId, final String... values) throws IOException { builder.withGenotype(sampleId, formatId, values); } @Override public boolean complete() throws IOException { listener.record(builder.build()); builder.reset(); fileFormat = null; meta = null; samples = null; return true; } }); }