de.deepamehta.core.model
Class ChildTopicsModel

Show UML class diagram
java.lang.Object
  extended by de.deepamehta.core.model.ChildTopicsModel
All Implemented Interfaces:
Iterable<String>
Direct Known Subclasses:
FacetValue

public class ChildTopicsModel
extends Object
implements Iterable<String>

A recursive composite of key/value pairs. ### FIXDOC

Keys are strings, values are non-null atomic (string, int, long, double, boolean) or again a ChildTopicsModel. ### FIXDOC


Field Summary
private  Map<String,Object> childTopics
          Internal representation.
private static String DEL_PREFIX
           
private  Logger logger
           
private static String REF_ID_PREFIX
           
private static String REF_URI_PREFIX
           
 
Constructor Summary
ChildTopicsModel()
           
ChildTopicsModel(org.codehaus.jettison.json.JSONObject values)
           
 
Method Summary
 ChildTopicsModel add(String childTypeUri, RelatedTopicModel value)
          Adds a value to a multiple-valued child.
 ChildTopicsModel add(String childTypeUri, TopicModel value)
           
 ChildTopicsModel addDeletionRef(String childTypeUri, long refTopicId)
          Adds a by-ID topic deletion reference to a multiple-valued child.
 ChildTopicsModel addRef(String childTypeUri, long refTopicId)
          Adds a by-ID topic reference to a multiple-valued child.
 ChildTopicsModel addRef(String childTypeUri, String refTopicUri)
          Adds a by-URI topic reference to a multiple-valued child.
 ChildTopicsModel clone()
           
private  RelatedTopicModel createReferenceModel(Object value, AssociationModel relatingAssoc)
           
private  RelatedTopicModel createTopicModel(String childTypeUri, Object value)
          Creates a topic model from a JSON value.
private  long delTopicId(String val)
           
 Object get(String childTypeUri)
          Accesses a child generically, regardless of single-valued or multiple-valued.
 boolean getBoolean(String childTypeUri)
          Convenience accessor for the *simple* value of a single-valued child.
 boolean getBoolean(String childTypeUri, boolean defaultValue)
          Convenience accessor for the *simple* value of a single-valued child.
 ChildTopicsModel getChildTopicsModel(String childTypeUri)
          Convenience accessor for the *composite* value of a single-valued child.
 ChildTopicsModel getChildTopicsModel(String childTypeUri, ChildTopicsModel defaultValue)
          Convenience accessor for the *composite* value of a single-valued child.
 double getDouble(String childTypeUri)
          Convenience accessor for the *simple* value of a single-valued child.
 double getDouble(String childTypeUri, double defaultValue)
          Convenience accessor for the *simple* value of a single-valued child.
 int getInt(String childTypeUri)
          Convenience accessor for the *simple* value of a single-valued child.
 int getInt(String childTypeUri, int defaultValue)
          Convenience accessor for the *simple* value of a single-valued child.
 long getLong(String childTypeUri)
          Convenience accessor for the *simple* value of a single-valued child.
 long getLong(String childTypeUri, long defaultValue)
          Convenience accessor for the *simple* value of a single-valued child.
 Object getObject(String childTypeUri)
          Convenience accessor for the *simple* value of a single-valued child.
 Object getObject(String childTypeUri, Object defaultValue)
          Convenience accessor for the *simple* value of a single-valued child.
 String getString(String childTypeUri)
          Convenience accessor for the *simple* value of a single-valued child.
 String getString(String childTypeUri, String defaultValue)
          Convenience accessor for the *simple* value of a single-valued child.
 RelatedTopicModel getTopic(String childTypeUri)
          Accesses a single-valued child.
 RelatedTopicModel getTopic(String childTypeUri, RelatedTopicModel defaultValue)
          Accesses a single-valued child.
 List<RelatedTopicModel> getTopics(String childTypeUri)
          Accesses a multiple-valued child.
 List<RelatedTopicModel> getTopics(String childTypeUri, List<RelatedTopicModel> defaultValue)
          Accesses a multiple-valued child.
 boolean has(String childTypeUri)
          Checks if a child is contained in this ChildTopicsModel.
