Eric J. Bowersox 070fd2c9e2 implemented the "pics in posts" flag globally...it marks the first appearance
of "properties" storage and editing for conferences, communities, users, and
the global system.  In addition, the "global properties" editing screen got
implemented, because it wasn't there yet.
2001-11-11 01:22:07 +00:00

161 lines
4.1 KiB
Java

/*
* 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 <http://www.mozilla.org/MPL/>.
*
* 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 <erbo@silcom.com>,
* 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<options.length; i++)
{ // look at all the chars in the option string and set bits accordingly
int ndx = ALPHA.indexOf(options[i]);
if (ndx>=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<super.length(); i++)
if (super.get(i))
b.append(ALPHA.charAt(i));
return b;
} // end asStringBuffer
/*--------------------------------------------------------------------------------
* Overrides from class BitSet
*--------------------------------------------------------------------------------
*/
public void clear(int bitIndex)
{
if (bitIndex>=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<super.length(); i++)
super.clear(i);
for (i=0; i<options.length; i++)
{ // look at all the chars in the option string and set bits accordingly
int ndx = ALPHA.indexOf(options[i]);
if (ndx>=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