Project

General

Profile

1
package eu.dnetlib.data.collective.transformation.engine;
2

    
3
import java.util.Collection;
4
import java.util.LinkedHashMap;
5
import java.util.LinkedList;
6
import java.util.List;
7
import java.util.Map;
8

    
9
/**
10
 * @author js
11
 *
12
 */
13
public class FunctionResults {
14

    
15
	private Map<String, List<String>> resultMap = new LinkedHashMap<String, List<String>>();
16
	
17
	
18
	/**
19
	 * get the first single result from the result list at the given index
20
	 * @param aIndex
21
	 * @return a result
22
	 */
23
	public String get(int aIndex){
24
		return resultMap.get(aIndex + "").get(0);
25
	}
26
	
27
	/**
28
	 * get the single result for the node at the given position from the list at the given index
29
	 * @param aIndex
30
	 * @param aPosition
31
	 * @return a result
32
	 */
33
	public String get(int aIndex, int aPosition){
34
		if (aPosition <= 0){
35
			throw new IllegalArgumentException("position is " + aPosition + ", must be greater 0");
36
		}
37
		return resultMap.get(aIndex + "").get(aPosition - 1);
38
	}
39
	
40
	/**
41
	 * add a collection containing the results for each record
42
	 * @param aCollection
43
	 */
44
	public void addAll(Collection<? extends String> aCollection){
45
		for (String result : aCollection){
46
			add(result);
47
		}
48
	}
49
	
50
	/**
51
	 * add a single result calculated for a record node
52
	 * @param aResult
53
	 */
54
	public void add(String aResult){
55
		List<String> resultList = new LinkedList<String>();
56
		resultList.add(aResult);
57
		resultMap.put(resultMap.size() + "", resultList);
58
	}
59
	
60
	/**
61
	 * add a list of results calculated for all resp. record nodes
62
	 * @param aResults
63
	 */
64
	public void add(List<String> aResults){
65
		resultMap.put(resultMap.size() + "", aResults);
66
	}
67
}
(1-1/3)