private  void initTypeUri(org.codehaus.jettison.json.JSONObject value, String childTypeUri)
           
 Iterator<String> iterator()
          Returns an interator which iterates this ChildTopicsModel's child type URIs.
 ChildTopicsModel put(String childTypeUri, ChildTopicsModel value)
          Convenience method to put a *composite* value in a single-valued child.
 ChildTopicsModel put(String childTypeUri, List<RelatedTopicModel> values)
          Sets the values of a multiple-valued child.
 ChildTopicsModel put(String childTypeUri, Object value)
          Convenience method to put a *simple* value in a single-valued child.
 ChildTopicsModel put(String childTypeUri, RelatedTopicModel value)
          Puts a value in a single-valued child.
 ChildTopicsModel put(String childTypeUri, TopicModel value)
           
 ChildTopicsModel putRef(String childTypeUri, long refTopicId)
          Puts a by-ID topic reference in a single-valued child.
 ChildTopicsModel putRef(String childTypeUri, String refTopicUri)
          Puts a by-URI topic reference in a single-valued child.
private  long refTopicId(String val)
           
private  String refTopicUri(String val)
           
 ChildTopicsModel remove(String childTypeUri)
          Removes a single-valued child.
 ChildTopicsModel remove(String childTypeUri, TopicModel value)
          Removes a value from a multiple-valued child.
 int size()
          Returns the number of childs contained in this ChildTopicsModel.
 void throwInvalidAccess(String childTypeUri, ClassCastException e)
          ### TODO: should not be public.
 org.codehaus.jettison.json.JSONObject toJSON()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REF_ID_PREFIX

private static final String REF_ID_PREFIX
See Also:
Constant Field Values

REF_URI_PREFIX

private static final String REF_URI_PREFIX
See Also:
Constant Field Values

DEL_PREFIX

private static final String DEL_PREFIX
See Also:
Constant Field Values

childTopics

private Map<String,Object> childTopics
Internal representation. Key: String, value: RelatedTopicModel or List


logger

private Logger logger
Constructor Detail

ChildTopicsModel

public ChildTopicsModel()

ChildTopicsModel

public ChildTopicsModel(org.codehaus.jettison.json.JSONObject values)
Method Detail

getTopic

public RelatedTopicModel getTopic(String childTypeUri)
Accesses a single-valued child. Throws if there is no such child.


getTopic

public RelatedTopicModel getTopic(String childTypeUri,
                                  RelatedTopicModel defaultValue)
Accesses a single-valued child. Returns a default value if there is no such child.


getTopics

public List<RelatedTopicModel> getTopics(String childTypeUri)
Accesses a multiple-valued child. Throws if there is no such child.


getTopics

public List<RelatedTopicModel> getTopics(String childTypeUri,
                                         List<RelatedTopicModel> defaultValue)
Accesses a multiple-valued child. Returns a default value if there is no such child.


get

public Object get(String childTypeUri)
Accesses a child generically, regardless of single-valued or multiple-valued. Returns null if there is no such child.

Returns:
A RelatedTopicModel or List, or null if there is no such child.

has

public boolean has(String childTypeUri)
Checks if a child is contained in this ChildTopicsModel.


size

public int size()
Returns the number of childs contained in this ChildTopicsModel. Multiple-valued childs count as one.


getString

public String getString(String childTypeUri)
Convenience accessor for the *simple* value of a single-valued child. Throws if the child doesn't exist.


getString

public String getString(String childTypeUri,
                        String defaultValue)
Convenience accessor for the *simple* value of a single-valued child. Returns a default value if the child doesn't exist.


getInt

public int getInt(String childTypeUri)
Convenience accessor for the *simple* value of a single-valued child. Throws if the child doesn't exist.


getInt

public int getInt(String childTypeUri,
                  int defaultValue)
Convenience accessor for the *simple* value of a single-valued child. Returns a default value if the child doesn't exist.


getLong

public long getLong(String childTypeUri)
Convenience accessor for the *simple* value of a single-valued child. Throws if the child doesn't exist.


getLong

public long getLong(String childTypeUri,
                    long defaultValue)
Convenience accessor for the *simple* value of a single-valued child. Returns a default value if the child doesn't exist.


getDouble

public double getDouble(String childTypeUri)
Convenience accessor for the *simple* value of a single-valued child. Throws if the child doesn't exist.


getDouble

public double getDouble(String childTypeUri,
                        double defaultValue)
Convenience accessor for the *simple* value of a single-valued child. Returns a default value if the child doesn't exist.


getBoolean

public boolean getBoolean(String childTypeUri)
Convenience accessor for the *simple* value of a single-valued child. Throws if the child doesn't exist.


getBoolean

public boolean getBoolean(String childTypeUri,
                          boolean defaultValue)
