org.neo4j.graphdb.PropertyContainer Maven / Gradle / Ivy
/*
* Copyright (c) 2002-2015 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package org.neo4j.graphdb;
import java.util.Map;
/**
* Defines a common API for handling properties on both {@link Node nodes} and
* {@link Relationship relationships}.
*
* Properties are key-value pairs. The keys are always strings. Valid property
* value types are all the Java primitives (int
, byte
,
* float
, etc), java.lang.String
s and arrays of
* primitives and Strings.
*
* Please note that Neo4j does NOT accept arbitrary objects as property
* values. {@link #setProperty(String, Object) setProperty()} takes a
* java.lang.Object
only to avoid an explosion of overloaded
* setProperty()
methods.
*/
public interface PropertyContainer
{
/**
* Get the {@link GraphDatabaseService} that this {@link Node} or
* {@link Relationship} belongs to.
*
* @return The GraphDatabase this Node or Relationship belongs to.
*/
GraphDatabaseService getGraphDatabase();
/**
* Returns true
if this property container has a property
* accessible through the given key, false
otherwise. If key is
* null
, this method returns false
.
*
* @param key the property key
* @return true
if this property container has a property
* accessible through the given key, false
otherwise
*/
boolean hasProperty( String key );
/**
* Returns the property value associated with the given key. The value is of
* one of the valid property types, i.e. a Java primitive, a {@link String
* String} or an array of any of the valid types.
*
* If there's no property associated with key
an unchecked
* exception is raised. The idiomatic way to avoid an exception for an
* unknown key and instead get null
back is to use a default
* value: {@link #getProperty(String, Object) Object valueOrNull =
* nodeOrRel.getProperty( key, null )}
*
* @param key the property key
* @return the property value associated with the given key
* @throws NotFoundException if there's no property associated with
* key
*/
Object getProperty( String key );
/**
* Returns the property value associated with the given key, or a default
* value. The value is of one of the valid property types, i.e. a Java
* primitive, a {@link String String} or an array of any of the valid types.
*
* @param key the property key
* @param defaultValue the default value that will be returned if no
* property value was associated with the given key
* @return the property value associated with the given key
*/
Object getProperty( String key, Object defaultValue );
/**
* Sets the property value for the given key to value
. The
* property value must be one of the valid property types, i.e:
*
* boolean
or boolean[]
* byte
or byte[]
* short
or short[]
* int
or int[]
* long
or long[]
* float
or float[]
* double
or double[]
* char
or char[]
* java.lang.String
or String[]
*
*
* This means that null
is not an accepted property value.
*
* @param key the key with which the new property value will be associated
* @param value the new property value, of one of the valid property types
* @throws IllegalArgumentException if value
is of an
* unsupported type (including null
)
*/
void setProperty( String key, Object value );
/**
* Removes the property associated with the given key and returns the old
* value. If there's no property associated with the key, null
* will be returned.
*
* @param key the property key
* @return the property value that used to be associated with the given key
*/
Object removeProperty( String key );
/**
* Returns all existing property keys, or an empty iterable if this property
* container has no properties.
*
* @return all property keys on this property container
*/
// TODO: figure out concurrency semantics
Iterable getPropertyKeys();
/**
* Returns specified existing properties. The collection is mutable,
* but changing it has no impact on the graph as the data is detached.
*
* @param keys the property keys to return
* @return specified properties on this property container
* @throws NullPointerException if the array of keys or any key is null
*/
Map getProperties( String... keys );
/**
* Returns all existing properties.
*
* @return all properties on this property container
*/
Map getAllProperties();
}