/* * The contents of this file are subject to the Mozilla Public License Version 1.1 * (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at . * * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT * WARRANTY OF ANY KIND, either express or implied. See the License for the specific * language governing rights and limitations under the License. * * The Original Code is the Venice Web Communities System. * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ package com.silverwrist.util; import java.util.BitSet; public class OptionSet extends BitSet { /*-------------------------------------------------------------------------------- * Static data members *-------------------------------------------------------------------------------- */ private static final String ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + "!#$%&()*+,-./:;<=>?@[]^_`{|}~"; /*-------------------------------------------------------------------------------- * Constructors *-------------------------------------------------------------------------------- */ public OptionSet() { super(); } // end constructor public OptionSet(int nbits) { super(Math.min(nbits,ALPHA.length())); } // end constructor public OptionSet(char[] options) { super(); // initialize all bits to 0 for (int i=0; i=0) super.set(ndx); } // end for } // end constructor public OptionSet(String options) { this(options.toCharArray()); } // end constructor private StringBuffer asStringBuffer() { StringBuffer b = new StringBuffer(); for (int i=0; i=ALPHA.length()) throw new IndexOutOfBoundsException(); super.clear(bitIndex); } // end clear public boolean get(int bitIndex) { if (bitIndex>=ALPHA.length()) throw new IndexOutOfBoundsException(); return super.get(bitIndex); } // end get public void set(int bitIndex) { if (bitIndex>=ALPHA.length()) throw new IndexOutOfBoundsException(); super.set(bitIndex); } // end set /*-------------------------------------------------------------------------------- * External operations *-------------------------------------------------------------------------------- */ public boolean assign(int ndx, boolean val) { if (ndx>=ALPHA.length()) throw new IndexOutOfBoundsException(); boolean old = super.get(ndx); if (val) super.set(ndx); else super.clear(ndx); return (old!=val); } // end assign public void assign(char[] options) { int i; for (i=0; i=0) super.set(ndx); } // end for } // end assign public void assign(String options) { if (options!=null) assign(options.toCharArray()); } // end assign public char[] asCharArray() { return asStringBuffer().toString().toCharArray(); } // end asCharArray public String asString() { return asStringBuffer().toString(); } // end asString } // end class OptionSet