Java Code Examples for com.tinkerpop.blueprints.Element#removeProperty()
The following examples show how to use
com.tinkerpop.blueprints.Element#removeProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyIndexableGraphHelper.java From org.openntf.domino with Apache License 2.0 | 6 votes |
/** * For those graphs that do no support automatic reindexing of elements when a key is provided for indexing, this method can be used to simulate that behavior. * The elements in the graph are iterated and their properties (for the provided keys) are removed and then added. * Be sure that the key indices have been created prior to calling this method so that they can pick up the property mutations calls. * Finally, if the graph is a TransactionalGraph, then a 1000 mutation buffer is used for each commit. * * @param graph the graph containing the provided elements * @param elements the elements to index into the key indices * @param keys the keys of the key indices * @return the number of element properties that were indexed */ public static long reIndexElements(final Graph graph, final Iterable<? extends Element> elements, final Set<String> keys) { final boolean isTransactional = graph instanceof TransactionalGraph; long counter = 0; for (final Element element : elements) { for (final String key : keys) { final Object value = element.removeProperty(key); if (null != value) { counter++; element.setProperty(key, value); if (isTransactional && (counter % 1000 == 0)) { ((TransactionalGraph) graph).commit(); } } } } if (isTransactional) { ((TransactionalGraph) graph).commit(); } return counter; }
Example 2
Source File: ElementHelper.java From org.openntf.domino with Apache License 2.0 | 5 votes |
/** * 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); } } }
Example 3
Source File: ElementHelper.java From org.openntf.domino with Apache License 2.0 | 5 votes |
/** * Typecasts a property value. This only works for casting to a class that has a constructor of the for new X(String). * If no such constructor exists, a RuntimeException is thrown and the original element property is left unchanged. * * @param key the key for the property value to typecast * @param classCast the class to typecast to * @param elements the elements to have their property typecasted */ public static void typecastProperty(final String key, final Class classCast, final Iterable<Element> elements) { for (final Element element : elements) { final Object value = element.removeProperty(key); if (null != value) { try { element.setProperty(key, classCast.getConstructor(String.class).newInstance(value.toString())); } catch (Exception e) { element.setProperty(key, value); throw new RuntimeException(e.getMessage(), e); } } } }
Example 4
Source File: ElementHelper.java From org.openntf.domino with Apache License 2.0 | 3 votes |
/** * 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); } }
Example 5
Source File: ElementHelper.java From org.openntf.domino with Apache License 2.0 | 2 votes |
/** * 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); } }