01: package com.jat.util;
02:
03: import java.util.Enumeration;
04: import java.util.Vector;
05:
06: /**
07: * <p>Title: JAT</p>
08: * <p>Description: </p>
09: * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
10: * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
11: * @author stf
12: * @version 1.0
13: */
14:
15: public class OrderVector extends java.util.Vector {
16:
17: public static OrderVector orderAscendent(Vector _vett) {
18: return orderAscendent(_vett, null);
19: }
20:
21: public static OrderVector orderAscendent(Vector _vett,
22: Object _orderBy) {
23: OrderVector order = new OrderVector(_orderBy);
24: for (Enumeration e = _vett.elements(); e.hasMoreElements();) {
25: order.addAscElement(e.nextElement());
26: }
27: return order;
28: }
29:
30: public static OrderVector orderDescendent(Vector _vett) {
31: return orderDescendent(_vett, null);
32: }
33:
34: public static OrderVector orderDescendent(Vector _vett,
35: Object _orderBy) {
36: OrderVector order = new OrderVector(_orderBy);
37: for (Enumeration e = _vett.elements(); e.hasMoreElements();) {
38: order.addDescElement(e.nextElement());
39: }
40: return order;
41: }
42:
43: public OrderVector() {
44: super ();
45: }
46:
47: public OrderVector(Object _orderBy) {
48: this ();
49: this .setOrderBy(_orderBy);
50: }
51:
52: public void setOrderBy(Object _orderBy) {
53: this .orderBy_ = _orderBy;
54: }
55:
56: public void addAscElement(Object _obj) {
57: Orderable orderable = (Orderable) _obj;
58: if (this .orderBy_ != null)
59: orderable.orderBy(this .orderBy_);
60: for (int i = 0; i < super .size(); i++) {
61: Orderable item = (Orderable) super .elementAt(i);
62: if (this .orderBy_ != null)
63: item.orderBy(this .orderBy_);
64: if (orderable.lessThan(item)) {
65: super .insertElementAt(orderable, i);
66: return;
67: }
68: }
69: super .addElement(orderable);
70: }
71:
72: public void addDescElement(Object _obj) {
73: Orderable orderable = (Orderable) _obj;
74: if (this .orderBy_ != null)
75: orderable.orderBy(this .orderBy_);
76: for (int i = 0; i < super .size(); i++) {
77: Orderable item = (Orderable) super .elementAt(i);
78: if (orderable.greatThan(item)) {
79: super .insertElementAt(orderable, i);
80: return;
81: }
82: }
83: super .addElement(orderable);
84: }
85:
86: private Object orderBy_ = null;
87: }
|