Project

General

Profile

« Previous | Next » 

Revision 44011

[maven-release-plugin] copy for tag dnet-index-client-2.3.0

View differences:

modules/dnet-index-client/tags/dnet-index-client-2.3.0/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-index-client/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "dnet-index-client"}
modules/dnet-index-client/tags/dnet-index-client-2.3.0/src/main/java/eu/dnetlib/functionality/index/model/AnySeq.java
1
package eu.dnetlib.functionality.index.model;
2

  
3
import java.util.Date;
4
import java.util.List;
5

  
6
/**
7
 * Interface for a sequence of Any objects.
8
 * 
9
 * <p>
10
 * AnySeq does <b>not</b> allow <code>null</code> values!
11
 * </p>
12
 * 
13
 */
14
public interface AnySeq extends List<Any>, Any {
15

  
16
	/**
17
	 * @param element
18
	 *            The string object to add
19
	 * @return true if successfully added, false else
20
	 */
21
	boolean add(String element);
22

  
23
	/**
24
	 * Long, Integer, Short and Byte values will be converted to Value object of type LONG, all others to Value object
25
	 * of type DOUBLE.
26
	 * 
27
	 * @param number
28
	 *            The number object to add
29
	 * @return true if successfully added, false else
30
	 */
31
	boolean add(Number number);
32

  
33
	/**
34
	 * @param index
35
	 *            The index where to add the any object
36
	 * @param element
37
	 *            The any object to add
38
	 */
39
	@Override
40
	void add(int index, Any element);
41

  
42
	/**
43
	 * @param index
44
	 *            The index of the object to return
45
	 * @return The AnyMap matching to the index, an InvalidValueTypeException is thrown if the value is not of type
46
	 *         AnyMap
47
	 */
48
	AnyMap getMap(int index);
49

  
50
	/**
51
	 * @param index
52
	 *            The index of the object to return
53
	 * @return The AnySeq matching to this index, an InvalidValueTypeException is thrown if the value is not of type
54
	 */
55
	AnySeq getSeq(int index);
56

  
57
	/**
58
	 * @param index
59
	 *            The index of the object to return
60
	 * @return The value matching to this index, an InvalidValueTypeException is thrown if the value is no value type.
61
	 */
62
	Value getValue(int index);
63

  
64
	/**
65
	 * @param index
66
	 *            The index of the object to return
67
	 * @return The string value matching to this index, an InvalidValueTypeException is thrown if the value is not of
68
	 *         type string
69
	 */
70
	String getStringValue(int index);
71

  
72
	/**
73
	 * @param index
74
	 *            The index of the object to return
75
	 * @return The double value matching to this index, an InvalidValueTypeException is thrown if the value is not of
76
	 *         type double
77
	 */
78
	Double getDoubleValue(int index);
79

  
80
	/**
81
	 * @param index
82
	 *            The index of the object to return
83
	 * @return The long value matching to this index, an InvalidValueTypeException is thrown if the value is not of type
84
	 *         long
85
	 */
86
	Long getLongValue(int index);
87

  
88
	/**
89
	 * @param index
90
	 *            The index of the object to return
91
	 * @return The boolean value matching to this index, an InvalidValueTypeException is thrown if the value is not of
92
	 *         type boolean
93
	 */
94
	Boolean getBooleanValue(int index);
95

  
96
	/**
97
	 * @param index
98
	 *            The index of the object to return
99
	 * @return The date value matching to this index, an InvalidValueTypeException is thrown if the value is not of type
100
	 *         date
101
	 */
102
	Date getDateValue(int index);
103

  
104
	/**
105
	 * @param index
106
	 *            The index of the object to return
107
	 * @return The date time value matching to this index, an InvalidValueTypeException is thrown if the value is not of
108
	 *         type date time
109
	 */
110
	Date getDateTimeValue(int index);
111

  
112
	/**
113
	 * returns all values as a List of Strings.
114
	 * 
115
	 * @throws InvalidValueTypeException
116
	 *             if not all contained values are strings.
117
	 */
118
	List<String> asStrings();
119

  
120
	/**
121
	 * returns all values as a List of Long.
122
	 * 
123
	 * @throws InvalidValueTypeException
124
	 *             if not all contained values are Longs.
125
	 */
126
	List<Long> asLongs();
127

  
128
}
0 129

  
modules/dnet-index-client/tags/dnet-index-client-2.3.0/src/main/java/eu/dnetlib/functionality/index/model/DataFactory.java
1
package eu.dnetlib.functionality.index.model;
2

  
3
import java.util.Date;
4

  
5
import eu.dnetlib.functionality.index.model.Any.ValueType;
6

  
7
/**
8
 * Interface for creation of data objects.
9
 */
