public Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> suggestCanvasUpdatedVisualizationLayerInfoForNewDesign(Set<NetworkLayer> newNetworkLayers) { final Map<NetworkLayer, Boolean> oldLayerVisibilityMap = getCanvasLayerVisibilityMap(); final BidiMap<NetworkLayer, Integer> oldLayerOrderMap = new DualHashBidiMap<>(getCanvasLayerOrderIndexMap(true)); final Map<NetworkLayer, Boolean> newLayerVisibilityMap = new HashMap<>(); final BidiMap<NetworkLayer, Integer> newLayerOrderMap = new DualHashBidiMap<>(); for (int oldVisibilityOrderIndex = 0; oldVisibilityOrderIndex < oldLayerOrderMap.size(); oldVisibilityOrderIndex++) { final NetworkLayer oldLayer = oldLayerOrderMap.inverseBidiMap().get(oldVisibilityOrderIndex); if (newNetworkLayers.contains(oldLayer)) { newLayerOrderMap.put(oldLayer, newLayerVisibilityMap.size()); newLayerVisibilityMap.put(oldLayer, oldLayerVisibilityMap.get(oldLayer)); } } final Set<NetworkLayer> newLayersNotExistingBefore = Sets.difference(newNetworkLayers, oldLayerVisibilityMap.keySet()); for (NetworkLayer newLayer : newLayersNotExistingBefore) { newLayerOrderMap.put(newLayer, newLayerVisibilityMap.size()); newLayerVisibilityMap.put(newLayer, true); // new layers always visible } return Pair.of(newLayerOrderMap, newLayerVisibilityMap); }
/** * * @param jcas a JCas created by an EOP LAP * @return A list of roots, each belonging to a BIU dependency parse tree of a sentence in the CAS. Trees are ordered by sentence order. * @throws CasTreeConverterException * @throws UnsupportedPosTagStringException */ public List<BasicNode> convertCasToTrees(JCas jcas) throws CasTreeConverterException, UnsupportedPosTagStringException { Collection<Sentence> sentenceAnnotations = JCasUtil.select(jcas, Sentence.class); lastSentenceList = new ArrayList<Sentence>(sentenceAnnotations); lastTokenToNodeBySentence = new LinkedHashMap<Sentence, OneToManyBidiMultiHashMap<Token,BasicNode>>(); lastRootList = new ArrayList<BasicNode>(sentenceAnnotations.size()); lastSentenceToRoot = new DualHashBidiMap<>(); for (Sentence sentenceAnno : lastSentenceList) { BasicNode root = convertSentenceToTree(jcas, sentenceAnno); lastSentenceToRoot.put(sentenceAnno, root); lastRootList.add(root); OneToManyBidiMultiHashMap<Token,BasicNode> tokenToNodeCopy = new OneToManyBidiMultiHashMap<Token,BasicNode>(tokenToNode); lastTokenToNodeBySentence.put(sentenceAnno, tokenToNodeCopy); } return lastRootList; }
/** * This is separate from initialize() because these data structures are shared among all * graphs loaded (i.e., they're defined inside <code>graphml</code> rather than <code>graph</code>. */ protected void initializeData() { this.vertex_ids = new DualHashBidiMap<V, String>(); this.vertex_desc = new HashMap<V, String>(); this.vertex_metadata = new HashMap<String, GraphMLMetadata<V>>(); this.edge_ids = new DualHashBidiMap<E, String>(); this.edge_desc = new HashMap<E, String>(); this.edge_metadata = new HashMap<String, GraphMLMetadata<E>>(); this.graph_desc = new HashMap<G, String>(); this.graph_metadata = new HashMap<String, GraphMLMetadata<G>>(); this.hyperedge_vertices = new ArrayList<V>(); }
/** * Return the enum aliases map. * * @return the enum aliases map */ public BidiMap<String, Class<? extends Enum<?>>> getEnumAliases() { // using the double-checked locking with volatile // @see http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html if (enumAliases == null) { synchronized (this) { if (enumAliases == null) { enumAliases = initializeEnumAliases(); } } } // Defensive copy. TODO: move to CollectionUtil as a generic factory method return new DualHashBidiMap<>(enumAliases); }
public void setCanvasLayerVisibility(final NetworkLayer layer, final boolean isVisible) { if (!this.getNetPlan().getNetworkLayers().contains(layer)) throw new RuntimeException(); BidiMap<NetworkLayer, Integer> new_layerVisiblityOrderMap = new DualHashBidiMap<>(this.visualizationSnapshot.getMapCanvasLayerVisualizationOrder()); Map<NetworkLayer, Boolean> new_layerVisibilityMap = new HashMap<>(this.visualizationSnapshot.getMapCanvasLayerVisibility()); new_layerVisibilityMap.put(layer, isVisible); setCanvasLayerVisibilityAndOrder(this.getNetPlan(), new_layerVisiblityOrderMap, new_layerVisibilityMap); }
public static Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> generateCanvasDefaultVisualizationLayerInfo(NetPlan np) { final BidiMap<NetworkLayer, Integer> res_1 = new DualHashBidiMap<>(); final Map<NetworkLayer, Boolean> res_2 = new HashMap<>(); for (NetworkLayer layer : np.getNetworkLayers()) { res_1.put(layer, res_1.size()); res_2.put(layer, true); } return Pair.of(res_1, res_2); }
public Map getMap() { Map testMap = new DualHashBidiMap(); testMap.put("A", "a"); testMap.put("B", "b"); testMap.put("C", "c"); return testMap; }
/** * Creates a <code>GraphMLReader</code> instance with the specified * vertex and edge factories. * * @param vertex_factory the vertex factory to use to create vertex objects * @param edge_factory the edge factory to use to create edge objects * @throws ParserConfigurationException * @throws SAXException */ public MyGraphMLReader(Factory<V> vertex_factory, Factory<E> edge_factory) throws ParserConfigurationException, SAXException { current_vertex = null; current_edge = null; SAXParserFactory factory = SAXParserFactory.newInstance(); saxp = factory.newSAXParser(); current_states = new LinkedList<TagState>(); tag_state = new DualHashBidiMap<String, TagState>(); tag_state.put("node", TagState.VERTEX); tag_state.put("edge", TagState.EDGE); tag_state.put("hyperedge", TagState.HYPEREDGE); tag_state.put("endpoint", TagState.ENDPOINT); tag_state.put("graph", TagState.GRAPH); tag_state.put("data", TagState.DATA); tag_state.put("key", TagState.KEY); tag_state.put("desc", TagState.DESC); tag_state.put("default", TagState.DEFAULT_KEY); tag_state.put("graphml", TagState.GRAPHML); this.key_type = KeyType.NONE; this.vertex_factory = vertex_factory; this.edge_factory = edge_factory; }
/** * Creates a <code>GraphMLReader</code> instance with the specified * vertex and edge factories. * * @param vertex_factory the vertex factory to use to create vertex objects * @param edge_factory the edge factory to use to create edge objects * @throws ParserConfigurationException * @throws SAXException */ public GraphMLReader(Factory<V> vertex_factory, Factory<E> edge_factory) throws ParserConfigurationException, SAXException { current_vertex = null; current_edge = null; SAXParserFactory factory = SAXParserFactory.newInstance(); saxp = factory.newSAXParser(); current_states = new LinkedList<TagState>(); tag_state = new DualHashBidiMap<String, TagState>(); tag_state.put("node", TagState.VERTEX); tag_state.put("edge", TagState.EDGE); tag_state.put("hyperedge", TagState.HYPEREDGE); tag_state.put("endpoint", TagState.ENDPOINT); tag_state.put("graph", TagState.GRAPH); tag_state.put("data", TagState.DATA); tag_state.put("key", TagState.KEY); tag_state.put("desc", TagState.DESC); tag_state.put("default", TagState.DEFAULT_KEY); tag_state.put("graphml", TagState.GRAPHML); this.key_type = KeyType.NONE; this.vertex_factory = vertex_factory; this.edge_factory = edge_factory; }
/** * Set the static enum alias map field. * <p> * Warning: do not call this method outside this class. It is meant to be called by * Spring when instantiating the singleton instance of this bean. */ @SuppressWarnings("unchecked") private BidiMap<String, Class<? extends Enum<?>>> initializeEnumAliases() { final Class<Alias> annotationClass = Alias.class; // TODO: move to CollectionUtil as a generic factory method final BidiMap<String, Class<? extends Enum<?>>> map = new DualHashBidiMap<>(); for (final Class<?> annotatedClass : this.getObject()) { if (annotatedClass.isEnum()) { final String alias = annotatedClass .getAnnotation(annotationClass) .value(); final Class<? extends Enum<?>> otherClass = map.get(alias); if (otherClass != null) { // This is the second time that we encountered the alias // key, signal name collision final String errorMessage = "Enum alias collision!!! Both " + otherClass + ", " + annotatedClass + " have the same alias: " + quote(alias) + ". Rename the @" + annotationClass.getSimpleName() + " annotation value one of them."; // Log message before throwing, otherwise Spring will // show an incomprehensible TargetInvocationException // without its cause here. log.error(errorMessage); throw new ApplicationException(errorMessage); } map.put(alias, (Class<? extends Enum<?>>) annotatedClass); } } return map; }
public MapIterator makeEmptyMapIterator() { return UnmodifiableMapIterator.decorate(new DualHashBidiMap().mapIterator()); }
/** * Returns a <code>BidiMap</code> mapping each element of the collection to its * index as encountered while iterating over the collection. The purpose * of the index operation is to supply an O(1) replacement operation for the * O(n) <code>indexOf(element)</code> method of a <code>List</code> * @param <T> * @param collection * @param start start index * @return a bidirectional map from collection elements to start-based indices */ public static <T> BidiMap<T,Integer> create(Collection<T> collection, int start) { BidiMap<T,Integer> map = new DualHashBidiMap<T,Integer>(); int i=start; for(T t : collection) { map.put(t,i++); } return map; }