01: package net.sourceforge.squirrel_sql.fw.dialects;
02:
03: import java.io.Serializable;
04: import java.util.Comparator;
05:
06: public class IndexColInfo {
07: private String _colName;
08: private Integer _ordinalPosition = Integer.valueOf(0);
09:
10: public static final NameComparator NAME_COMPARATOR = new NameComparator();
11: public static final OrdinalPositionComparator ORDINAL_POSITION_COMPARATOR = new OrdinalPositionComparator();
12:
13: public IndexColInfo(String colName) {
14: _colName = colName;
15: }
16:
17: public IndexColInfo(String colName, int ordinalPosition) {
18:
19: _colName = colName;
20: _ordinalPosition = Integer.valueOf(ordinalPosition);
21: }
22:
23: /**
24: * @see java.lang.Object#hashCode()
25: */
26: @Override
27: public int hashCode() {
28: final int PRIME = 31;
29: int result = 1;
30: result = PRIME * result
31: + ((_colName == null) ? 0 : _colName.hashCode());
32: result = PRIME
33: * result
34: + ((_ordinalPosition == null) ? 0 : _ordinalPosition
35: .hashCode());
36: return result;
37: }
38:
39: /**
40: * @see java.lang.Object#equals(java.lang.Object)
41: */
42: @Override
43: public boolean equals(Object obj) {
44: if (this == obj)
45: return true;
46: if (obj == null)
47: return false;
48: if (getClass() != obj.getClass())
49: return false;
50: final IndexColInfo other = (IndexColInfo) obj;
51: if (_colName == null) {
52: if (other._colName != null)
53: return false;
54: } else if (!_colName.equals(other._colName))
55: return false;
56: if (_ordinalPosition == null) {
57: if (other._ordinalPosition != null)
58: return false;
59: } else if (!_ordinalPosition.equals(other._ordinalPosition))
60: return false;
61: return true;
62: }
63:
64: public String toString() {
65: return _colName;
66: }
67:
68: public int compareTo(Object obj) {
69: return _ordinalPosition
70: .compareTo(((IndexColInfo) obj)._ordinalPosition);
71: }
72:
73: public static class NameComparator implements
74: Comparator<IndexColInfo>, Serializable {
75: private static final long serialVersionUID = 1L;
76:
77: public int compare(IndexColInfo o1, IndexColInfo o2) {
78: return o1._colName.compareTo(o2._colName);
79: }
80: }
81:
82: public static class OrdinalPositionComparator implements
83: Comparator<IndexColInfo>, Serializable {
84: private static final long serialVersionUID = 1L;
85:
86: public int compare(IndexColInfo o1, IndexColInfo o2) {
87: return o1._ordinalPosition.compareTo(o2._ordinalPosition);
88: }
89:
90: }
91:
92: }
|