10
public interface DataFactory {
11

  
12
	/** default instance. */
13
	DataFactory DEFAULT = DataFactoryCreator.newInstance();
14

  
15
	/**
16
	 * @return The created AnyMap object
17
	 */
18
	AnyMap createAnyMap();
19

  
20
	/**
21
	 * @return The created AnySeq object
22
	 */
23
	AnySeq createAnySeq();
24

  
25
	/**
26
	 * @param value
27
	 *            the String to create the Value from.
28
	 * @return The created Value object.
29
	 */
30
	Value createStringValue(String value);
31

  
32
	/**
33
	 * @param value
34
	 *            the Boolean to create the Value from.
35
	 * @return The created Value object.
36
	 */
37
	Value createBooleanValue(Boolean value);
38

  
39
	/**
40
	 * @param value
41
	 *            the Long to create the Value from.
42
	 * @return The created Value object.
43
	 */
44
	Value createLongValue(Long value);
45

  
46
	/**
47
	 * @param value
48
	 *            the int to create the Value from.
49
	 * @return The created Value object.
50
	 */
51
	Value createLongValue(int value);
52

  
53
	/**
54
	 * @param value
55
	 *            the Double to create the Value from.
56
	 * @return The created Value object.
57
	 */
58
	Value createDoubleValue(Double value);
59

  
60
	/**
61
	 * @param value
62
	 *            the float to create the Value from.
63
	 * @return The created Value object.
64
	 */
65
	Value createDoubleValue(float value);
66

  
67
	/**
68
	 * @param value
69
	 *            the Date to create the Value from.
70
	 * @return The created Value object.
71
	 */
72
	Value createDateValue(Date value);
73

  
74
	/**
75
	 * @param value
76
	 *            the DateTime to create the Value from.
77
	 * @return The created Value object.
78
	 */
79
	Value createDateTimeValue(Date value);
80

  
81
	/**
82
	 * @param value
83
	 *            The value
84
	 * @param type
85
	 *            The type
86
	 * @return The Value object with correct type, InvalidvalueTypeException else.
87
	 */
88
	Value parseFromString(String value, String type);
89

  
90
	/**
91
	 * @param value
92
	 *            The value
93
	 * @param valueType
94
	 *            The value's type
95
	 * @return The Value object with correct type, InvalidvalueTypeException else.
96
	 */
97
	Value parseFromString(final String value, final ValueType valueType);
98

  
99
	/**
100
	 * Tries to convert the String to a Date or Timestamp Value, if not possible return a String Value.
101
	 * 
102
	 * @param value
103
	 *            The value to check for Date/Timestamp
104
	 * @return The Value object with guessed type, InvalidvalueTypeException if value is null.
105
	 */
106
	Value tryDateTimestampParsingFromString(String value);
107

  
108
	/**
109
	 * @param object
110
	 *            The object
111
	 * @return The value matching the class of given object, InvalidValueTypeException otherwise.
112
	 * @deprecated Use {@link #autoConvertValue(Object)} instead
113
	 */
114
	@Deprecated
115
	Value parseFromObject(final Object object);
116

  
117
	/**
118
	 * auto converts the given object into the object's corresponding Value.
119
	 * 
120
	 * @param object
121
	 *            The object, must be one of the simple types
122
	 * @return The value matching the class of given object, InvalidValueTypeException otherwise.
123
	 * 
124
	 */
125
	Value autoConvertValue(final Object object);
126

  
127
	/**
128
	 * Clone Any object.
129
	 * 
130
	 * @param source
131
	 *            the source
132
	 * 
133
	 * @return the attribute
134
	 */
135
	Any cloneAny(final Any source);
136

  
137
	/**
138
	 * Clone AnyMap object.
139
	 * 
140
	 * @param source
141
	 *            the source
142
	 * 
143
	 * @return the attribute
144
	 */
145
	AnyMap cloneAnyMap(final AnyMap source);
146

  
147
	/**
148
	 * Clone AnySeq object.
149
	 * 
150
	 * @param source
151
	 *            the source
152
	 * 
153
	 * @return the attribute
154
	 */
155
	AnySeq cloneAnySeq(final AnySeq source);
156

  
157
}
modules/dnet-index-client/tags/dnet-index-client-2.3.0/src/main/java/eu/dnetlib/functionality/index/model/DataFactoryCreator.java
1
package eu.dnetlib.functionality.index.model;
2

  
3
import eu.dnetlib.functionality.index.model.impl.DefaultDataFactoryImpl;
4

  
5
/**
6
 * Helper class to decouple Any and Record interfaces better from default implementation.
7
 */
8
public final class DataFactoryCreator {
9

  
10
	/**
11
	 * Private default constructor to avoid instance creation.
12
	 */
13
	private DataFactoryCreator() {
14
	}
15

  
16
	/**
17
	 * @return instance of the default DataFactory.
18
	 */
19
	public static DataFactory newInstance() {
20
		return new DefaultDataFactoryImpl();
21
	}
22
}
modules/dnet-index-client/tags/dnet-index-client-2.3.0/src/main/java/eu/dnetlib/functionality/index/model/impl/AnySeqImpl.java
1
package eu.dnetlib.functionality.index.model.impl;
2

  
3
import java.util.ArrayList;
4
import java.util.Collection;
5
import java.util.Date;
6
import java.util.Iterator;
7
import java.util.List;
8
import java.util.ListIterator;
9

  
10
import eu.dnetlib.functionality.index.model.Any;
11
import eu.dnetlib.functionality.index.model.AnyMap;
12
import eu.dnetlib.functionality.index.model.AnySeq;
13
import eu.dnetlib.functionality.index.model.InvalidValueTypeException;
14
import eu.dnetlib.functionality.index.model.Value;
15

  
16
/**
17
 * Sequence of Any objects.
18
 */
