1
2
3
4 package org.xanot.util;
5
6 import java.util.ArrayList;
7
8 /***
9 * Helper class acting like an ArrayList, in fact it was build using ArrayList
10 * as it storage. It stores list of object pairs.
11 *
12 * @author Ferdinand Neman (newm4n _at_ gmail.com)
13 */
14 public class UniquePairs {
15 private ArrayList<Pair> pairs = new ArrayList<Pair>();
16
17 /***
18 * Add new pair
19 *
20 * @param a
21 * First object
22 * @param b
23 * Second object
24 */
25 public void addPair(Object a, Object b) {
26 pairs.add(new Pair(a, b));
27 }
28
29 /***
30 * Chech wether an object pair is exist
31 *
32 * @param a
33 * First object
34 * @param b
35 * Second object
36 * @return True if pair exist, False if not exist.
37 */
38 public boolean isPairExist(Object a, Object b) {
39 for (Pair p : pairs) {
40 if (p.a.equals(a) && p.b.equals(b)) {
41 return true;
42 }
43 }
44
45 return false;
46 }
47
48 /***
49 * A pair.
50 *
51 * @author Ferdinand Neman (newm4n _at_ gmail.com)
52 */
53 class Pair {
54 Object a;
55
56 Object b;
57
58 /***
59 * Instantiate a pair
60 *
61 * @param a
62 * First object
63 * @param b
64 * Second object
65 */
66 public Pair(Object a, Object b) {
67 this.a = a;
68 this.b = b;
69 }
70 }
71 }