1 package com.atlassian.pageobjects.elements;
2
3
4
5
6
7 public final class Options
8 {
9 static abstract class AbstractOption implements Option
10 {
11 private final String id, value, text;
12
13 public AbstractOption(String id, String value, String text)
14 {
15 if (value == null && id == null && text == null)
16 {
17 throw new IllegalArgumentException("One of the option identifiers must be non-null");
18 }
19 this.value = value;
20 this.id = id;
21 this.text = text;
22 }
23
24 public String id()
25 {
26 return id;
27 }
28
29 public String value()
30 {
31 return value;
32 }
33
34 public String text()
35 {
36 return text;
37 }
38
39 @Override
40 public boolean equals(Object obj)
41 {
42 if (obj == null)
43 {
44 return false;
45 }
46 if (!Option.class.isAssignableFrom(obj.getClass()))
47 {
48 return false;
49 }
50 AbstractOption other = (AbstractOption) obj;
51 if (id != null && !id.equals(other.id))
52 {
53 return false;
54 }
55 if (value != null && !value.equals(other.value))
56 {
57 return false;
58 }
59 if(text != null && !text.equals(other.text))
60 {
61 return false;
62 }
63 return true;
64 }
65
66 @Override
67 public int hashCode()
68 {
69 int result = id != null ? id.hashCode() : 0;
70 result = 31 * result + (value != null ? value.hashCode() : 0);
71 result = 31 * result + (text != null ? text.hashCode(): 0);
72 return result;
73 }
74 }
75
76
77 public static class IdOption extends AbstractOption
78 {
79 IdOption(String id) { super(id, null, null); }
80
81 }
82
83 public static class ValueOption extends AbstractOption
84 {
85 ValueOption(String value) { super(null, value, null); }
86 }
87
88 public static class TextOption extends AbstractOption
89 {
90 TextOption(String text) { super(null,null,text); }
91 }
92
93 public static class FullOption extends AbstractOption
94 {
95 FullOption(String id, String value, String text) { super(id, value, text); }
96 }
97
98
99
100
101
102
103
104 public static IdOption id(String id)
105 {
106 return new IdOption(id);
107 }
108
109
110
111
112
113
114
115 public static ValueOption value(String value)
116 {
117 return new ValueOption(value);
118 }
119
120
121
122
123
124
125
126 public static TextOption text(String text)
127 {
128 return new TextOption(text);
129 }
130
131
132
133
134
135
136
137
138
139
140 public static Option full(String id, String value, String text)
141 {
142 return new FullOption(id, value, text);
143 }
144 }