19
public final class AnySeqImpl extends AbstractAny implements AnySeq {
20

  
21
	/** version. */
22
	private static final long serialVersionUID = 1L;
23

  
24
	/** holds the Any objects of this AnySeq. */
25
	private final List<Any> _anyList;
26

  
27
	/**
28
	 * constructs a new instance of AnySeqImpl.
29
	 */
30
	AnySeqImpl() {
31
		super(ValueType.SEQ);
32
		_anyList = new ArrayList<Any>();
33
	}
34

  
35
	/** {@inheritDoc} */
36
	@Override
37
	public boolean add(final Any value) {
38
		if (value == null) {
39
			throw new IllegalArgumentException("The value of any Any must not be null.");
40
		}
41
		return _anyList.add(value);
42
	}
43

  
44
	/** {@inheritDoc} */
45
	@Override
46
	public boolean add(final String e) {
47
		return add(new ValueImpl(ValueType.STRING, e));
48
	}
49

  
50
	/** {@inheritDoc} */
51
	@Override
52
	public boolean add(final Number n) {
53
		if (n instanceof Double) {
54
			return add(new ValueImpl(ValueType.DOUBLE, n));
55
		} else if (n instanceof Long) {
56
			return add(new ValueImpl(ValueType.LONG, n));
57
		} else if (n instanceof Integer || n instanceof Short || n instanceof Byte) {
58
			return add(new ValueImpl(ValueType.LONG, Long.valueOf(n.longValue())));
59
		} else { // default: DOUBLE
60
			return add(new ValueImpl(ValueType.DOUBLE, Double.valueOf(n.doubleValue())));
61
		}
62
	}
63

  
64
	/** {@inheritDoc} */
65
	@Override
66
	public void add(final int index, final Any element) {
67
		if (element == null) {
68
			throw new IllegalArgumentException("The value of any Any must not be null.");
69
		}
70
		_anyList.add(index, element);
71
	}
72

  
73
	/** {@inheritDoc} */
74
	@Override
75
	public boolean addAll(final Collection<? extends Any> c) {
76
		return _anyList.addAll(c);
77
	}
78

  
79
	/** {@inheritDoc} */
80
	@Override
81
	public boolean addAll(final int index, final Collection<? extends Any> c) {
82
		return _anyList.addAll(index, c);
83
	}
84

  
85
	/** {@inheritDoc} */
86
	@Override
87
	public void clear() {
88
		_anyList.clear();
89
	}
90

  
91
	/** {@inheritDoc} */
92
	@Override
93
	public boolean contains(final Object o) {
94
		return _anyList.contains(o);
95
	}
96

  
97
	/** {@inheritDoc} */
98
	@Override
99
	public boolean containsAll(final Collection<?> c) {
100
		return _anyList.containsAll(c);
101
	}
102

  
103
	/** {@inheritDoc} */
104
	@Override
105
	public Any get(final int index) {
106
		return _anyList.get(index);
107
	}
108

  
109
	/** {@inheritDoc} */
110
	@Override
111
	public Any set(final int index, final Any element) {
112
		if (element == null) {
113
			throw new IllegalArgumentException("The value of any Any must not be null.");
114
		}
115
		return _anyList.set(index, element);
116
	}
117

  
118
	/** {@inheritDoc} */
119
	@Override
120
	public int indexOf(final Object o) {
121
		return _anyList.indexOf(o);
122
	}
123

  
124
	/** {@inheritDoc} */
125
	@Override
126
	public boolean isEmpty() {
127
		return _anyList.isEmpty();
128
	}
129

  
130
	/** {@inheritDoc} */
131
	@Override
132
	public Iterator<Any> iterator() {
133
		return _anyList.iterator();
134
	}
135

  
136
	/** {@inheritDoc} */
137
	@Override
138
	public int lastIndexOf(final Object o) {
139
		return _anyList.lastIndexOf(o);
140
	}
141

  
142
	/** {@inheritDoc} */
143
	@Override
144
	public ListIterator<Any> listIterator() {
145
		return _anyList.listIterator();
146
	}
147

  
148
	/** {@inheritDoc} */
149
	@Override
150
	public ListIterator<Any> listIterator(final int index) {
151
		return _anyList.listIterator(index);
152
	}
153

  
154
	/** {@inheritDoc} */
155
	@Override
156
	public Any remove(final int index) {
157
		return _anyList.remove(index);
158
	}
159

  
160
	/** {@inheritDoc} */
161
	@Override
162
	public boolean remove(final Object o) {
163
		return _anyList.remove(o);
164
	}
165

  
166
	/** {@inheritDoc} */
167
	@Override
168
	public boolean removeAll(final Collection<?> c) {
169
		return _anyList.removeAll(c);
170
	}
171

  
172
	/** {@inheritDoc} */
173
	@Override
174
	public boolean retainAll(final Collection<?> c) {
175
		return _anyList.retainAll(c);
176
	}
177

  
178
	/** {@inheritDoc} */
179
	@Override
180
	public int size() {
181
		return _anyList.size();
182
	}
183

  
184
	/** {@inheritDoc} */
185
	@Override
186
	public List<Any> subList(final int fromIndex, final int toIndex) {
187
		return _anyList.subList(fromIndex, toIndex);
188
	}
189

  
190
	/** {@inheritDoc} */
191
	@Override
192
	public Object[] toArray() {
193
		return _anyList.toArray();
194
	}
195

  
196
	/** {@inheritDoc} */
197
	@Override
198
	public <T> T[] toArray(final T[] a) {
199
		return _anyList.toArray(a);
200
	}
201

  
202
	/** {@inheritDoc} */
203
	@Override
204
	public AnyMap getMap(final int index) {
205
		final Any anyValue = get(index);
206
		if (anyValue != null) {
207
			if (anyValue.isMap()) {
208
				return (AnyMap) anyValue;
209
			} else {
210
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to AnyMap.");
211
			}
212
		}
213
		return null;
214
	}
215

  
216
	/** {@inheritDoc} */
217
	@Override
218
	public AnySeq getSeq(final int index) {
219
		final Any anyValue = get(index);
220
		if (anyValue != null) {
221
			if (anyValue.isSeq()) {
222
				return (AnySeq) anyValue;
223
			} else {
224
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to AnySeq.");
225
			}
226
		}
227
		return null;
228
	}
229

  
230
	/** {@inheritDoc} */
231
	@Override
232
	public Value getValue(final int index) {
233
		final Any anyValue = get(index);
234
		if (anyValue != null) {
235
			if (anyValue instanceof Value) {
236
				return (Value) anyValue;
237
			} else {
238
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to Value.");
239
			}
240
		}
241
		return null;
242
	}
243

  
244
	/** {@inheritDoc} */
245
	@Override
246
	public String getStringValue(final int index) {
247
		final Any anyValue = get(index);
248
		if (anyValue != null) {
249
			if (anyValue instanceof Value) {
250
				return ((Value) anyValue).asString();
251
			} else {
252
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to String.");
253
			}
254
		}
255
		return null;
256
	}
257

  
258
	/** {@inheritDoc} */
259
	@Override
260
	public Double getDoubleValue(final int index) {
261
		final Any anyValue = get(index);
262
		if (anyValue != null) {
263
			if (anyValue instanceof Value) {
264
				return ((Value) anyValue).asDouble();
265
			} else {
266
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to double.");
267
			}
268
		}
269
		return null;
270
	}
271

  
272
	/** {@inheritDoc} */
273
	@Override
274
	public Long getLongValue(final int index) {
275
		final Any anyValue = get(index);
276
		if (anyValue != null) {
277
			if (anyValue instanceof Value) {
278
				return ((Value) anyValue).asLong();
279
			} else {
280
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to long.");
281
			}
282
		}
283
		return null;
284
	}
285

  
286
	/** {@inheritDoc} */
287
	@Override
288
	public Boolean getBooleanValue(final int index) {
289
		final Any anyValue = get(index);
290
		if (anyValue != null) {
291
			if (anyValue instanceof Value) {
292
				return ((Value) anyValue).asBoolean();
293
			} else {
294
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to boolean.");
295
			}
296
		}
297
		return null;
298
	}
299

  
300
	/** {@inheritDoc} */
301
	@Override
302
	public Date getDateValue(final int index) {
303
		final Any anyValue = get(index);
304
		if (anyValue != null) {
305
			if (anyValue instanceof Value) {
306
				return ((Value) anyValue).asDate();
307
			} else {
308
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to Date.");
309
			}
310
		}
311
		return null;
312
	}
313

  
314
	/** {@inheritDoc} */
315
	@Override
316
	public Date getDateTimeValue(final int index) {
317
		final Any anyValue = get(index);
318
		if (anyValue != null) {
319
			if (anyValue instanceof Value) {
320
				return ((Value) anyValue).asDateTime();
321
			} else {
322
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to DateTime.");
323
			}
324
		}
325
		return null;
326
	}
327

  
328
	/** {@inheritDoc} */
329
	@Override
330
	public int hashCode() {
331
		final int prime = 31;
332
		int result = 1;
333
		result = prime * result + (_anyList == null ? 0 : _anyList.hashCode());
334
		return result;
335
	}
336

  
337
	/** {@inheritDoc} */
338
	@Override
339
	public boolean equals(final Object obj) {
340
		if (this == obj) {
341
			return true;
342
		}
343
		if (obj == null) {
344
			return false;
345
		}
346
		if (!(obj instanceof AnySeqImpl)) {
347
			return false;
348
		}
349
		final AnySeqImpl other = (AnySeqImpl) obj;
350
		if (_anyList == null) {
351
			if (other._anyList != null) {
352
				return false;
353
			}
354
		} else if (!_anyList.equals(other._anyList)) {
355
			return false;
356
		}
357
		return true;
358
	}
359

  
360
	/**
361
	 * {@inheritDoc}
362
	 */
363
	@Override
364
	public String toString() {
365
		return _anyList.toString();
366
	}
367

  
368
	/**
369
	 * {@inheritDoc}
370
	 * 
371
	 * @see org.eclipse.smila.datamodel.Any#asSeq()
372
	 */
373
	@Override
374
	public AnySeq asSeq() {
375
		return this;
376
	}
377

  
378
	/**
379
	 * {@inheritDoc}
380
	 * 
381
	 * @see org.eclipse.smila.datamodel.AnySeq#asStrings()
382
	 */
383
	@Override
384
	public List<String> asStrings() {
385
		final List<String> values = new ArrayList<String>(_anyList.size());
386
		for (final Any any : _anyList) {
387
			values.add(any.asValue().asString());
388
		}
389
		return values;
390
	}
391

  
392
	/**
393
	 * {@inheritDoc}
394
	 * 
395
	 * @see org.eclipse.smila.datamodel.AnySeq#asLongs()
396
	 */
397
	@Override
398
	public List<Long> asLongs() {
399
		final List<Long> values = new ArrayList<Long>(_anyList.size());
400
		for (final Any any : _anyList) {
401
			values.add(any.asValue().asLong());
402
		}
403
		return values;
404
	}
405

  
406
}
0 407

  
modules/dnet-index-client/tags/dnet-index-client-2.3.0/src/main/java/eu/dnetlib/functionality/index/model/impl/AnyMapImpl.java
1
package eu.dnetlib.functionality.index.model.impl;
2

  
3
import java.util.Collection;
4
import java.util.Date;
5
import java.util.Iterator;
6
import java.util.LinkedHashMap;
7
import java.util.Map;
8
import java.util.Set;
9

  
10
import eu.dnetlib.functionality.index.model.Any;
11
import eu.dnetlib.functionality.index.model.AnyMap;
12
import eu.dnetlib.functionality.index.model.AnySeq;
13
import eu.dnetlib.functionality.index.model.InvalidValueTypeException;
14
import eu.dnetlib.functionality.index.model.Value;
15

  
16
/**
17
 * Class implementing AnyMap.
18
 */
