source: trunk/src/org/expeditee/items/Data.java@ 1450

Last change on this file since 1450 was 1388, checked in by bln4, 5 years ago

Data is now contained in its own object. Functionally nothing has changed, but perhaps it will be easier to make changes in the future!

File size: 1.5 KB
Line 
1package org.expeditee.items;
2
3import java.util.ArrayList;
4import java.util.List;
5
6public class Data {
7
8 private List<String> entries = new ArrayList<String>();
9
10 /**
11 * @return The entries in the data.
12 */
13 public List<String> getData() {
14 return entries;
15 }
16
17 /**
18 * Sets data entries to parameter unless parameter is empty or null, in which case it sets the data entries to null.
19 * @param data The list of strings to set as the entries to the data.
20 */
21 public void setData(List<String> data) {
22 if (data == null || data.isEmpty()) {
23 entries = null;
24 } else {
25 entries = data;
26 }
27 }
28
29 /**
30 * Sets data entries to new list with parameter in it unless parameter is empty or null, in which case it sets _data to null.
31 * @param data The data that will be the only data entry.
32 */
33 public void setData(String data) {
34 if (data == null || data.isEmpty()) {
35 entries = null;
36 } else {
37 entries = new ArrayList<String>();
38 entries.add(data);
39 }
40 }
41
42 /**
43 * Adds parameter to data entries.
44 * @param data The data to add.
45 */
46 public void addToData(String data) {
47 if (data != null) {
48 if (entries == null)
49 entries = new ArrayList<String>();
50 entries.add(data);
51 }
52 }
53
54 public boolean hasData(String data) {
55 if (entries != null && data != null && data.length() > 0) {
56 for (final String d : entries) {
57 if (d.compareTo(data) == 0) {
58 return true;
59 }
60 }
61 }
62 return false;
63 }
64}
Note: See TracBrowser for help on using the repository browser.