List of usage examples for com.google.common.collect Multimap isEmpty
boolean isEmpty();
From source file:fr.ujm.tse.lt2c.satin.rules.run.RunSCM_RNG2.java
@Override protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) { final long subPropertyOf = AbstractDictionary.subPropertyOf; final long range = AbstractDictionary.range; int loops = 0; final Multimap<Long, Long> rangeMultimap = ts1.getMultiMapForPredicate(range); if (rangeMultimap != null && !rangeMultimap.isEmpty()) { final Collection<Triple> subpropertyTriples = ts2.getbyPredicate(subPropertyOf); final HashMap<Long, Collection<Long>> cachePredicates = new HashMap<>(); /* For each type triple */ for (final Triple triple : subpropertyTriples) { /*// w w w .j av a2 s . c om * Get all objects (c2) of subClassOf triples with range triples * objects as subject */ Collection<Long> cs; if (!cachePredicates.containsKey(triple.getObject())) { cs = rangeMultimap.get(triple.getObject()); cachePredicates.put(triple.getObject(), cs); } else { cs = cachePredicates.get(triple.getObject()); } loops++; for (final Long c : cs) { final Triple result = new ImmutableTriple(triple.getSubject(), range, c); outputTriples.add(result); } } } return loops; }
From source file:org.onosproject.segmentrouting.cli.McastTreeListCommand.java
@Override protected void execute() { // Get SR service and the handled mcast groups SegmentRoutingService srService = get(SegmentRoutingService.class); Set<IpAddress> mcastGroups = ImmutableSet.copyOf(srService.getMcastLeaders(null).keySet()); if (!isNullOrEmpty(gAddr)) { mcastGroups = mcastGroups.stream().filter(mcastIp -> mcastIp.equals(IpAddress.valueOf(gAddr))) .collect(Collectors.toSet()); }/*from w w w . j a v a 2 s. co m*/ ObjectMapper mapper = new ObjectMapper(); ObjectNode root = mapper.createObjectNode(); // Print the trees for each group or build json objects mcastGroups.forEach(group -> { // We want to use source cp only for a specific group ConnectPoint sourcecp = null; if (!isNullOrEmpty(source) && !isNullOrEmpty(gAddr)) { sourcecp = ConnectPoint.deviceConnectPoint(source); } Multimap<ConnectPoint, List<ConnectPoint>> mcastTree = srService.getMcastTrees(group, sourcecp); if (!mcastTree.isEmpty()) { // Build a json object for each group if (outputJson()) { root.putPOJO(group.toString(), json(mcastTree)); } else { // Banner and then the trees printMcastGroup(group); mcastTree.forEach(this::printMcastSink); } } }); // Print the json object at the end if (outputJson()) { print("%s", root); } }
From source file:fr.ujm.tse.lt2c.satin.rules.run.RunCAX_SCO.java
@Override protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) { final long subClassOf = AbstractDictionary.subClassOf; final long type = AbstractDictionary.type; int loops = 0; final Multimap<Long, Long> subclassMultimap = ts1.getMultiMapForPredicate(subClassOf); if (subclassMultimap != null && !subclassMultimap.isEmpty()) { final HashMap<Long, Collection<Long>> cachePredicates = new HashMap<>(); final Collection<Triple> types = ts2.getbyPredicate(type); for (final Triple typeTriple : types) { Collection<Long> c2s; if (!cachePredicates.containsKey(typeTriple.getObject())) { c2s = subclassMultimap.get(typeTriple.getObject()); cachePredicates.put(typeTriple.getObject(), c2s); } else { c2s = cachePredicates.get(typeTriple.getObject()); }//from ww w . j ava2 s . c om loops++; for (final Long c2 : c2s) { if (typeTriple.getSubject() >= 0) { final Triple result = new ImmutableTriple(typeTriple.getSubject(), type, c2); outputTriples.add(result); } } } } return loops; }
From source file:fr.ujm.tse.lt2c.satin.rules.run.RunSCM_DOM2.java
@Override protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) { final long subPropertyOf = AbstractDictionary.subPropertyOf; final long domain = AbstractDictionary.domain; int loops = 0; final Multimap<Long, Long> domainMultimap = ts1.getMultiMapForPredicate(domain); if (domainMultimap != null && !domainMultimap.isEmpty()) { final Collection<Triple> subpropertyTriples = ts2.getbyPredicate(subPropertyOf); final HashMap<Long, Collection<Long>> cachePredicates = new HashMap<>(); /* For each type triple */ for (final Triple triple : subpropertyTriples) { /*/*from w w w .j a v a2s . c o m*/ * Get all objects (c2) of subClassOf triples with domain * triples objects as subject */ Collection<Long> cs; if (!cachePredicates.containsKey(triple.getObject())) { cs = domainMultimap.get(triple.getObject()); cachePredicates.put(triple.getObject(), cs); } else { cs = cachePredicates.get(triple.getObject()); } loops++; for (final Long c : cs) { final Triple result = new ImmutableTriple(triple.getSubject(), domain, c); outputTriples.add(result); } } } return loops; }
From source file:org.lanternpowered.server.network.vanilla.message.processor.play.ProcessorPlayOutTabListEntries.java
@Override public void process(CodecContext context, MessagePlayOutTabListEntries message, List<Message> output) throws CodecException { final Multimap<Class<?>, Entry> entriesByType = HashMultimap.create(); for (Entry entry : message.getEntries()) { entriesByType.put(entry.getClass(), entry); }// www. j a v a 2s .co m if (entriesByType.isEmpty()) { return; } if (entriesByType.keySet().size() == 1) { output.add(message); } else { for (java.util.Map.Entry<Class<?>, Collection<Entry>> en : entriesByType.asMap().entrySet()) { output.add(new MessagePlayOutTabListEntries(en.getValue())); } } }
From source file:com.torodb.backend.BackendTransactionImpl.java
@Override public Cursor<Tuple2<Integer, KvValue<?>>> findByFieldInProjection(MetaDatabase db, MetaCollection col, MetaDocPart docPart, Multimap<MetaField, KvValue<?>> valuesMultimap) { try {/*w w w .jav a 2s . co m*/ if (valuesMultimap.isEmpty()) { return new EmptyCursor<>(); } return sqlInterface.getReadInterface().getCollectionDidsAndProjectionWithFieldsIn(dsl, db, col, docPart, valuesMultimap); } catch (SQLException ex) { throw sqlInterface.getErrorHandler().handleException(Context.FETCH, ex); } }
From source file:fr.ujm.tse.lt2c.satin.rules.run.RunSCM_RNG1.java
@Override protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) { final long range = AbstractDictionary.range; final long subClassOf = AbstractDictionary.subClassOf; int loops = 0; final Multimap<Long, Long> subclassMultimap = ts1.getMultiMapForPredicate(subClassOf); if (subclassMultimap != null && !subclassMultimap.isEmpty()) { final Collection<Triple> rangeTriples = ts2.getbyPredicate(range); final HashMap<Long, Collection<Long>> cachePredicates = new HashMap<>(); /* For each type triple */ for (final Triple triple : rangeTriples) { /*/* w w w. j a va2 s. c o m*/ * Get all objects (c2) of subClassOf triples with range triples * objects as subject */ Collection<Long> c2s; if (!cachePredicates.containsKey(triple.getObject())) { c2s = subclassMultimap.get(triple.getObject()); cachePredicates.put(triple.getObject(), c2s); } else { c2s = cachePredicates.get(triple.getObject()); } loops++; for (final Long c2 : c2s) { final Triple result = new ImmutableTriple(triple.getSubject(), range, c2); outputTriples.add(result); } } } return loops; }
From source file:fr.ujm.tse.lt2c.satin.rules.run.RunSCM_DOM1.java
@Override protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) { final long domain = AbstractDictionary.domain; final long subClassOf = AbstractDictionary.subClassOf; int loops = 0; final Multimap<Long, Long> subclassMultimap = ts1.getMultiMapForPredicate(subClassOf); if (subclassMultimap != null && !subclassMultimap.isEmpty()) { final HashMap<Long, Collection<Long>> cachePredicates = new HashMap<>(); final Collection<Triple> domainTriples = ts2.getbyPredicate(domain); /* For each type triple */ for (final Triple triple : domainTriples) { /*// w w w. j a v a 2s . c om * Get all objects (c2) of subClassOf triples with domain * triples objects as subject */ Collection<Long> c2s; if (!cachePredicates.containsKey(triple.getObject())) { c2s = subclassMultimap.get(triple.getObject()); cachePredicates.put(triple.getObject(), c2s); } else { c2s = cachePredicates.get(triple.getObject()); } loops++; for (final Long c2 : c2s) { final Triple result = new ImmutableTriple(triple.getSubject(), domain, c2); outputTriples.add(result); } } } return loops; }
From source file:com.torodb.backend.BackendTransactionImpl.java
@Override public BackendCursor findByFieldIn(MetaDatabase db, MetaCollection col, MetaDocPart docPart, Multimap<MetaField, KvValue<?>> valuesMultimap) { try {/*ww w. j a v a2 s. c o m*/ if (valuesMultimap.isEmpty()) { return new EmptyBackendCursor(); } Cursor<Integer> allDids = sqlInterface.getReadInterface().getCollectionDidsWithFieldsIn(dsl, db, col, docPart, valuesMultimap); return new LazyBackendCursor(sqlInterface, allDids, dsl, db, col); } catch (SQLException ex) { throw sqlInterface.getErrorHandler().handleException(Context.FETCH, ex); } }
From source file:co.cask.cdap.cli.command.system.SearchCommandsCommand.java
@Override public void execute(Arguments arguments, PrintStream output) throws Exception { String originalQuery = arguments.get(ArgumentName.QUERY.getName()); String queryString = originalQuery; if (!queryString.startsWith("^")) { queryString = "^.*?" + queryString; }/*from w w w. j av a 2 s . c o m*/ if (!queryString.endsWith("$")) { queryString = queryString + ".+?$"; } final String query = queryString; Predicate<Command> filter = new Predicate<Command>() { @Override public boolean apply(@Nullable Command input) { return input != null && input.getPattern().matches(query); } }; output.println(); Multimap<String, Command> categorizedCommands = categorizeCommands(commands.get(), CommandCategory.GENERAL, filter); if (categorizedCommands.isEmpty()) { output.printf("No matches found for \"%s\"", originalQuery); output.println(); } else { output.printf("Listing matches for \"%s\":", originalQuery); output.println(); output.println(); for (CommandCategory category : CommandCategory.values()) { List<Command> commandList = Lists.newArrayList(categorizedCommands.get(category.getName())); if (commandList.isEmpty()) { continue; } printCommands(output, category.getName(), commandList); } } }