1 21 22 package org.apache.commons.validator.util; 23 24 import java.io.Serializable ; 25 26 44 public class Flags implements Serializable { 45 46 49 private long flags = 0; 50 51 54 public Flags() { 55 super(); 56 } 57 58 61 public Flags(long flags) { 62 super(); 63 this.flags = flags; 64 } 65 66 69 public long getFlags() { 70 return this.flags; 71 } 72 73 77 public boolean isOn(long flag) { 78 return (this.flags & flag) > 0; 79 } 80 81 85 public boolean isOff(long flag) { 86 return (this.flags & flag) == 0; 87 } 88 89 93 public void turnOn(long flag) { 94 this.flags |= flag; 95 } 96 97 101 public void turnOff(long flag) { 102 this.flags &= ~flag; 103 } 104 105 108 public void turnOffAll() { 109 this.flags = 0; 110 } 111 112 116 public void clear() { 117 this.flags = 0; 118 } 119 120 123 public void turnOnAll() { 124 this.flags = Long.MAX_VALUE; 125 } 126 127 131 public Object clone() { 132 try { 133 return super.clone(); 134 } catch(CloneNotSupportedException e) { 135 throw new RuntimeException ("Couldn't clone Flags object."); 136 } 137 } 138 139 144 public boolean equals(Object obj) { 145 if (!(obj instanceof Flags)) { 146 return false; 147 } 148 149 if (obj == this) { 150 return true; 151 } 152 153 Flags f = (Flags) obj; 154 155 return this.flags == f.flags; 156 } 157 158 162 public int hashCode() { 163 return (int) this.flags; 164 } 165 166 171 public String toString() { 172 StringBuffer bin = new StringBuffer (Long.toBinaryString(this.flags)); 173 for (int i = 64 - bin.length(); i > 0; i--) { 174 bin.insert(0, "0"); 175 } 176 return bin.toString(); 177 } 178 179 } 180 | Popular Tags |