1 | /**
|
---|
2 | * DotType.java
|
---|
3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | package org.expeditee.items;
|
---|
20 |
|
---|
21 | public enum DotType {
|
---|
22 | square, circle, diamond, roundSquare, triangle;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Converts the given Expeditee justification code into a int corresponding
|
---|
26 | * to the constants defined in Item.
|
---|
27 | *
|
---|
28 | * @param justCode
|
---|
29 | * The Expeditee justification code to convert
|
---|
30 | * @return The resulting int corresponding to one of the constants defined
|
---|
31 | * in Item
|
---|
32 | */
|
---|
33 | public static DotType convertString(String justCode) {
|
---|
34 | assert (justCode != null);
|
---|
35 | justCode = justCode.trim().toLowerCase();
|
---|
36 |
|
---|
37 | // if it is a single char just match the first character
|
---|
38 | if (justCode.length() == 1) {
|
---|
39 | char code = justCode.charAt(0);
|
---|
40 | DotType[] values = values();
|
---|
41 | for (int i = 0; i < values.length; i++) {
|
---|
42 | DotType j = values[i];
|
---|
43 | if (Character.toLowerCase(j.name().charAt(0)) == code)
|
---|
44 | return j;
|
---|
45 | }
|
---|
46 | // Otherwise match the whole string
|
---|
47 | } else {
|
---|
48 | try {
|
---|
49 | return valueOf(justCode);
|
---|
50 | } catch (Exception e) {
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | // default justification
|
---|
55 | return square;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public char getCode() {
|
---|
59 | return Character.toUpperCase(this.toString().charAt(0));
|
---|
60 | }
|
---|
61 |
|
---|
62 | public String toString() {
|
---|
63 | return this.name();
|
---|
64 | }
|
---|
65 | }
|
---|