public void debug(Element element) { System.out.println("---"); for (String key : element.getPropertyKeys()) { System.out.println(key + " : " + element.getProperty(key)); } System.out.println("---"); }
/** * @return The id of this element. */ protected <N> N getId() { return (N) element.getId(); }
/** * Copy the properties (key and value) from one element to another. * The properties are preserved on the from element. * ElementPropertiesRule that share the same key on the to element are overwritten. * * @param from the element to copy properties from * @param to the element to copy properties to */ public static void copyProperties(final Element from, final Element to) { for (final String key : from.getPropertyKeys()) { to.setProperty(key, from.getProperty(key)); } }
public Object getId() { return propertyBased ? baseElement.getProperty(IdGraph.ID) : baseElement.getId(); }
/** * Renames a property by removing the old key and adding the stored value to the new key. * If property does not exist, nothing occurs. * * @param oldKey the key to rename * @param newKey the key to rename to * @param elements the elements to rename */ public static void renameProperty(final String oldKey, final String newKey, final Iterable<Element> elements) { for (final Element element : elements) { Object value = element.removeProperty(oldKey); if (null != value) element.setProperty(newKey, value); } }
@Override public Object processElement(Object frame, Method method, Object[] arguments, Property annotation, FramedGraph<?> framedGraph, Element element) { if (ClassUtilities.isGetMethod(method)) { Object value = element.getProperty(annotation.value()); if (method.getReturnType().isEnum()) return getValueAsEnum(method, value); else return value; } else if (ClassUtilities.isSetMethod(method)) { Object value = arguments[0]; if (null == value) { element.removeProperty(annotation.value()); } else { if (value.getClass().isEnum()) { element.setProperty(annotation.value(), ((Enum<?>) value).name()); } else { element.setProperty(annotation.value(), value); } } if (method.getReturnType().isAssignableFrom(frame.getClass())) return frame; } else if (ClassUtilities.isRemoveMethod(method)) { element.removeProperty(annotation.value()); return null; } return null; }
/** * Return a property value. * * @param name * The name of the property. * @return the value of the property or null if none was present. */ protected <T> T getProperty(String name) { return element.getProperty(name); }
protected Map<String, Object> processNextStart() { final S element = this.starts.next(); final Map<String, Object> map = new HashMap<String, Object>(); if (this.keys.length == 0) { // TODO: add ID and LABEL as properties? for (final String key : element.getPropertyKeys()) { map.put(key, element.getProperty(key)); } } else { for (final String key : this.keys) { if (key.equals(ID)) map.put(ID, element.getId()); else if (element instanceof Edge && key.equals(LABEL)) map.put(LABEL, ((Edge) element).getLabel()); else map.put(key, element.getProperty(key)); } } return map; } }
@Override public <T extends FramedElement> void init(Element element, Class<T> kind) { String clazz = element.getProperty("java_class"); if (clazz == null) { element.setProperty("java_class", kind.getName()); } } };
public void setProperty(final String key, final Object value) { this.baseElement.setProperty(key, value); }
/** * @return The property keys of this element. */ protected Set<String> getPropertyKeys() { return element.getPropertyKeys(); }
/** * Clear all the properties from an iterable of elements. * * @param elements the elements to remove properties from */ public static void removeProperties(final Iterable<Element> elements) { for (final Element element : elements) { final List<String> keys = new ArrayList<String>(); keys.addAll(element.getPropertyKeys()); for (final String key : keys) { element.removeProperty(key); } } }
/** * Remove a property from all elements in the provided iterable. * * @param key the property to remove by key * @param elements the elements to remove the property from */ public static void removeProperty(final String key, final Iterable<Element> elements) { for (final Element element : elements) { element.removeProperty(key); } }
@Override public Object getId() { return propertyBased ? base.getProperty(IdGraph.ID) : base.getId(); }
@Override public Object processElement(final Property annotation, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Element element, final Direction direction) { if (ClassUtilities.isGetMethod(method)) { Object value = element.getProperty(annotation.value()); if (method.getReturnType().isEnum()) return getValueAsEnum(method, value); else return value; } else if (ClassUtilities.isSetMethod(method)) { Object value = arguments[0]; if (null == value) { element.removeProperty(annotation.value()); } else { if (value.getClass().isEnum()) { element.setProperty(annotation.value(), ((Enum<?>) value).name()); } else { element.setProperty(annotation.value(), value); } } return null; } else if (ClassUtilities.isRemoveMethod(method)) { element.removeProperty(annotation.value()); return null; } return null; }
public <T> T getProperty(final String key) { if (propertyBased && key.equals(IdGraph.ID)) { return null; } else { return baseElement.getProperty(key); } }
/** * Copies all {@code propertyKeys} from the {@code source} to the {@code target}. * * @param source the source element * @param target the target element * @param propertyKeys the property keys to copy */ private void copyProperties(Element source, Element target, Set<String> propertyKeys) { propertyKeys.forEach(k -> target.setProperty(k, source.getProperty(k))); }
/** * Set a property value. * * @param name * The name of the property. * @param value * The value of the property. */ protected void setProperty(String name, Object value) { if (value == null) { element.removeProperty(name); } else { if (value instanceof Enum) { element.setProperty(name, value.toString()); } else { element.setProperty(name, value); } } }
@Override public void init(final Element element, final Class<?> kind) { element.setProperty(this.typeResolutionKey, kind.getSimpleName()); }
@Override public Set<String> getPropertyKeys() { return wrappedElement.getPropertyKeys(); }