1 5 package com.opensymphony.webwork.util; 6 7 import java.io.Serializable ; 8 9 10 19 public class Counter implements java.util.Iterator , Serializable { 20 22 boolean wrap = false; 23 24 long first = 1; 26 long current = first; 27 long interval = 1; 28 long last = -1; 29 30 32 public void setAdd(long addition) { 33 current += addition; 34 } 35 36 public void setCurrent(long current) { 37 this.current = current; 38 } 39 40 public long getCurrent() { 41 return current; 42 } 43 44 public void setFirst(long first) { 45 this.first = first; 46 current = first; 47 } 48 49 public long getFirst() { 50 return first; 51 } 52 53 public void setInterval(long interval) { 54 this.interval = interval; 55 } 56 57 public long getInterval() { 58 return interval; 59 } 60 61 public void setLast(long last) { 62 this.last = last; 63 } 64 65 public long getLast() { 66 return last; 67 } 68 69 public long getNext() { 71 long next = current; 72 current += interval; 73 74 if (wrap && (current > last)) { 75 current -= ((1 + last) - first); 76 } 77 78 return next; 79 } 80 81 public long getPrevious() { 82 current -= interval; 83 84 if (wrap && (current < first)) { 85 current += (last - first + 1); 86 } 87 88 return current; 89 } 90 91 public void setWrap(boolean wrap) { 92 this.wrap = wrap; 93 } 94 95 public boolean isWrap() { 96 return wrap; 97 } 98 99 public boolean hasNext() { 100 return ((last == -1) || wrap) ? true : (current <= last); 101 } 102 103 public Object next() { 104 return new Long (getNext()); 105 } 106 107 public void remove() { 108 } 110 } 111 | Popular Tags |