19
public final class AnyMapImpl extends AbstractAny implements AnyMap {
20

  
21
	/** version. */
22
	private static final long serialVersionUID = 1L;
23

  
24
	/** internal representation of the AnyMap. */
25
	private final Map<String, Any> _anyMap;
26

  
27
	/** Constructs a new AnyMapImpl. */
28
	AnyMapImpl() {
29
		super(ValueType.MAP);
30
		_anyMap = new LinkedHashMap<String, Any>();
31
	}
32

  
33
	/** {@inheritDoc} */
34
	@Override
35
	public void add(final String key, final Any value) {
36
		final Any any = _anyMap.get(key);
37
		AnySeq anySeq = null;
38
		if (any == null) {
39
			anySeq = getFactory().createAnySeq();
40
			_anyMap.put(key, anySeq);
41
		} else if (any.isValue() || any.isMap()) {
42
			anySeq = getFactory().createAnySeq();
43
			anySeq.add(any);
44
			_anyMap.put(key, anySeq);
45
		} else { // any.isSeq()
46
			anySeq = (AnySeq) any;
47
		}
48
		anySeq.add(value);
49
	}
50

  
51
	/** {@inheritDoc} */
52
	@Override
53
	public void clear() {
54
		_anyMap.clear();
55
	}
56

  
57
	/** {@inheritDoc} */
58
	@Override
59
	public boolean isEmpty() {
60
		return _anyMap.isEmpty();
61
	}
62

  
63
	/** {@inheritDoc} */
64
	@Override
65
	public Set<String> keySet() {
66
		return _anyMap.keySet();
67
	}
68

  
69
	/** {@inheritDoc} */
70
	@Override
71
	public Any put(final String key, final String value) {
72
		try {
73
			return put(key, new ValueImpl(ValueType.STRING, value));
74
		} catch (final Exception e) {
75
			throw new IllegalArgumentException("cannot add value for key: " + key, e);
76
		}
77
	}
78

  
79
	/** {@inheritDoc} */
80
	@Override
81
	public Any put(final String key, final Number value) {
82
		if (value == null) {
83
			throw new IllegalArgumentException("The value of any Any must not be null.");
84
		}
85
		if (value instanceof Double) {
86
			return put(key, new ValueImpl(ValueType.DOUBLE, value));
87
		} else if (value instanceof Long) {
88
			return put(key, new ValueImpl(ValueType.LONG, value));
89
		} else if (value instanceof Integer) {
90
			return put(key, new ValueImpl(ValueType.LONG, Long.valueOf(value.longValue())));
91
		} else if (value instanceof Short) {
92
			return put(key, new ValueImpl(ValueType.LONG, Long.valueOf(value.longValue())));
93
		} else if (value instanceof Byte) {
94
			return put(key, new ValueImpl(ValueType.LONG, Long.valueOf(value.longValue())));
95
		} else { // default: DOUBLE
96
			return put(key, new ValueImpl(ValueType.DOUBLE, Double.valueOf(value.doubleValue())));
97
		}
98
	}
99

  
100
	/** {@inheritDoc} */
101
	@Override
102
	public Any put(final String key, final Boolean value) {
103
		return put(key, new ValueImpl(ValueType.BOOLEAN, value));
104
	}
105

  
106
	/** {@inheritDoc} */
107
	@Override
108
	public Any put(final String key, final Any value) {
109
		if (value == null) {
110
			throw new IllegalArgumentException("The value of any Any must not be null.");
111
		}
112
		return _anyMap.put(key, value);
113
	}
114

  
115
	/** {@inheritDoc} */
116
	@Override
117
	public int size() {
118
		return _anyMap.size();
119
	}
120

  
121
	/** {@inheritDoc} */
122
	@Override
123
	public Collection<Any> values() {
124
		return _anyMap.values();
125
	}
126

  
127
	/** {@inheritDoc} */
128
	@Override
129
	public Iterator<Any> iterator() {
130
		return _anyMap.values().iterator();
131
	}
132

  
133
	/** {@inheritDoc} */
134
	@Override
135
	public AnyMap getMap(final String key) {
136
		final Any anyValue = get(key);
137
		if (anyValue != null) {
138
			if (anyValue.isMap()) {
139
				return (AnyMap) anyValue;
140
			} else {
141
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to AnyMap.");
142
			}
143
		}
144
		return null;
145
	}
146

  
147
	/** {@inheritDoc} */
148
	@Override
149
	public AnySeq getSeq(final String key) {
150
		final Any anyValue = get(key);
151
		if (anyValue != null) {
152
			if (anyValue.isSeq()) {
153
				return (AnySeq) anyValue;
154
			} else {
155
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to AnySeq.");
156
			}
157
		}
158
		return null;
159
	}
160

  
161
	/** {@inheritDoc} */
162
	@Override
163
	public Value getValue(final String key) {
164
		final Any anyValue = get(key);
165
		if (anyValue != null) {
166
			if (anyValue instanceof Value) {
167
				return (Value) anyValue;
168
			} else {
169
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to Value.");
170
			}
171
		}
172
		return null;
173
	}
174

  
175
	/** {@inheritDoc} */
176
	@Override
177
	public String getStringValue(final String key) {
178
		final Any anyValue = get(key);
179
		if (anyValue != null) {
180
			if (anyValue instanceof Value) {
181
				return ((Value) anyValue).asString();
182
			} else {
183
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to String.");
184
			}
185
		}
186
		return null;
187
	}
188

  
189
	/** {@inheritDoc} */
190
	@Override
191
	public Double getDoubleValue(final String key) {
192
		final Any anyValue = get(key);
193
		if (anyValue != null) {
194
			if (anyValue instanceof Value) {
195
				return ((Value) anyValue).asDouble();
196
			} else {
197
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to double.");
198
			}
199
		}
200
		return null;
201
	}
202

  
203
	/** {@inheritDoc} */
204
	@Override
205
	public Long getLongValue(final String key) {
206
		final Any anyValue = get(key);
207
		if (anyValue != null) {
208
			if (anyValue instanceof Value) {
209
				return ((Value) anyValue).asLong();
210
			} else {
211
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to long.");
212
			}
213
		}
214
		return null;
215
	}
216

  
217
	/** {@inheritDoc} */
218
	@Override
219
	public Boolean getBooleanValue(final String key) {
220
		final Any anyValue = get(key);
221
		if (anyValue != null) {
222
			if (anyValue instanceof Value) {
223
				return ((Value) anyValue).asBoolean();
224
			} else {
225
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to boolean.");
226
			}
227
		}
228
		return null;
229
	}
230

  
231
	/** {@inheritDoc} */
232
	@Override
233
	public Date getDateValue(final String key) {
234
		final Any anyValue = get(key);
235
		if (anyValue != null) {
236
			if (anyValue instanceof Value) {
237
				return ((Value) anyValue).asDate();
238
			} else {
239
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to Date.");
240
			}
241
		}
242
		return null;
243
	}
244

  
245
	/** {@inheritDoc} */
246
	@Override
247
	public Date getDateTimeValue(final String key) {
248
		final Any anyValue = get(key);
249
		if (anyValue != null) {
250
			if (anyValue instanceof Value) {
251
				return ((Value) anyValue).asDateTime();
252
			} else {
253
				throw new InvalidValueTypeException("Cannot convert value of type '" + anyValue.getValueType() + "' to DateTime.");
254
			}
255
		}
256
		return null;
257
	}
258

  
259
	/** {@inheritDoc} */
260
	@Override
261
	public int hashCode() {
262
		final int prime = 31;
263
		int result = 1;
264
		result = prime * result + (_anyMap == null ? 0 : _anyMap.hashCode());
265
		return result;
266
	}
267

  
268
	/** {@inheritDoc} */
269
	@Override
270
	public boolean equals(final Object obj) {
271
		if (this == obj) {
272
			return true;
273
		}
274
		if (obj == null) {
275
			return false;
276
		}
277
		if (getClass() != obj.getClass()) {
278
			return false;
279
		}
280
		final AnyMapImpl other = (AnyMapImpl) obj;
281
		if (_anyMap == null) {
282
			if (other._anyMap != null) {
283
				return false;
284
			}
285
		} else if (!_anyMap.equals(other._anyMap)) {
286
			return false;
287
		}
288
		return true;
289
	}
290

  
291
	/**
292
	 * {@inheritDoc}
293
	 */
294
	@Override
295
	public String toString() {
296
		return _anyMap.toString();
297
	}
298

  
299
	/** {@inheritDoc} */
300
	@Override
301
	public boolean containsKey(final Object key) {
302
		return _anyMap.containsKey(key);
303
	}
304

  
305
	/** {@inheritDoc} */
306
	@Override
307
	public boolean containsValue(final Object value) {
308
		return _anyMap.containsValue(value);
309
	}
310

  
311
	/** {@inheritDoc} */
312
	@Override
313
	public Any get(final Object key) {
314
		return _anyMap.get(key);
315
	}
316

  
317
	/** {@inheritDoc} */
318
	@Override
319
	public void putAll(final Map<? extends String, ? extends Any> map) {
320
		_anyMap.putAll(map);
321
	}
322

  
323
	/** {@inheritDoc} */
324
	@Override
325
	public Any remove(final Object key) {
326
		return _anyMap.remove(key);
327
	}
328

  
329
	/** {@inheritDoc} */
330
	@Override
331
	public Set<java.util.Map.Entry<String, Any>> entrySet() {
332
		return _anyMap.entrySet();
333
	}
334

  
335
	/**
336
	 * {@inheritDoc}
337
	 * 
338
	 * @see org.eclipse.smila.datamodel.impl.AbstractAny#asMap()
339
	 */
340
	@Override
341
	public AnyMap asMap() {
342
		return this;
343
	}
344

  
345
	/**
346
	 * {@inheritDoc}
347
	 * 
348
	 * @see org.eclipse.smila.datamodel.AnyMap#getMap(java.lang.String, boolean)
349
	 */
350
	@Override
351
	public AnyMap getMap(final String key, final boolean create) {
352
		AnyMap val = getMap(key);
353
		if (val == null && create) {
354
			val = getFactory().createAnyMap();
355
			this.put(key, val);
356
		}
357
		return val;
358

  
359
	}
360

  
361
	/**
362
	 * {@inheritDoc}
363
	 * 
364
	 * @see org.eclipse.smila.datamodel.AnyMap#getSeq(java.lang.String, boolean)
365
	 */
366
	@Override
367
	public AnySeq getSeq(final String key, final boolean create) {
368
		AnySeq val = getSeq(key);
369
		if (val == null && create) {
370
			val = getFactory().createAnySeq();
371
			this.put(key, val);
372
		}
373
		return val;
374

  
375
	}
376
}
0 377

  
modules/dnet-index-client/tags/dnet-index-client-2.3.0/src/main/java/eu/dnetlib/functionality/index/model/impl/ImmutableAnyMapImpl.java
1
package eu.dnetlib.functionality.index.model.impl;
2

  
3
import java.util.Collection;
4
import java.util.Collections;
5
import java.util.Date;
6
import java.util.Iterator;
7
import java.util.Map;
8
import java.util.Set;
9

  
10
import eu.dnetlib.functionality.index.model.Any;
11
import eu.dnetlib.functionality.index.model.AnyMap;
12
import eu.dnetlib.functionality.index.model.AnySeq;
13
import eu.dnetlib.functionality.index.model.DataFactory;
14
import eu.dnetlib.functionality.index.model.Value;
15

  
16
/**
17
 * immutable decorator for an AnyMap.
18
 */
