List of usage examples for com.google.common.collect Maps immutableEntry
@GwtCompatible(serializable = true) public static <K, V> Entry<K, V> immutableEntry(@Nullable K key, @Nullable V value)
From source file:com.mind_era.knime_rapidminer.knime.nodes.util.KnimeExampleSet.java
/** * @param entry//from ww w . ja v a 2 s .c o m * @return A new NominalMapping. */ private NominalMapping createPolynomialMapping(final Entry<DataColumnSpec, Integer> entry) { return new PolynominalMapping( MapHelper.<Integer, String>newHashMap(Iterables.transform(mapping.get(entry.getValue()).entrySet(), new Function<Entry<String, Double>, Entry<Integer, String>>() { @Override public Entry<Integer, String> apply(final Entry<String, Double> input) { return Maps.immutableEntry(Integer.valueOf(entry.getValue().intValue()), input.getKey()); } }))); }
From source file:me.lucko.luckperms.common.commands.utils.Util.java
public static Map.Entry<FancyMessage, String> permNodesToMessage(SortedSet<LocalizedNode> nodes, PermissionHolder holder, String label, int pageNumber) { List<Node> l = new ArrayList<>(); for (Node node : nodes) { if (!node.isTemporary()) { l.add(node);/* w w w. ja va 2 s . c o m*/ } } if (l.isEmpty()) { return Maps.immutableEntry(new FancyMessage("None").color(ChatColor.getByChar('3')), null); } int index = pageNumber - 1; List<List<Node>> pages = divideList(l, 15); if ((index < 0 || index >= pages.size())) { pageNumber = 1; index = 0; } List<Node> page = pages.get(index); FancyMessage message = new FancyMessage(""); String title = "&7(showing page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + nodes.size() + "&7 entries)"; for (Node node : page) { message = makeFancy(holder, label, node, message.then("> ").color(ChatColor.getByChar('3'))); message = makeFancy(holder, label, node, message.then(Util.color(node.getPermission())) .color(node.getValue() ? ChatColor.getByChar('a') : ChatColor.getByChar('c'))); message = appendNodeContextDescription(node, message); message = message.then("\n"); } return Maps.immutableEntry(message, title); }
From source file:org.graylog2.inputs.InputServiceImpl.java
@Override public List<Map.Entry<String, String>> getStaticFields(Input input) { if (input.getFields().get(InputImpl.EMBEDDED_STATIC_FIELDS) == null) { return Collections.emptyList(); }//from ww w . j ava 2 s . c om final ImmutableList.Builder<Map.Entry<String, String>> listBuilder = ImmutableList.builder(); final BasicDBList mSF = (BasicDBList) input.getFields().get(InputImpl.EMBEDDED_STATIC_FIELDS); for (final Object element : mSF) { final DBObject ex = (BasicDBObject) element; try { final Map.Entry<String, String> staticField = Maps.immutableEntry( (String) ex.get(InputImpl.FIELD_STATIC_FIELD_KEY), (String) ex.get(InputImpl.FIELD_STATIC_FIELD_VALUE)); listBuilder.add(staticField); } catch (Exception e) { LOG.error("Cannot build static field from persisted data. Skipping.", e); } } return listBuilder.build(); }
From source file:org.apache.accumulo.tserver.session.SessionManager.java
public synchronized Map<String, MapCounter<ScanRunState>> getActiveScansPerTable() { Map<String, MapCounter<ScanRunState>> counts = new HashMap<String, MapCounter<ScanRunState>>(); Set<Entry<Long, Session>> copiedIdleSessions = new HashSet<Entry<Long, Session>>(); synchronized (idleSessions) { /**//from w w w. j a va2s . c om * Add sessions so that get the list returned in the active scans call */ for (Session session : idleSessions) { copiedIdleSessions.add(Maps.immutableEntry(expiredSessionMarker, session)); } } for (Entry<Long, Session> entry : sessions.entrySet()) { Session session = entry.getValue(); @SuppressWarnings("rawtypes") ScanTask nbt = null; String tableID = null; if (session instanceof ScanSession) { ScanSession ss = (ScanSession) session; nbt = ss.nextBatchTask; tableID = ss.extent.getTableId(); } else if (session instanceof MultiScanSession) { MultiScanSession mss = (MultiScanSession) session; nbt = mss.lookupTask; tableID = mss.threadPoolExtent.getTableId(); } if (nbt == null) continue; ScanRunState srs = nbt.getScanRunState(); if (srs == ScanRunState.FINISHED) continue; MapCounter<ScanRunState> stateCounts = counts.get(tableID); if (stateCounts == null) { stateCounts = new MapCounter<ScanRunState>(); counts.put(tableID, stateCounts); } stateCounts.increment(srs, 1); } return counts; }
From source file:org.onosproject.store.primitives.resources.impl.AtomixConsistentTreeMapService.java
private Map.Entry<String, Versioned<byte[]>> toVersionedEntry(Map.Entry<String, MapEntryValue> entry) { return entry == null || valueIsNull(entry.getValue()) ? null : Maps.immutableEntry(entry.getKey(), toVersioned(entry.getValue())); }
From source file:com.doctusoft.bean.binding.observable.ObservableMap.java
@Override public Set<Entry<K, V>> entrySet() { if (entrySet == null) { entrySet = new ObservableSet<Entry<K, V>>(delegate.entrySet()); entrySet.addDeleteListener(new SetElementRemovedListener<Entry<K, V>>() { @Override//from w ww . ja v a 2s . c om public void removed(ObservableSet<Entry<K, V>> set, Entry<K, V> element) { remove(element.getKey()); } }); // the entrySet doesn't support adding elements either addInsertListener(new MapElementInsertedListener<K, V>() { @Override public void inserted(ObservableMap<K, V> map, K key, V element) { entrySet.add(Maps.immutableEntry(key, element)); } }); addDeleteListener(new MapElementRemovedListener<K, V>() { @Override public void removed(ObservableMap<K, V> map, K key, V element) { entrySet.remove(Maps.immutableEntry(key, element)); } }); } return entrySet; }
From source file:org.onosproject.store.primitives.resources.impl.AtomixConsistentMapState.java
/** * Handles a entry set commit.//from w w w .j a va2 s .c o m * * @param commit * entrySet commit * @return set of map entries */ protected Set<Map.Entry<String, Versioned<byte[]>>> entrySet(Commit<? extends EntrySet> commit) { try { return mapEntries.entrySet().stream() .map(e -> Maps.immutableEntry(e.getKey(), toVersioned(e.getValue()))) .collect(Collectors.toSet()); } finally { commit.close(); } }
From source file:omero.cmd.graphs.Chown2I.java
@Override public Object step(int step) throws Cancel { helper.assertStep(step);/*from w ww.j av a2 s . c o m*/ try { switch (step) { case 0: /* if targetObjects were an IObjectList then this would need IceMapper.reverse */ final SetMultimap<String, Long> targetMultimap = HashMultimap.create(); for (final Entry<String, List<Long>> oneClassToTarget : targetObjects.entrySet()) { /* determine actual class from given target object class name */ String targetObjectClassName = oneClassToTarget.getKey(); final int lastDot = targetObjectClassName.lastIndexOf('.'); if (lastDot > 0) { targetObjectClassName = targetObjectClassName.substring(lastDot + 1); } final Class<? extends IObject> targetObjectClass = graphPathBean .getClassForSimpleName(targetObjectClassName); /* check that it is legal to target the given class */ final Iterator<Class<? extends IObject>> legalTargetsIterator = targetClasses.iterator(); do { if (!legalTargetsIterator.hasNext()) { final Exception e = new IllegalArgumentException( "cannot target " + targetObjectClassName); throw helper.cancel(new ERR(), e, "bad-target"); } } while (!legalTargetsIterator.next().isAssignableFrom(targetObjectClass)); /* note IDs to target for the class */ final Collection<Long> ids = oneClassToTarget.getValue(); targetMultimap.putAll(targetObjectClass.getName(), ids); targetObjectCount += ids.size(); } final Entry<SetMultimap<String, Long>, SetMultimap<String, Long>> plan = graphTraversal .planOperation(helper.getSession(), targetMultimap, true, true); return Maps.immutableEntry(plan.getKey(), GraphUtil.arrangeDeletionTargets(helper.getSession(), plan.getValue())); case 1: graphTraversal.assertNoPolicyViolations(); return null; case 2: processor = graphTraversal.processTargets(); return null; case 3: unlinker = graphTraversal.unlinkTargets(false); graphTraversal = null; return null; case 4: unlinker.execute(); return null; case 5: processor.execute(); return null; default: final Exception e = new IllegalArgumentException( "model object graph operation has no step " + step); throw helper.cancel(new ERR(), e, "bad-step"); } } catch (Cancel c) { throw c; } catch (GraphException ge) { final omero.cmd.GraphException graphERR = new omero.cmd.GraphException(); graphERR.message = ge.message; throw helper.cancel(graphERR, ge, "graph-fail"); } catch (Throwable t) { throw helper.cancel(new ERR(), t, "graph-fail"); } }
From source file:omero.cmd.graphs.Chgrp2I.java
@Override public Object step(int step) throws Cancel { helper.assertStep(step);/* ww w . j a v a 2s. co m*/ try { switch (step) { case 0: /* if targetObjects were an IObjectList then this would need IceMapper.reverse */ final SetMultimap<String, Long> targetMultimap = HashMultimap.create(); for (final Entry<String, List<Long>> oneClassToTarget : targetObjects.entrySet()) { /* determine actual class from given target object class name */ String targetObjectClassName = oneClassToTarget.getKey(); final int lastDot = targetObjectClassName.lastIndexOf('.'); if (lastDot > 0) { targetObjectClassName = targetObjectClassName.substring(lastDot + 1); } final Class<? extends IObject> targetObjectClass = graphPathBean .getClassForSimpleName(targetObjectClassName); /* check that it is legal to target the given class */ final Iterator<Class<? extends IObject>> legalTargetsIterator = targetClasses.iterator(); do { if (!legalTargetsIterator.hasNext()) { final Exception e = new IllegalArgumentException( "cannot target " + targetObjectClassName); throw helper.cancel(new ERR(), e, "bad-target"); } } while (!legalTargetsIterator.next().isAssignableFrom(targetObjectClass)); /* note IDs to target for the class */ final Collection<Long> ids = oneClassToTarget.getValue(); targetMultimap.putAll(targetObjectClass.getName(), ids); targetObjectCount += ids.size(); } final Entry<SetMultimap<String, Long>, SetMultimap<String, Long>> plan = graphTraversal .planOperation(helper.getSession(), targetMultimap, true, true); return Maps.immutableEntry(plan.getKey(), GraphUtil.arrangeDeletionTargets(helper.getSession(), plan.getValue())); case 1: graphTraversal.assertNoPolicyViolations(); return null; case 2: processor = graphTraversal.processTargets(); return null; case 3: unlinker = graphTraversal.unlinkTargets(true); graphTraversal = null; return null; case 4: unlinker.execute(); return null; case 5: processor.execute(); return null; default: final Exception e = new IllegalArgumentException( "model object graph operation has no step " + step); throw helper.cancel(new ERR(), e, "bad-step"); } } catch (Cancel c) { throw c; } catch (GraphException ge) { final omero.cmd.GraphException graphERR = new omero.cmd.GraphException(); graphERR.message = ge.message; throw helper.cancel(graphERR, ge, "graph-fail"); } catch (Throwable t) { throw helper.cancel(new ERR(), t, "graph-fail"); } }
From source file:omero.cmd.graphs.Preprocessor.java
public Preprocessor(List<Request> requests, Helper helper) { final IQuery iQuery = helper.getServiceFactory().getQueryService(); this.hierarchyNavigator = new HierarchyNavigatorWrap<TargetType, GraphModifyTarget>(iQuery) { @Override/*from w ww .j av a 2 s .c o m*/ protected String typeToString(TargetType type) { return TargetType.byType.get(type); } @Override protected TargetType stringToType(String typeName) { return TargetType.byName.get(typeName); } @Override protected Entry<String, Long> entityToStringLong(GraphModifyTarget entity) { return Maps.immutableEntry(TargetType.byType.get(entity.targetType), entity.targetId); } @Override protected GraphModifyTarget stringLongToEntity(String typeName, long id) { return new GraphModifyTarget(TargetType.byName.get(typeName), id); } }; this.requests = requests; process(); }