1 23 24 package com.sun.enterprise.util.collection; 25 26 public class IntSet { 27 int[] members = new int[6]; 28 int size = 0; 29 30 public IntSet() { 31 } 32 33 public boolean add(int value) { 34 for (int i=0; i<size; i++) { 35 if (members[i] == value) { 36 return false; 37 } 38 } 39 40 if (size == members.length) { 41 int[] temp = new int[size + 4]; 42 System.arraycopy(members, 0, temp, 0, size); 43 members = temp; 44 } 45 members[size++] = value; 46 return true; 47 } 48 49 public boolean remove(int value) { 50 for (int i=0; i<size; i++) { 51 if (members[i] == value) { 52 for (int j=i+1; j<size; j++) { 53 members[j-1] = members[j]; 54 } 55 return true; 56 } 57 } 58 return false; 59 } 60 61 public boolean contains(int value) { 62 for (int i=0; i<size; i++) { 63 if (members[i] == value) { 64 return true; 65 } 66 } 67 return false; 68 } 69 70 71 72 public int size() { 73 return size; 74 } 75 76 public int[] getMembers() { 77 return members; 78 } 79 80 } 81 82 | Popular Tags |