Home » xmlbeans-2.5.0-src » org.apache.xmlbeans.impl » config » [javadoc | source]

    1   /*   Copyright 2004 The Apache Software Foundation
    2    *
    3    *   Licensed under the Apache License, Version 2.0 (the "License");
    4    *   you may not use this file except in compliance with the License.
    5    *   You may obtain a copy of the License at
    6    *
    7    *       http://www.apache.org/licenses/LICENSE-2.0
    8    *
    9    *   Unless required by applicable law or agreed to in writing, software
   10    *   distributed under the License is distributed on an "AS IS" BASIS,
   11    *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12    *   See the License for the specific language governing permissions and
   13    *  limitations under the License.
   14    */
   15   /**
   16    * Author: Cezar Andrei ( cezar.andrei at bea.com )
   17    * Date: Apr 25, 2004
   18    */
   19   package org.apache.xmlbeans.impl.config;
   20   
   21   import java.util.Set;
   22   import java.util.HashSet;
   23   
   24   /**
   25    * Used to build {@link NameSet NameSets}.
   26    */
   27   public class NameSetBuilder
   28   {
   29       private boolean _isFinite;
   30       private Set _finiteSet;
   31   
   32       /**
   33        * Creates an empty builder for a NameSet.
   34        */
   35       public NameSetBuilder()
   36       {
   37           _isFinite = true;
   38           _finiteSet = new HashSet();
   39       }
   40   
   41       /**
   42        * Inverts the representing NameSet
   43        */
   44       public void invert()
   45       {
   46           _isFinite = !_isFinite;
   47       }
   48   
   49       /**
   50        * Adds a name to the representing NameSet
   51        * @param name
   52        */
   53       public void add(String name)
   54       {
   55           if (_isFinite )
   56               _finiteSet.add(name);
   57           else
   58               _finiteSet.remove(name);
   59       }
   60   
   61       /**
   62        * Creates a new NameSet with the current state.
   63        * @return created NameSet
   64        */
   65       public NameSet toNameSet()
   66       {
   67           if ( _finiteSet.size()==0 )
   68               if ( _isFinite )
   69                   return NameSet.EMPTY;
   70               else
   71                   return NameSet.EVERYTHING;
   72           else
   73               return NameSet.newInstance(_isFinite, _finiteSet);
   74       }
   75   }

Home » xmlbeans-2.5.0-src » org.apache.xmlbeans.impl » config » [javadoc | source]