1 | /**
|
---|
2 | *#########################################################################
|
---|
3 | * Pair.java - part of the demo-client for Greenstone 3, of the
|
---|
4 | * Greenstone digital library suite from the New Zealand Digital Library
|
---|
5 | * Project at the * University of Waikato, New Zealand.
|
---|
6 | * <BR><BR>
|
---|
7 | * Copyright (C) 2008 New Zealand Digital Library Project
|
---|
8 | * <BR><BR>
|
---|
9 | * This program is free software; you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation; either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | * <BR><BR>
|
---|
14 | * This program is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *########################################################################
|
---|
19 | */
|
---|
20 |
|
---|
21 | package org.greenstone.gs3client.data;
|
---|
22 |
|
---|
23 | import java.util.Vector;
|
---|
24 |
|
---|
25 | /** Pair is a simple utility class to represent two associated String values.
|
---|
26 | * For instance, a Metadata (name, value) pair to be displayed in either
|
---|
27 | * SearchResultsDisplay or BrowseDisplay's metanames and metavalues
|
---|
28 | * JLists. (These two classes can be found in org.greenstone.gs3client.)
|
---|
29 | * A Comparator--like the one provided by org.greenstone.gs3client.Displays'
|
---|
30 | * inner class MetadataComparator--is necessary to ensure that the "natural
|
---|
31 | * ordering" of any List of metadata Pairs will be as required. This class
|
---|
32 | * does not implement Comparable so that it may be used for other purposes
|
---|
33 | * than storing ordered Metadata pairs, which is why using an external
|
---|
34 | * Comparator to provide the sorting facility is more useful.
|
---|
35 | * @author ak19 */
|
---|
36 | public class Pair {
|
---|
37 | /** first item of the Pair */
|
---|
38 | public final String first;
|
---|
39 | /** second item of the Pair */
|
---|
40 | public final String second;
|
---|
41 |
|
---|
42 | /** Constructor that creates a Pair from two String values.
|
---|
43 | * @param a - the value for the first item of the Pair
|
---|
44 | * @param b - the value for the second item of the Pair. */
|
---|
45 | public Pair(String a, String b) {
|
---|
46 | first = a;
|
---|
47 | second = b;
|
---|
48 | }
|
---|
49 |
|
---|
50 | /** Given a Vector of Pairs, returns an array of all the first
|
---|
51 | * values of each Pair.
|
---|
52 | * @return all the first fields in a Vector of pairs as an array. */
|
---|
53 | public static String[] getFirst(Vector pairs) {
|
---|
54 | String[] firsts = new String[pairs.size()];
|
---|
55 | for(int i = 0; i < pairs.size(); i++) {
|
---|
56 | Pair p = (Pair)pairs.get(i);
|
---|
57 | firsts[i] = p.first;
|
---|
58 | }
|
---|
59 | return firsts;
|
---|
60 | }
|
---|
61 |
|
---|
62 | /** Given a Vector of Pairs, returns an array of all the second
|
---|
63 | * values of each Pair.
|
---|
64 | * @return all the second fields in a Vector of pairs as an array. */
|
---|
65 | public static String[] getSecond(Vector pairs) {
|
---|
66 | String[] seconds = new String[pairs.size()];
|
---|
67 | for(int i = 0; i < pairs.size(); i++) {
|
---|
68 | Pair p = (Pair)pairs.get(i);
|
---|
69 | seconds[i] = p.second;
|
---|
70 | }
|
---|
71 | return seconds;
|
---|
72 | }
|
---|
73 | }
|
---|