1 18 package org.apache.tools.ant.util; 19 20 import java.util.Stack ; 21 22 26 public class IdentityStack extends Stack { 27 28 33 public static IdentityStack getInstance(Stack s) { 34 if (s instanceof IdentityStack) { 35 return (IdentityStack) s; 36 } 37 IdentityStack result = new IdentityStack(); 38 if (s != null) { 39 result.addAll(s); 40 } 41 return result; 42 } 43 44 47 public IdentityStack() { 48 } 49 50 55 public IdentityStack(Object o) { 56 super(); 57 push(o); 58 } 59 60 66 public synchronized boolean contains(Object o) { 67 return indexOf(o) >= 0; 68 } 69 70 77 public synchronized int indexOf(Object o, int pos) { 78 for (int i = pos; i < size(); i++) { 79 if (get(i) == o) { 80 return i; 81 } 82 } 83 return -1; 84 } 85 86 93 public synchronized int lastIndexOf(Object o, int pos) { 94 for (int i = pos; i >= 0; i--) { 95 if (get(i) == o) { 96 return i; 97 } 98 } 99 return -1; 100 } 101 102 } 103 | Popular Tags |