Java Code Examples for com.tinkerpop.blueprints.Element#getProperty()

The following examples show how to use com.tinkerpop.blueprints.Element#getProperty() . 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: ArrayPropertyTransformer.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
static void transform(Iterable<? extends Element> elements) {
  for (Element element: elements) {
    for (String key: element.getPropertyKeys()) {
      if (PROTECTED_PROPERTY_KEYS.contains(key)) {
        continue;
      } else {
        Object value = element.getProperty(key);
        if (value instanceof Iterable) {
          // Leave it
        } else if (value.getClass().isArray()) {
          element.setProperty(key, Arrays.asList(value));
        } else {
          element.setProperty(key, newArrayList(value));
        }
      }
    }
  }
}
 
Example 2
Source File: BaseIndexValuesTableWrapper.java    From AccumuloGraph with Apache License 2.0 6 votes vote down vote up
/**
 * Add the property to this index.
 * 
 * <p/>Note that this requires a round-trip to Accumulo to see
 * if the property exists if the provided key has an index.
 * So for best performance, create indices after bulk ingest.
 * <p/>If the force parameter is true, set the property regardless
 * of whether indexing is enabled for the given key. This is needed
 * for {@link IndexableGraph} operations.
 * @param element
 * @param key
 * @param value
 * @param force
 */
public void setPropertyForIndex(Element element, String key, Object value,
    boolean force) {
  AccumuloGraphUtils.validateProperty(key, value);
  if (force || globals.getConfig().getAutoIndex() ||
      globals.getIndexMetadataWrapper()
      .getIndexedKeys(elementType).contains(key)) {
    BatchWriter writer = getWriter();

    Object oldValue = element.getProperty(key);
    if (oldValue != null && !oldValue.equals(value)) {
      Mutators.apply(writer, new IndexValueMutator.Delete(element, key, oldValue));
    }

    Mutators.apply(writer, new IndexValueMutator.Add(element, key, value));
    globals.checkedFlush();
  }
}
 
Example 3
Source File: TinkerGraphUtil.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
static void copyProperties(Element source, Element target) {
  for (String key : source.getPropertyKeys()) {
    Object property = source.getProperty(key);
    if (property.getClass().isArray()) {
      List<Object> propertyList = new ArrayList<>();
      for (int i = 0; i < Array.getLength(property); i++) {
        propertyList.add(Array.get(property, i));
      }
      property = propertyList;
    }
    target.setProperty(key, property);
  }
}
 
Example 4
Source File: VersionedElementUtils.java    From antiquity with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the end version of the specified historic element
 * 
 * @param versionedElement The element to get the end version.
 * @return The end version of the specified element.
 */
@SuppressWarnings("unchecked")
public V getEndVersion(Element versionedElement) {
    Element element = versionedElement;
    if (versionedElement instanceof HistoricVersionedElement) {
        // must be invoked on underline otherwise an infinent loop will
        // occur
        element = ((HistoricVersionedElement) versionedElement).getRaw();
    }

    return (V) element.getProperty(VEProps.VALID_MAX_VERSION_PROP_KEY);
}
 
Example 5
Source File: VersionedElementUtils.java    From antiquity with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return the element type {@link VEProps.GRAPH_TYPE}.
 * 
 * @param e The element to test
 * @return {@link VEProps.GRAPH_TYPE#ACTIVE} or
 *         {@link VEProps.GRAPH_TYPE#HISTORIC}
 */
public VEProps.GRAPH_TYPE getElementType(Element e) {
    // we may receive the underline element for test
    // Preconditions.checkArgument((e instanceof ActiveVersionedElement || e
    // instanceof HistoricVersionedElement),
    // "Unidentified element");
    Boolean historic = e.getProperty(VEProps.HISTORIC_ELEMENT_PROP_KEY);
    Preconditions.checkNotNull(historic, "Element has no [" + VEProps.HISTORIC_ELEMENT_PROP_KEY + "] key.)");

    if ((Boolean) e.getProperty(VEProps.HISTORIC_ELEMENT_PROP_KEY)) {
        return VEProps.GRAPH_TYPE.HISTORIC;
    } else {
        return VEProps.GRAPH_TYPE.ACTIVE;
    }
}
 
Example 6
Source File: PartitionGraph.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public boolean isInPartition(final Element element) {
    final String writePartition;
    if (element instanceof PartitionElement)
        writePartition = ((PartitionElement) element).getPartition();
    else
        writePartition = element.getProperty(this.partitionKey);
    return (null == writePartition || this.readPartitions.contains(writePartition));
}
 
Example 7
Source File: PropertyPipe.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
protected E processNextStart() {
    while (true) {
        Element e = this.starts.next();
        E value = (E) e.getProperty(this.key);
        if (this.allowNull || value != null)
            return value;
    }
}
 
Example 8
Source File: TypeManager.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
private Class<?> resolve(Element e, Class<?> defaultType) {
	Class<?> typeHoldingTypeField = typeRegistry.getTypeHoldingTypeField(defaultType);
	if (typeHoldingTypeField != null) {
		String value = e.getProperty(typeHoldingTypeField.getAnnotation(TypeField.class).value());
		Class<?> type = value == null ? null : typeRegistry.getType(typeHoldingTypeField, value);
		if (type != null) {
			return type;
		}
	}
	return defaultType;
}
 
Example 9
Source File: VersionedElementUtils.java    From antiquity with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the start version of the specified historic element
 * 
 * <p>
 * Note: this method receive a plain vertex and not
 * {@link HistoricVersionedVertex} as it's executed by
 * {@link HistoricVersionedVertexPredicate} over base graph elements.
 * </p>
 * 
 * @param versionedElement The element to get the start version.
 * @return The start version of the specified element.
 */
@SuppressWarnings("unchecked")
public V getStartVersion(Element versionedElement) {
    ensureHistoricType(versionedElement);
    return (V) versionedElement.getProperty(VEProps.VALID_MIN_VERSION_PROP_KEY);
}