@Override public void executionFinished(ThreadExecutionController controller, Object out) { try { double execTime = (System.nanoTime() - start) / 1e9; final VisualizationState vs = mainWindow.getVisualizationState(); final NetPlan netPlan = mainWindow.getDesign(); Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer,Boolean>> res = vs.suggestCanvasUpdatedVisualizationLayerInfoForNewDesign(new HashSet<> (netPlan.getNetworkLayers())); vs.setCanvasLayerVisibilityAndOrder(netPlan, res.getFirst() , res.getSecond()); mainWindow.updateVisualizationAfterNewTopology(); mainWindow.addNetPlanChange(); String outMessage = String.format("Algorithm executed successfully%nExecution time: %.3g s%nExit message: %s", execTime, out); JOptionPane.showMessageDialog(null, outMessage, "Solve design", JOptionPane.PLAIN_MESSAGE); } catch (Throwable ex) { ErrorHandling.addErrorOrException(ex, OfflineExecutionPanel.class); ErrorHandling.showErrorDialog("Error executing algorithm"); } }
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); }
private final void modifyEntrySet(BidiMap map) { // Gets first entry final Map.Entry entry = (Map.Entry) map.entrySet().iterator().next(); // Gets key and value final Object key = entry.getKey(); final Object oldValue = entry.getValue(); // Sets new value final Object newValue = "newValue"; entry.setValue(newValue); assertEquals("Modifying entrySet did not affect underlying Map.", newValue, map.get(key)); assertNull("Modifying entrySet did not affect inverse Map.", map.getKey(oldValue)); }
public void testBidiClear() { if (isRemoveSupported() == false) { try { makeFullBidiMap().clear(); fail(); } catch (UnsupportedOperationException ex) { } return; } BidiMap map = makeFullBidiMap(); map.clear(); assertTrue("Map was not cleared.", map.isEmpty()); assertTrue("Inverse map was not cleared.", map.inverseBidiMap().isEmpty()); // Tests clear on inverse map = makeFullBidiMap().inverseBidiMap(); map.clear(); assertTrue("Map was not cleared.", map.isEmpty()); assertTrue("Inverse map was not cleared.", map.inverseBidiMap().isEmpty()); }
/** * Returns a SparseDoubleMatrix2D whose entries represent the edge weights for the * edges in <code>g</code>, as specified by <code>nev</code>. * * <p>The <code>(i,j)</code> entry of the matrix returned will be equal to the sum * of the weights of the edges connecting the vertex with index <code>i</code> to * <code>j</code>. * * <p>If <code>nev</code> is <code>null</code>, then a constant edge weight of 1 is used. * * @param g * @param nev */ public static <V,E> SparseDoubleMatrix2D graphToSparseMatrix(Graph<V,E> g, Map<E,Number> nev) { if (nev == null) nev = new ConstantMap<E,Number>(1); int numVertices = g.getVertexCount(); SparseDoubleMatrix2D matrix = new SparseDoubleMatrix2D(numVertices, numVertices); BidiMap<V,Integer> indexer = Indexer.<V>create(g.getVertices()); int i=0; for(V v : g.getVertices()) { for (E e : g.getOutEdges(v)) { V w = g.getOpposite(v,e); int j = indexer.get(w); matrix.set(i, j, matrix.getQuick(i,j) + nev.get(e).doubleValue()); } i++; } return matrix; }
/** * 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 read(Graph<V,E> graph, String file, Factory<V> vf, Factory<E> ef) throws ParserConfigurationException, SAXException, IOException{ //Step 1 we make a new GraphML Reader. We want an Undirected Graph of type node and edge. GraphMLReader<Graph<V,E>, V,E> gmlr = new GraphMLReader<Graph<V,E>, V,E>(vf, ef); //Here we read in our graph. filename is our .graphml file, and graph is where we will store our graph. gmlr.load(file, graph); BidiMap<V, String> vertex_ids = gmlr.getVertexIDs(); //The vertexIDs are stored in a BidiMap. Map<String, GraphMLMetadata<V>> vertex_color = gmlr.getVertexMetadata(); //Our vertex Metadata is stored in a map. Map<String, GraphMLMetadata<E>> edge_meta = gmlr.getEdgeMetadata(); // Our edge Metadata is stored in a map. // Here we iterate through our vertices, n, and we set the value and the color of our nodes from the data we have // in the vertex_ids map and vertex_color map. for (V n : graph.getVertices()) { //n.setValue(vertex_ids.get(n)); //Set the value of the node to the vertex_id which was read in from the GraphML Reader. //n.setColor(vertex_color.get("d0").transformer.transform(n)); // Set the color, which we get from the Map vertex_color. //Let's print out the data so we can get a good understanding of what we've got going on. //System.out.println("ID: "+n.getID()+", Value: "+n.getValue()+", Color: "+n.getColor()); } // Just as we added the vertices to the graph, we add the edges as well. for (E e : graph.getEdges()) { //e.setValue(edge_meta.get("d1").transformer.transform(e)); //Set the edge's value. //System.out.println("Edge ID: "+e.getID()); } }
private void resetButton() { try { final int result = JOptionPane.showConfirmDialog(null, "Are you sure you want to reset? This will remove all unsaved data", "Reset", JOptionPane.YES_NO_OPTION); if (result != JOptionPane.YES_OPTION) return; if (inOnlineSimulationMode()) { switch (onlineSimulationPane.getSimKernel().getSimCore().getSimulationState()) { case NOT_STARTED: case STOPPED: break; default: onlineSimulationPane.getSimKernel().getSimCore().setSimulationState(SimState.STOPPED); break; } onlineSimulationPane.getSimKernel().reset(); setDesign(onlineSimulationPane.getSimKernel().getCurrentNetPlan()); } else { setDesign(new NetPlan()); //algorithmSelector.reset(); executionPane.reset(); } // reportSelector.reset(); // reportContainer.removeAll(); } catch (Throwable ex) { ErrorHandling.addErrorOrException(ex, GUINetworkDesign.class); ErrorHandling.showErrorDialog("Unable to reset"); } Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = VisualizationState.generateCanvasDefaultVisualizationLayerInfo(getDesign()); vs.setCanvasLayerVisibilityAndOrder(getDesign(), res.getFirst(), res.getSecond()); updateVisualizationAfterNewTopology(); undoRedoManager.addNetPlanChange(); }
@Override protected JMenuItem getAddOption() { JMenuItem addItem = new JMenuItem("Add " + networkElementType); addItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NetPlan netPlan = callback.getDesign(); try { netPlan.addLayer("Layer " + netPlan.getNumberOfLayers(), null, null, null, null, null); final VisualizationState vs = callback.getVisualizationState(); Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = vs.suggestCanvasUpdatedVisualizationLayerInfoForNewDesign(new HashSet<>(callback.getDesign().getNetworkLayers())); vs.setCanvasLayerVisibilityAndOrder(callback.getDesign(), res.getFirst(), res.getSecond()); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LAYER)); callback.addNetPlanChange(); } catch (Throwable ex) { ex.printStackTrace(); ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to add " + networkElementType); } } }); return addItem; }
public VisualizationState(NetPlan currentNp, BidiMap<NetworkLayer, Integer> mapLayer2VisualizationOrder, Map<NetworkLayer, Boolean> layerVisibilityMap, int maxSizePickUndoList) { this.visualizationSnapshot = new VisualizationSnapshot(currentNp); this.showInCanvasNodeNames = false; this.showInCanvasLinkLabels = false; this.showInCanvasLinksInNonActiveLayer = true; this.showInCanvasInterLayerLinks = true; this.showInCanvasNonConnectedNodes = true; this.showInCanvasLowerLayerPropagation = true; this.showInCanvasUpperLayerPropagation = true; this.showInCanvasThisLayerPropagation = true; this.whatIfAnalysisActive = false; this.nodesToHideInCanvasAsMandatedByUserInTable = new HashSet<>(); this.linksToHideInCanvasAsMandatedByUserInTable = new HashSet<>(); this.interLayerSpaceInPixels = 50; this.tableRowFilter = null; this.linkUtilizationColorThresholdList = new ArrayList<> (VisualizationConstants.DEFAULT_LINKCOLORINGUTILIZATIONTHRESHOLDS); this.linkCapacityThicknessThresholdList = new ArrayList<> (VisualizationConstants.DEFAULT_LINKTHICKNESSTHRESHPOLDS); this.linkRunoutTimeColorThresholdList = new ArrayList<> (VisualizationConstants.DEFAULT_LINKCOLORINGRUNOUTTHRESHOLDS); this.isActiveLinkUtilizationColorThresholdList = true; this.isActiveLinkRunoutTimeColorThresholdList = false; this.isActiveLinkCapacityThicknessThresholdList = true; this.linkWidthIncreaseFactorRespectToDefault = 1; this.nodeSizeFactorRespectToDefault = 1; this.pickManager = new PickManager(this); this.setCanvasLayerVisibilityAndOrder(currentNp, mapLayer2VisualizationOrder, layerVisibilityMap); }
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 BidiMap<V, K> inverseBidiMap() { if (inverse == null) { inverse = new UnmodifiableBidiMap<V, K>(getBidiMap().inverseBidiMap()); inverse.inverse = this; } return inverse; }
public void testDecorateFactory() { MapIterator it = makeFullMapIterator(); assertSame(it, UnmodifiableMapIterator.decorate(it)); it = ((BidiMap) getMap()).mapIterator(); assertTrue(it != UnmodifiableMapIterator.decorate(it)); try { UnmodifiableMapIterator.decorate(null); fail(); } catch (IllegalArgumentException ex) { } }
public BidiMap makeFullBidiMap() { BidiMap bidi = new DualHashBidiMap(); for (int i = 0; i < entries.length; i++) { bidi.put(entries[i][0], entries[i][1]); } return UnmodifiableBidiMap.decorate(bidi); }
/** * Override to create a full <code>BidiMap</code> other than the default. * * @return a full <code>BidiMap</code> implementation. */ public BidiMap makeFullBidiMap() { final BidiMap map = makeEmptyBidiMap(); for (int i = 0; i < entries.length; i++) { map.put(entries[i][0], entries[i][1]); } return map; }
public void testBidiPut() { if (isPutAddSupported() == false || isPutChangeSupported() == false) return; BidiMap map = makeEmptyBidiMap(); BidiMap inverse = map.inverseBidiMap(); assertEquals(0, map.size()); assertEquals(map.size(), inverse.size()); map.put("A", "B"); assertEquals(1, map.size()); assertEquals(map.size(), inverse.size()); assertEquals("B", map.get("A")); assertEquals("A", inverse.get("B")); map.put("A", "C"); assertEquals(1, map.size()); assertEquals(map.size(), inverse.size()); assertEquals("C", map.get("A")); assertEquals("A", inverse.get("C")); map.put("B", "C"); assertEquals(1, map.size()); assertEquals(map.size(), inverse.size()); assertEquals("C", map.get("B")); assertEquals("B", inverse.get("C")); map.put("E", "F"); assertEquals(2, map.size()); assertEquals(map.size(), inverse.size()); assertEquals("F", map.get("E")); assertEquals("E", inverse.get("F")); }
public void verifyInverse() { assertEquals(map.size(), ((BidiMap) map).inverseBidiMap().size()); Map map1 = new HashMap(map); Map map2 = new HashMap(((BidiMap) map).inverseBidiMap()); Set keys1 = map1.keySet(); Set keys2 = map2.keySet(); Collection values1 = map1.values(); Collection values2 = map2.values(); assertEquals(true, keys1.containsAll(values2)); assertEquals(true, values2.containsAll(keys1)); assertEquals(true, values1.containsAll(keys2)); assertEquals(true, keys2.containsAll(values1)); }
private final void removeByKeySet(BidiMap map, Object key, Object value) { map.keySet().remove(key); assertTrue("Key was not removed.", !map.containsKey(key)); assertTrue("Value was not removed.", !map.containsValue(value)); assertTrue("Key was not removed from inverse map.", !map.inverseBidiMap().containsValue(key)); assertTrue("Value was not removed from inverse map.", !map.inverseBidiMap().containsKey(value)); }
private final void removeByEntrySet(BidiMap map, Object key, Object value) { Map temp = new HashMap(); temp.put(key, value); map.entrySet().remove(temp.entrySet().iterator().next()); assertTrue("Key was not removed.", !map.containsKey(key)); assertTrue("Value was not removed.", !map.containsValue(value)); assertTrue("Key was not removed from inverse map.", !map.inverseBidiMap().containsValue(key)); assertTrue("Value was not removed from inverse map.", !map.inverseBidiMap().containsKey(value)); }
public BidiMap makeFullBidiMap() { SortedBidiMap bidi = new DualTreeBidiMap(); for (int i = 0; i < entries.length; i++) { bidi.put(entries[i][0], entries[i][1]); } return UnmodifiableSortedBidiMap.decorate(bidi); }
public BidiMap makeFullBidiMap() { OrderedBidiMap bidi = new TreeBidiMap(); for (int i = 0; i < entries.length; i++) { bidi.put(entries[i][0], entries[i][1]); } return UnmodifiableOrderedBidiMap.decorate(bidi); }
public BidiMap inverseBidiMap() { if (inverse == null) { inverse = new TestOrderedBidiMap((OrderedBidiMap) getBidiMap().inverseBidiMap()); inverse.inverse = this; } return inverse; }
/** * 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; }
@Override public void actionPerformed(ActionEvent e) { try { final Pair<List<Node>, Set<Demand>> filtInfo = computeFilteringNodesAndDemands(); final List<Node> filteredNodes = filtInfo.getFirst(); final Set<Demand> filteredDemands = filtInfo.getSecond(); if (filteredNodes.size() <= 1) throw new Net2PlanException("No demands are selected"); if (filteredDemands.isEmpty()) throw new Net2PlanException("No demands are selected"); boolean allCellsEditable = true; for (int row = 0; row < trafficMatrixTable.getRowCount() - 1; row++) { for (int col = 1; col < trafficMatrixTable.getColumnCount() - 1; col++) { if (row != col - 1 && !trafficMatrixTable.isCellEditable(row, col)) { allCellsEditable = false; break; } } } if (!allCellsEditable) throw new Net2PlanException("Traffic matrix modification is only possible when all the cells are editable"); DoubleMatrix2D newTraffic2D = null; if (e.getSource() == applyTrafficModelButton) newTraffic2D = new ApplyTrafficModels(filteredNodes).applyOption(cmb_trafficModelPattern.getSelectedIndex()); else if (e.getSource() == applyTrafficNormalizationButton) newTraffic2D = new ApplyTrafficNormalizationsAndAdjustments(filteredNodes, filteredDemands).applyOption(cmb_trafficNormalization.getSelectedIndex()); else throw new RuntimeException(); if (newTraffic2D == null) return; final int result = JOptionPane.showConfirmDialog(NetPlanViewTableComponent_trafficMatrix.this, "Overwrite current matrix?", "", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; final Map<Node, Integer> node2IndexInFilteredListMap = new HashMap<>(); for (int cont = 0; cont < filteredNodes.size(); cont++) node2IndexInFilteredListMap.put(filteredNodes.get(cont), cont); final List<Demand> filteredDemandList = new ArrayList<>(filteredDemands); final List<Double> demandOfferedTrafficsList = new ArrayList<>(filteredDemands.size()); for (Demand d : filteredDemandList) demandOfferedTrafficsList.add(newTraffic2D.get(node2IndexInFilteredListMap.get(d.getIngressNode()), node2IndexInFilteredListMap.get(d.getEgressNode()))); if (networkViewer.getVisualizationState().isWhatIfAnalysisActive()) { final WhatIfAnalysisPane whatIfPane = networkViewer.getWhatIfAnalysisPane(); whatIfPane.whatIfDemandOfferedTrafficModified(filteredDemandList, demandOfferedTrafficsList); final VisualizationState vs = networkViewer.getVisualizationState(); Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = vs.suggestCanvasUpdatedVisualizationLayerInfoForNewDesign(new HashSet<>(networkViewer.getDesign().getNetworkLayers())); vs.setCanvasLayerVisibilityAndOrder(networkViewer.getDesign(), res.getFirst(), res.getSecond()); networkViewer.updateVisualizationAfterNewTopology(); } else { for (int cont = 0; cont < filteredDemandList.size(); cont++) filteredDemandList.get(cont).setOfferedTraffic(demandOfferedTrafficsList.get(cont)); networkViewer.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.DEMAND)); networkViewer.addNetPlanChange(); } } catch (Net2PlanException ee) { ErrorHandling.showErrorDialog(ee.getMessage(), "Error"); } catch (Throwable eee) { eee.printStackTrace(); throw new Net2PlanException("Impossible to complete this action: " + eee.getMessage()); } }
private static TableModel createTableModel(final GUINetworkDesign callback) { TableModel multicastDemandTableModel = new ClassAwareTableModel(new Object[1][netPlanViewTableHeader.length], netPlanViewTableHeader) { private static final long serialVersionUID = 1L; @Override public boolean isCellEditable(int rowIndex, int columnIndex) { if (!callback.getVisualizationState().isNetPlanEditable()) return false; if (columnIndex >= netPlanViewTableHeader.length) return true; if (rowIndex == getRowCount() - 1) return false; if (getValueAt(rowIndex, columnIndex) == null) return false; return columnIndex == COLUMN_OFFEREDTRAFFIC || columnIndex >= netPlanViewTableHeader.length; } @Override public void setValueAt(Object newValue, int row, int column) { Object oldValue = getValueAt(row, column); /* If value doesn't change, exit from function */ if (newValue.equals(oldValue)) return; NetPlan netPlan = callback.getDesign(); if (getValueAt(row, 0) == null) row = row - 1; final long demandId = (Long) getValueAt(row, 0); final MulticastDemand demand = netPlan.getMulticastDemandFromId(demandId); /* Perform checks, if needed */ try { switch (column) { case COLUMN_OFFEREDTRAFFIC: final double newOfferedTraffic = Double.parseDouble(newValue.toString()); if (newOfferedTraffic < 0) throw new Net2PlanException("The demand offered traffic cannot be negative"); if (callback.getVisualizationState().isWhatIfAnalysisActive()) { final WhatIfAnalysisPane whatIfPane = callback.getWhatIfAnalysisPane(); whatIfPane.whatIfMulticastDemandOfferedTrafficModified(demand, newOfferedTraffic); final VisualizationState vs = callback.getVisualizationState(); Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = vs.suggestCanvasUpdatedVisualizationLayerInfoForNewDesign(new HashSet<>(callback.getDesign().getNetworkLayers())); vs.setCanvasLayerVisibilityAndOrder(callback.getDesign(), res.getFirst(), res.getSecond()); callback.updateVisualizationAfterNewTopology(); } else { demand.setOfferedTraffic(newOfferedTraffic); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.MULTICAST_DEMAND)); callback.getVisualizationState().pickElement(demand); callback.updateVisualizationAfterPick(); callback.addNetPlanChange(); } break; default: break; } } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error modifying multicast demand"); return; } /* Set new value */ super.setValueAt(newValue, row, column); } }; return multicastDemandTableModel; }
private static TableModel createTableModel(final GUINetworkDesign callback) { TableModel demandTableModel = new ClassAwareTableModel(new Object[1][netPlanViewTableHeader.length], netPlanViewTableHeader) { private static final long serialVersionUID = 1L; @Override public boolean isCellEditable(int rowIndex, int columnIndex) { if (!callback.getVisualizationState().isNetPlanEditable()) return false; if (columnIndex >= netPlanViewTableHeader.length) return true; if (rowIndex == getRowCount() - 1) return false; // the last row is for the aggregated info if (getValueAt(rowIndex, columnIndex) == null) return false; return columnIndex == COLUMN_OFFEREDTRAFFIC; } @Override public void setValueAt(Object newValue, int row, int column) { Object oldValue = getValueAt(row, column); /* If value doesn't change, exit from function */ if (newValue.equals(oldValue)) return; NetPlan netPlan = callback.getDesign(); if (getValueAt(row, 0) == null) row = row - 1; final long demandId = (Long) getValueAt(row, 0); final Demand demand = netPlan.getDemandFromId(demandId); /* Perform checks, if needed */ try { switch (column) { case COLUMN_OFFEREDTRAFFIC: final double newOfferedTraffic = Double.parseDouble(newValue.toString()); if (newOfferedTraffic < 0) throw new Net2PlanException("The demand offered traffic cannot be negative"); if (callback.getVisualizationState().isWhatIfAnalysisActive()) { final WhatIfAnalysisPane whatIfPane = callback.getWhatIfAnalysisPane(); whatIfPane.whatIfDemandOfferedTrafficModified(demand, newOfferedTraffic); final VisualizationState vs = callback.getVisualizationState(); Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = vs.suggestCanvasUpdatedVisualizationLayerInfoForNewDesign(new HashSet<>(callback.getDesign().getNetworkLayers())); vs.setCanvasLayerVisibilityAndOrder(callback.getDesign(), res.getFirst(), res.getSecond()); callback.updateVisualizationAfterNewTopology(); callback.addNetPlanChange(); } else { demand.setOfferedTraffic(newOfferedTraffic); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.DEMAND)); callback.getVisualizationState().pickElement(demand); callback.updateVisualizationAfterPick(); callback.addNetPlanChange(); } break; default: break; } } catch (Throwable ex) { ex.printStackTrace(); ErrorHandling.showErrorDialog(ex.getMessage(), "Error modifying demand"); return; } /* Set new value */ super.setValueAt(newValue, row, column); } }; return demandTableModel; }
public BidiMap<V, K> inverseBidiMap() { if (inverseBidiMap == null) { inverseBidiMap = createBidiMap(inverseMap, forwardMap, this); } return inverseBidiMap; }
public BidiMap<V, K> inverseBidiMap() { return getBidiMap().inverseBidiMap(); }
public MapIterator makeFullMapIterator() { return UnmodifiableMapIterator.decorate(((BidiMap) getMap()).mapIterator()); }
public BidiMap makeEmptyBidiMap() { return new TreeBidiMap(); }
public BidiMap makeEmptyBidiMap() { return new DualTreeBidiMap(); }
public BidiMap makeEmptyBidiMap() { return UnmodifiableBidiMap.decorate(new DualHashBidiMap()); }
public Map makeFullMap() { BidiMap bidi = new DualHashBidiMap(); addSampleMappings(bidi); return UnmodifiableBidiMap.decorate(bidi); }
private final void doTestGetKey(BidiMap map, Object key, Object value) { assertEquals("Value not found for key.", value, map.get(key)); assertEquals("Key not found for value.", key, map.getKey(value)); }
private final void remove(BidiMap map, Object key) { final Object value = map.remove(key); assertTrue("Key was not removed.", !map.containsKey(key)); assertNull("Value was not removed.", map.getKey(value)); }
private final void removeValue(BidiMap map, Object value) { final Object key = map.removeValue(value); assertTrue("Key was not removed.", !map.containsKey(key)); assertNull("Value was not removed.", map.getKey(value)); }
public BidiMap makeEmptyBidiMap() { return main.makeEmptyBidiMap().inverseBidiMap(); }
public BidiMap makeFullBidiMap() { return main.makeFullBidiMap().inverseBidiMap(); }