Project

General

Profile

1 1218 antonis.le
package eu.dnetlib.domain.data;
2
3 2384 vassilis.s
import java.util.Collections;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Set;
7
8 1218 antonis.le
public class BrowseData {
9
10 2384 vassilis.s
	private HashMap<String, FieldData> data = null;
11
12
	public BrowseData() {
13
		data = new HashMap<String, FieldData>();
14
	}
15
16 2943 vassilis.s
	public HashMap<String, FieldData> getData() {
17
		return data;
18
	}
19
20
	public void setData(HashMap<String, FieldData> data) {
21
		this.data = data;
22
	}
23
24 2384 vassilis.s
	public void addFieldEntry(String field, String value, int count) {
25
26
		// lowercase field!
27
		field = field.toLowerCase();
28 6685 katerina.i
29
		FieldData fieldData = data.get(field);
30
		if(fieldData == null){
31
			fieldData = new FieldData();
32
		}
33
34
		FieldRow row = new FieldRow(value, count);
35
		fieldData.getFieldRowList().add(row);
36 2384 vassilis.s
37 6685 katerina.i
		data.put(field, fieldData);
38 2384 vassilis.s
	}
39
40 10864 katerina.i
	public void append(BrowseData browseData) {
41
		for(String field: browseData.getFields()) {
42
			// lowercase field!
43
			field = field.toLowerCase();
44
45
			FieldData fieldData = data.get(field);
46
			if(fieldData == null){
47
				fieldData = new FieldData();
48
				data.put(field, fieldData);
49
			}
50
51
			fieldData.getFieldRowList().addAll
52
					(browseData.getData().get(field).getFieldRowList());
53
		}
54
	}
55
56 2384 vassilis.s
	public Set<String> getFields() {
57
		return data.keySet();
58
	}
59
60 6685 katerina.i
61 2384 vassilis.s
	public List<String> getFieldValues(String field) {
62
		FieldData fd = data.get(field.toLowerCase());
63
		if (fd == null) {
64
			return Collections.emptyList();
65
		} else {
66
			return fd.getValues();
67
		}
68
	}
69
70
	public List<Integer> getFieldCounts(String field) {
71
		FieldData fd = data.get(field.toLowerCase());
72
		if (fd == null) {
73
			return Collections.emptyList();
74
		} else {
75
			return fd.getCount();
76
		}
77
	}
78
79
	@Override
80
	public String toString() {
81
		StringBuffer buffer = new StringBuffer();
82
83
		for (FieldData field : data.values()) {
84
			buffer.append(field);
85
		}
86
87
		return buffer.toString();
88
	}
89 1218 antonis.le
}