/** Returns the value of a user-defined attributes * @param name the name of the attribute * @param defaultValue if no attribute with this name exists, returns this default value * @return see above */ protected String getAttributeOrDefault (String name , String defaultValue) { return e.getAttribute(name, defaultValue); }
}, e->((NetworkElement)e).getAttribute(attributeKey, "") , AGTYPE.NOAGGREGATION , null));
/** Returns the value associated to a user-defined attribute, as a boolean, or a default is the attribute does not exist, * or cannot be parsed to a boolen * @param name the name of the attribute * @param defaultValue see above * @return see above */ protected boolean getAttributeAsBooleanOrDefault (String name , Boolean defaultValue) { final String s = e.getAttribute(name); if (s == null) return defaultValue; try { return Boolean.parseBoolean (s); } catch (Exception ee) { return defaultValue; } }
protected int getAttributeAsIntegerOrDefault (String name , Integer defaultValue) { final String s = e.getAttribute(name); if (s == null) return defaultValue; try { return Integer.parseInt(s); } catch (Exception ee) { return defaultValue; } }
/** * <p>Returns the values of a given attribute for all the provided network elements.</p> * * @param collection Collection of network elements * @param attribute Attribute name * @return SortedMap with the value of each attribute per network element (value may be {@code null} if not defined * @see com.net2plan.interfaces.networkDesign.NetworkElement */ public static SortedMap<NetworkElement, String> getAttributes(Collection<? extends NetworkElement> collection, String attribute) { SortedMap<NetworkElement, String> attributes = new TreeMap<NetworkElement, String>(); for (NetworkElement e : collection) attributes.put(e, e.getAttribute(attribute)); return attributes; }
/** * <p>Retuns a vector with the values of all given network elements for the given attribute key.</p> * <p><b>Important:</b> Each element must have the attribute set and value must be of type {@code double}</p> * * @param collection Network elements * @param attributeKey Attribute name * @return The vector of values for the given attribute name for all network elements */ public DoubleMatrix1D getVectorAttributeValues(Collection<? extends NetworkElement> collection, String attributeKey) { DoubleMatrix1D res = DoubleFactory1D.dense.make(collection.size()); int counter = 0; for (NetworkElement e : collection) if (e.getAttribute(attributeKey) != null) res.set(counter++, Double.parseDouble(e.getAttribute(attributeKey))); else throw new Net2PlanException("The element does not contain the attribute " + attributeKey); return res; }
/** * <p>Returns the values of a given attribute for all the provided network elements, as a {@code DoubleMatrix1D} vector.</p> * * @param collection Collection of network elements * @param attributeName Attribute name * @param defaultValue If an element has value for the attribute, or it is not a double (it fails in the {@code Double.parseDouble} conversion), then this value is set * @return array with one element per {@code NetworkElement}, in the same order as the input {@code Collection}. * @see com.net2plan.interfaces.networkDesign.NetworkElement */ public static DoubleMatrix1D getAttributeValues(Collection<? extends NetworkElement> collection, String attributeName, double defaultValue) { DoubleMatrix1D res = DoubleFactory1D.dense.make(collection.size()); int counter = 0; for (NetworkElement e : collection) { double val = defaultValue; String value = e.getAttribute(attributeName); if (value != null) try { val = Double.parseDouble(value); } catch (Exception ex) { } res.set(counter++, val); } return res; }