de.hpi.fgis.dude.util.data
Class DuDeObject

java.lang.Object
  extended by de.hpi.fgis.dude.util.data.DuDeObject
All Implemented Interfaces:
AutoJsonable, Jsonable, Comparable<DuDeObject>

public class DuDeObject
extends Object
implements Comparable<DuDeObject>, Jsonable

DuDeObject encapsulates the data of the original object and two ids (for the source and a local one) for identifying each DuDeObject.

Author:
Matthias Pohl
See Also:
AbstractDataSource

Field Summary
static String OBJECT_DATA_ATTRIBUTE_NAME
          The attribute name of the object data within the DuDeObject's Json representation.
static String OBJECT_IDENTIFIER_ATTRIBUTE_NAME
          The attribute name of the object identifier within the DuDeObject's Json representation.
 
Constructor Summary
DuDeObject(JsonRecord data, String srcId, JsonArray objectId)
          Initializes a DuDeObject with the passed ids and the given data.
DuDeObject(JsonRecord data, String sourceId, String objectId)
          Initializes a DuDeObject using the given ids.
DuDeObject(String sourceId, JsonArray objectId)
          Creates a DuDeObject reference.
DuDeObject(String sourceId, String objectId)
          Creates a DuDeObject reference.
 
Method Summary
 void addIdentifier(DuDeObjectId id)
          Adds an identifier to this DuDeObject.
 int compareTo(DuDeObject other)
           
 boolean equals(Object otherObj)
          Two objects are equal, if both have the same ids.
 boolean equalsID(DuDeObject otherDuDeObject)
          Two objects are equal, if both have the same ids.
 void fromJson(DuDeJsonParser<?> jsonParser)
          Initializes the current instance using the passed DuDeJsonParser.
 JsonValue getAttributeValue(String name)
          Returns the first value of the given attribute.
 JsonValue getAttributeValue(String name, int index)
          Returns the concrete value of the given attribute at the passed position.
 JsonValue getAttributeValues(String attributeName)
          Looks within the current DuDeObject for the given attribute.
 JsonValue getAttributeValuesByPath(String... path)
          Traverses the passed path and returns the corresponding attribute value or null, if the passed path is invalid.
 JsonRecord getData()
          Returns the data that describes the real-world object of which this instance is the representation.
 DuDeObjectId getIdentifier()
          Returns the first identifier of this DuDeObject.
 Iterable<DuDeObjectId> getIdentifiers()
          Returns all identifiers of this DuDeObject.
 int getMergeCount()
          Returns the number of objects this DuDeObject was merged from.
 JsonArray getObjectId()
          Returns the object identifier of this object.
 String getSourceId()
          Returns the source identifier of this object.
 boolean hasData()
          Checks whether the current DuDeObject contains real data.
 int hashCode()
           
 boolean isMerged()
          Checks, if this DuDeObject is a merged object.
 void toJson(DuDeJsonGenerator jsonGenerator)
          Generates the Json code using the passed DuDeJsonGenerator.
 String toString()
          Converts the DuDeObject to its Json representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

OBJECT_DATA_ATTRIBUTE_NAME

public static final String OBJECT_DATA_ATTRIBUTE_NAME
The attribute name of the object data within the DuDeObject's Json representation.

See Also:
Constant Field Values

OBJECT_IDENTIFIER_ATTRIBUTE_NAME

public static final String OBJECT_IDENTIFIER_ATTRIBUTE_NAME
The attribute name of the object identifier within the DuDeObject's Json representation.

See Also:
Constant Field Values
Constructor Detail

DuDeObject

public DuDeObject(JsonRecord data,
                  String srcId,
                  JsonArray objectId)
Initializes a DuDeObject with the passed ids and the given data.

Parameters:
data - The data that describes the real-world object of which this instance is the representation.
srcId - The identifier of the source where this data comes from.
objectId - The identifier of the object within the source where this data comes from.
Throws:
NullPointerException - If null was passed through srcId or objId.

DuDeObject

public DuDeObject(String sourceId,
                  JsonArray objectId)
Creates a DuDeObject reference.

Parameters:
sourceId - The source identifier.
objectId - The object identifier.
Throws:
NullPointerException - If null was passed through sourceId or objectId.

DuDeObject

public DuDeObject(JsonRecord data,
                  String sourceId,
                  String objectId)
Initializes a DuDeObject using the given ids. objectId will be embedded into a JsonArray.

Parameters:
data - The data that describes the real-world object of which this instance is the representation.
objectId - The object identifier as String Value. It only consists of values of one column.
sourceId - The source identifier.

DuDeObject

public DuDeObject(String sourceId,
                  String objectId)
Creates a DuDeObject reference.