Convenience accessor for the *simple* value of a single-valued child. Returns a default value if the child doesn't exist.


getObject

public Object getObject(String childTypeUri)
Convenience accessor for the *simple* value of a single-valued child. Throws if the child doesn't exist.


getObject

public Object getObject(String childTypeUri,
                        Object defaultValue)
Convenience accessor for the *simple* value of a single-valued child. Returns a default value if the child doesn't exist.


getChildTopicsModel

public ChildTopicsModel getChildTopicsModel(String childTypeUri)
Convenience accessor for the *composite* value of a single-valued child. Throws if the child doesn't exist.


getChildTopicsModel

public ChildTopicsModel getChildTopicsModel(String childTypeUri,
                                            ChildTopicsModel defaultValue)
Convenience accessor for the *composite* value of a single-valued child. Returns a default value if the child doesn't exist.


put

public ChildTopicsModel put(String childTypeUri,
                            RelatedTopicModel value)
Puts a value in a single-valued child. An existing value is overwritten.


put

public ChildTopicsModel put(String childTypeUri,
                            TopicModel value)

put

public ChildTopicsModel put(String childTypeUri,
                            Object value)
Convenience method to put a *simple* value in a single-valued child. An existing value is overwritten.

Parameters:
value - a String, Integer, Long, Double, or a Boolean.
Returns:
this ChildTopicsModel.

put

public ChildTopicsModel put(String childTypeUri,
                            ChildTopicsModel value)
Convenience method to put a *composite* value in a single-valued child. An existing value is overwritten.

Returns:
this ChildTopicsModel.

putRef

public ChildTopicsModel putRef(String childTypeUri,
                               long refTopicId)
Puts a by-ID topic reference in a single-valued child. An existing reference is overwritten.


putRef

public ChildTopicsModel putRef(String childTypeUri,
                               String refTopicUri)
Puts a by-URI topic reference in a single-valued child. An existing reference is overwritten.


remove

public ChildTopicsModel remove(String childTypeUri)
Removes a single-valued child.


add

public ChildTopicsModel add(String childTypeUri,
                            RelatedTopicModel value)
Adds a value to a multiple-valued child.


add

public ChildTopicsModel add(String childTypeUri,
                            TopicModel value)

put

public ChildTopicsModel put(String childTypeUri,
                            List<RelatedTopicModel> values)
Sets the values of a multiple-valued child. Existing values are overwritten.


remove

public ChildTopicsModel remove(String childTypeUri,
                               TopicModel value)
Removes a value from a multiple-valued child.


addRef

public ChildTopicsModel addRef(String childTypeUri,
                               long refTopicId)
Adds a by-ID topic reference to a multiple-valued child.


addRef

public ChildTopicsModel addRef(String childTypeUri,
                               String refTopicUri)
Adds a by-URI topic reference to a multiple-valued child.


addDeletionRef

public ChildTopicsModel addDeletionRef(String childTypeUri,
                                       long refTopicId)
Adds a by-ID topic deletion reference to a multiple-valued child.


iterator

public Iterator<String> iterator()
Returns an interator which iterates this ChildTopicsModel's child type URIs.

Specified by:
iterator in interface Iterable<String>

toJSON

public org.codehaus.jettison.json.JSONObject toJSON()

clone

public ChildTopicsModel clone()
Overrides:
clone in class Object

toString

public String toString()
Overrides:
toString in class Object

createTopicModel

private RelatedTopicModel createTopicModel(String childTypeUri,
                                           Object value)
                                    throws org.codehaus.jettison.json.JSONException
Creates a topic model from a JSON value. Both topic serialization formats are supported: 1) canonic format -- contains entire topic models. 2) simplified format -- contains the topic value only (simple or composite).

Throws:
org.codehaus.jettison.json.JSONException

createReferenceModel

private RelatedTopicModel createReferenceModel(Object value,
                                               AssociationModel relatingAssoc)

initTypeUri

private void initTypeUri(org.codehaus.jettison.json.JSONObject value,
                         String childTypeUri)
                  throws org.codehaus.jettison.json.JSONException
Throws:
org.codehaus.jettison.json.JSONException

refTopicId

private long refTopicId(String val)

refTopicUri

private String refTopicUri(String val)

delTopicId

private long delTopicId(String val)

throwInvalidAccess

public void throwInvalidAccess(String childTypeUri,
                               ClassCastException e)
### TODO: should not be public. Specify interfaces also for model classes?



Copyright © 2015. All Rights Reserved.