19
public class ImmutableAnyMapImpl implements AnyMap {
20

  
21
	/** The underlying anymap. */
22
	private final AnyMap _anyMap;
23

  
24
	/** The underlying map, as immutable. */
25
	private final Map<String, Any> _immutable;
26

  
27
	/**
28
	 * @param createAnyMap
29
	 */
30
	public ImmutableAnyMapImpl(AnyMap map) {
31
		_anyMap = map;
32
		_immutable = Collections.unmodifiableMap(map);
33
	}
34

  
35
	@Override
36
	public void add(String key, Any value) {
37
		throw new UnsupportedOperationException();
38
	}
39

  
40
	@Override
41
	public AnyMap asMap() {
42
		return _anyMap.asMap();
43
	}
44

  
45
	@Override
46
	public AnySeq asSeq() {
47
		return _anyMap.asSeq();
48
	}
49

  
50
	@Override
51
	public Value asValue() {
52
		return _anyMap.asValue();
53
	}
54

  
55
	/**
56
	 * 
57
	 * @see java.util.Map#clear()
58
	 */
59
	@Override
60
	public void clear() {
61
		_immutable.clear();
62
	}
63

  
64
	/**
65
	 * @param key
66
	 * @return
67
	 * @see java.util.Map#containsKey(java.lang.Object)
68
	 */
69
	@Override
70
	public boolean containsKey(Object key) {
71
		return _immutable.containsKey(key);
72
	}
73

  
74
	/**
75
	 * @param value
76
	 * @return
77
	 * @see java.util.Map#containsValue(java.lang.Object)
78
	 */
79
	@Override
80
	public boolean containsValue(Object value) {
81
		return _immutable.containsValue(value);
82
	}
83

  
84
	/**
85
	 * @return
86
	 * @see java.util.Map#entrySet()
87
	 */
88
	@Override
89
	public Set<java.util.Map.Entry<String, Any>> entrySet() {
90
		return _immutable.entrySet();
91
	}
92

  
93
	/**
94
	 * @param o
95
	 * @return
96
	 * @see java.util.Map#equals(java.lang.Object)
97
	 */
98
	@Override
99
	public boolean equals(Object o) {
100
		return _immutable.equals(o);
101
	}
102

  
103
	/**
104
	 * @param key
105
	 * @return
106
	 * @see java.util.Map#get(java.lang.Object)
107
	 */
108
	@Override
109
	public Any get(Object key) {
110
		return _immutable.get(key);
111
	}
112

  
113
	@Override
114
	public Boolean getBooleanValue(String key) {
115
		return _anyMap.getBooleanValue(key);
116
	}
117

  
118
	@Override
119
	public Date getDateTimeValue(String key) {
120
		return _anyMap.getDateTimeValue(key);
121
	}
122

  
123
	@Override
124
	public Date getDateValue(String key) {
125
		return _anyMap.getDateValue(key);
126
	}
127

  
128
	@Override
129
	public Double getDoubleValue(String key) {
130
		return _anyMap.getDoubleValue(key);
131
	}
132

  
133
	@Override
134
	public DataFactory getFactory() {
135
		return _anyMap.getFactory();
136
	}
137

  
138
	@Override
139
	public Long getLongValue(String key) {
140
		return _anyMap.getLongValue(key);
141
	}
142

  
143
	@Override
144
	public AnyMap getMap(String key) {
145
		return _anyMap.getMap(key);
146
	}
147

  
148
	@Override
149
	public AnyMap getMap(String key, boolean create) {
150
		return _anyMap.getMap(key, create);
151
	}
152

  
153
	@Override
154
	public AnySeq getSeq(String key) {
155
		return _anyMap.getSeq(key);
156
	}
157

  
158
	@Override
159
	public AnySeq getSeq(String key, boolean create) {
160
		return _anyMap.getSeq(key, create);
161
	}
162

  
163
	@Override
164
	public String getStringValue(String key) {
165
		return _anyMap.getStringValue(key);
166
	}
167

  
168
	@Override
169
	public Value getValue(String key) {
170
		return _anyMap.getValue(key);
171
	}
172

  
173
	@Override
174
	public ValueType getValueType() {
175
		return _anyMap.getValueType();
176
	}
177

  
178
	/**
179
	 * @return
180
	 * @see java.util.Map#hashCode()
181
	 */
182
	@Override
183
	public int hashCode() {
184
		return _immutable.hashCode();
185
	}
186

  
187
	@Override
188
	public boolean isBoolean() {
189
		return _anyMap.isBoolean();
190
	}
191

  
192
	@Override
193
	public boolean isDate() {
194
		return _anyMap.isDate();
195
	}
196

  
197
	@Override
198
	public boolean isDateTime() {
199
		return _anyMap.isDateTime();
200
	}
201

  
202
	@Override
203
	public boolean isDouble() {
204
		return _anyMap.isDouble();
205
	}
206

  
207
	@Override
208
	public boolean isEmpty() {
209
		return _immutable.isEmpty();
210
	}
211

  
212
	@Override
213
	public boolean isLong() {
214
		return _anyMap.isLong();
215
	}
216

  
217
	@Override
218
	public boolean isMap() {
219
		return _anyMap.isMap();
220
	}
221

  
222
	@Override
223
	public boolean isNumber() {
224
		return _anyMap.isNumber();
225
	}
226

  
227
	@Override
228
	public boolean isSeq() {
229
		return _anyMap.isSeq();
230
	}
231

  
232
	@Override
233
	public boolean isString() {
234
		return _anyMap.isString();
235
	}
236

  
237
	@Override
238
	public boolean isValue() {
239
		return _anyMap.isValue();
240
	}
241

  
242
	@Override
243
	public Iterator<Any> iterator() {
244
		return _anyMap.iterator();
245
	}
246

  
247
	@Override
248
	public Set<String> keySet() {
249
		return _immutable.keySet();
250
	}
251

  
252
	/**
253
	 * @param key
254
	 * @param value
255
	 * @return
256
	 * @see java.util.Map#put(java.lang.Object, java.lang.Object)
257
	 */
258
	@Override
259
	public Any put(String key, Any value) {
260
		throw new UnsupportedOperationException();
261
	}
262

  
263
	@Override
264
	public Any put(String key, Boolean value) {
265
		throw new UnsupportedOperationException();
266
	}
267

  
268
	@Override
269
	public Any put(String key, Number value) {
270
		throw new UnsupportedOperationException();
271
	}
272

  
273
	@Override
274
	public Any put(String key, String value) {
275
		throw new UnsupportedOperationException();
276
	}
277

  
278
	@Override
279
	public void putAll(Map<? extends String, ? extends Any> m) {
280
		throw new UnsupportedOperationException();
281
	}
282

  
283
	/**
284
	 * @param key
285
	 * @return
286
	 * @see java.util.Map#remove(java.lang.Object)
287
	 */
288
	@Override
289
	public Any remove(Object key) {
290
		throw new UnsupportedOperationException();
291
	}
292

  
293
	@Override
294
	public int size() {
295
		return _immutable.size();
296
	}
297

  
298
	/**
299
	 * @return
300
	 * @see java.util.Map#values()
301
	 */
302
	@Override
303
	public Collection<Any> values() {
304
		return _immutable.values();
305
	}
306

  
307
}
modules/dnet-index-client/tags/dnet-index-client-2.3.0/src/main/java/eu/dnetlib/functionality/index/model/impl/DefaultDataFactoryImpl.java
1
package eu.dnetlib.functionality.index.model.impl;
2

  
3
import static java.lang.String.format;
4

  
5
import java.util.Date;
6
import java.util.Iterator;
7
import java.util.Map.Entry;
8

  
9
import org.apache.commons.lang.NotImplementedException;
10

  
11
import eu.dnetlib.functionality.index.model.Any;
12
import eu.dnetlib.functionality.index.model.AnyMap;
13
import eu.dnetlib.functionality.index.model.AnySeq;
14
import eu.dnetlib.functionality.index.model.DataFactory;
15
import eu.dnetlib.functionality.index.model.InvalidValueTypeException;
16
import eu.dnetlib.functionality.index.model.Value;
17
import eu.dnetlib.functionality.index.model.ValueFormatHelper;
18
import eu.dnetlib.functionality.index.model.Any.ValueType;
19

  
20
/**
21
 * Implementation of DataFactory.
22
 * 
23
 */
24
public class DefaultDataFactoryImpl implements DataFactory {
25

  
26
	/** instance for sharing. */
27
	public static final DefaultDataFactoryImpl INSTANCE = new DefaultDataFactoryImpl();
28

  
29
	/** immutable empyty map. */
30
	public static final AnyMap IMMUTABLE_EMPTY_MAP = new ImmutableAnyMapImpl(INSTANCE.createAnyMap());
31

  
32
	/**
33
	 * {@inheritDoc}
34
	 */
35
	@Override
36
	public AnyMap createAnyMap() {
37
		return new AnyMapImpl();
38
	}
39

  
40
	/**
41
	 * {@inheritDoc}
42
	 */
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff