001    package de.deepamehta.core;
002    
003    import de.deepamehta.core.model.CompositeValueModel;
004    import de.deepamehta.core.model.SimpleValue;
005    import de.deepamehta.core.model.TopicModel;
006    import de.deepamehta.core.service.ClientState;
007    import de.deepamehta.core.service.Directives;
008    
009    import java.util.List;
010    
011    
012    
013    public interface CompositeValue {
014    
015    
016    
017        // === Accessors ===
018    
019        /**
020         * Accesses a single-valued child.
021         * Throws if there is no such child.
022         */
023        Topic getTopic(String childTypeUri);
024    
025        /**
026         * Accesses a single-valued child.
027         * Returns a default value if there is no such child.
028         */
029        Topic getTopic(String childTypeUri, Topic defaultTopic);
030    
031        // ---
032    
033        /**
034         * Accesses a multiple-valued child.
035         * Throws if there is no such child.
036         */
037        List<Topic> getTopics(String childTypeUri);
038    
039        /**
040         * Accesses a multiple-valued child.
041         * Returns a default value if there is no such child.
042         */
043        List<Topic> getTopics(String childTypeUri, List<Topic> defaultValue);
044    
045        // ---
046    
047        Object get(String childTypeUri);
048    
049        boolean has(String childTypeUri);
050    
051        Iterable<String> childTypeUris();
052    
053        int size();
054    
055        // ---
056    
057        CompositeValueModel getModel();
058    
059    
060    
061        // === Convenience Accessors ===
062    
063        /**
064         * Convenience accessor for the *simple* value of a single-valued child.
065         * Throws if the child doesn't exist.
066         */
067        String getString(String childTypeUri);
068    
069        /**
070         * Convenience accessor for the *simple* value of a single-valued child.
071         * Returns a default value if the child doesn't exist.
072         */
073        String getString(String childTypeUri, String defaultValue);
074    
075        // ---
076    
077        /**
078         * Convenience accessor for the *simple* value of a single-valued child.
079         * Throws if the child doesn't exist.
080         */
081        int getInt(String childTypeUri);
082    
083        /**
084         * Convenience accessor for the *simple* value of a single-valued child.
085         * Returns a default value if the child doesn't exist.
086         */
087        int getInt(String childTypeUri, int defaultValue);
088    
089        // ---
090    
091        /**
092         * Convenience accessor for the *simple* value of a single-valued child.
093         * Throws if the child doesn't exist.
094         */
095        long getLong(String childTypeUri);
096    
097        /**
098         * Convenience accessor for the *simple* value of a single-valued child.
099         * Returns a default value if the child doesn't exist.
100         */
101        long getLong(String childTypeUri, long defaultValue);
102    
103        // ---
104    
105        /**
106         * Convenience accessor for the *simple* value of a single-valued child.
107         * Throws if the child doesn't exist.
108         */
109        double getDouble(String childTypeUri);
110    
111        /**
112         * Convenience accessor for the *simple* value of a single-valued child.
113         * Returns a default value if the child doesn't exist.
114         */
115        double getDouble(String childTypeUri, double defaultValue);
116    
117        // ---
118    
119        /**
120         * Convenience accessor for the *simple* value of a single-valued child.
121         * Throws if the child doesn't exist.
122         */
123        boolean getBoolean(String childTypeUri);
124    
125        /**
126         * Convenience accessor for the *simple* value of a single-valued child.
127         * Returns a default value if the child doesn't exist.
128         */
129        boolean getBoolean(String childTypeUri, boolean defaultValue);
130    
131        // ---
132    
133        /**
134         * Convenience accessor for the *simple* value of a single-valued child.
135         * Throws if the child doesn't exist.
136         */
137        Object getObject(String childTypeUri);
138    
139        /**
140         * Convenience accessor for the *simple* value of a single-valued child.
141         * Returns a default value if the child doesn't exist.
142         */
143        Object getObject(String childTypeUri, Object defaultValue);
144    
145        // ---
146    
147        /**
148         * Convenience accessor for the *composite* value of a single-valued child.
149         * Throws if the child doesn't exist.
150         */
151        CompositeValue getCompositeValue(String childTypeUri);
152    
153        /**
154         * Convenience accessor for the *composite* value of a single-valued child.
155         * Returns a default value if the child doesn't exist.
156         */
157        CompositeValue getCompositeValue(String childTypeUri, CompositeValue defaultValue);
158    
159        // Note: there are no convenience accessors for a multiple-valued child.
160    
161    
162    
163        // === Manipulators ===
164    
165        /**
166         * Sets a child.
167         * Works for both, single-valued child and multiple-valued child (cardinality "many").
168         */
169        CompositeValue set(String childTypeUri, TopicModel value,          ClientState clientState, Directives directives);
170    
171        /**
172         * Convenience method to set the simple value of a child.
173         * Works for both, single-valued child and multiple-valued child (cardinality "many").
174         *
175         * @param   value   The simple value.
176         *                  Either String, Integer, Long, Double, or Boolean. Primitive values are auto-boxed.
177         */
178        CompositeValue set(String childTypeUri, Object value,              ClientState clientState, Directives directives);
179    
180        /**
181         * Convenience method to set the composite value of a child.
182         * Works for both, single-valued child and multiple-valued child (cardinality "many").
183         */
184        CompositeValue set(String childTypeUri, CompositeValueModel value, ClientState clientState, Directives directives);
185    
186        // ---
187    
188        CompositeValue setRef(String childTypeUri, long refTopicId,        ClientState clientState, Directives directives);
189    
190        CompositeValue setRef(String childTypeUri, String refTopicUri,     ClientState clientState, Directives directives);
191    
192        // ---
193    
194        CompositeValue remove(String childTypeUri, long topicId,           ClientState clientState, Directives directives);
195    }