Parameters:
sourceId - The source identifier.
objectId - The object identifier as a String value.
Throws:
NullPointerException - If null was passed through sourceId or objectId.
Method Detail

equals

public boolean equals(Object otherObj)
Two objects are equal, if both have the same ids. If both objects contain data, this data has to be equal as well.

Overrides:
equals in class Object
Returns:
true, if both objects have the same ids; otherwise false
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equalsID

public boolean equalsID(DuDeObject otherDuDeObject)
Two objects are equal, if both have the same ids.

Parameters:
otherDuDeObject - The DuDeObject that shall be compared with the current instance.
Returns:
true, if both objects have the same ids; otherwise false.

getIdentifier

public DuDeObjectId getIdentifier()
Returns the first identifier of this DuDeObject.

Returns:
The DuDeObjectId which contains both, the source id as well as the object id.

addIdentifier

public void addIdentifier(DuDeObjectId id)
Adds an identifier to this DuDeObject.

Parameters:
id - The DuDeObjectId, which shall be added.

getIdentifiers

public Iterable<DuDeObjectId> getIdentifiers()
Returns all identifiers of this DuDeObject.

Returns:
An Iterable that contains all DuDeObjectIds of this DuDeObject.

isMerged

public boolean isMerged()
Checks, if this DuDeObject is a merged object.

Returns:
true, if it is a merged object, false otherwise

getMergeCount

public int getMergeCount()
Returns the number of objects this DuDeObject was merged from.

Returns:
The number of DuDeObjects that were the source for this merged object. If this object is not a merged one, the return value is 1.

getSourceId

public String getSourceId()
Returns the source identifier of this object.

Returns:
The source identifier of this object..

getObjectId

public JsonArray getObjectId()
Returns the object identifier of this object.

Returns:
The object identifier of this object.

getData

public JsonRecord getData()
Returns the data that describes the real-world object of which this instance is the representation.

Returns:
The object's data or null, if the DuDeObject has no data.

getAttributeValuesByPath

public JsonValue getAttributeValuesByPath(String... path)
Traverses the passed path and returns the corresponding attribute value or null, if the passed path is invalid.

Parameters:
path - The path which specifies the attribute whose value(s) shall be returned.
Returns:
The corresponding value(s) or null, if the path is invalid.

getAttributeValues

public JsonValue getAttributeValues(String attributeName)
Looks within the current DuDeObject for the given attribute. If this attribute is found, the corresponding value is returned. If this attribute does not exist, null will be returned.

Parameters:
attributeName - The name of the attribute whose value is requested.
Returns:
The corresponding JsonArray (since all attribute values are stored in arrays) or null, if this attribute does not exist.

getAttributeValue

public JsonValue getAttributeValue(String name,
                                   int index)
Returns the concrete value of the given attribute at the passed position.

Parameters:
name - The name of the attribute whose value shall be returned.
index - The index of the value within the attribute value list. If this parameter is negative, the corresponding JsonArray will be accessed in reverse order (e.g.: -1 returns the last element).
Returns:
The concrete value or null, if the attribute does not exist, or no value was found at the given position.

getAttributeValue

public JsonValue getAttributeValue(String name)
Returns the first value of the given attribute.

Parameters:
name - The attribute whose value shall be returned.
Returns:
The first value of the attribute or null, if the attribute does not exist or it has no value.

toString

public String toString()
Converts the DuDeObject to its Json representation.

Overrides:
toString in class Object
Returns:
The Json representation of the DuDeObject.

hasData

public boolean hasData()
Checks whether the current DuDeObject contains real data.

Returns:
true, if it contains data; otherwise false.

compareTo

public int compareTo(DuDeObject other)
Specified by:
compareTo in interface Comparable<DuDeObject>

toJson

public void toJson(DuDeJsonGenerator jsonGenerator)
            throws org.codehaus.jackson.JsonGenerationException,
                   IOException
Description copied from interface: Jsonable
Generates the Json code using the passed DuDeJsonGenerator.

Specified by:
toJson in interface Jsonable
Parameters:
jsonGenerator - The DuDeJsonGenerator that is used internally.
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while writing to the output.

fromJson

public void fromJson(DuDeJsonParser<?> jsonParser)
              throws org.codehaus.jackson.JsonParseException,
                     IOException
Description copied from interface: Jsonable
Initializes the current instance using the passed DuDeJsonParser.

Specified by:
fromJson in interface Jsonable
Parameters:
jsonParser - The parser that is used for extracting the data out of the Json.
Throws:
org.codehaus.jackson.JsonParseException - If an error occurs while parsing the Json.
IOException - If an error occurs while reading from the stream.


Copyright © 2011 Hasso Plattner Institute - Chair of Information Systems. All Rights Reserved.