Source for net.dpml.cli.DisplaySetting

   1: /**
   2:  * Copyright 2003-2004 The Apache Software Foundation
   3:  * Copyright 2005 Stephen McConnell
   4:  *
   5:  * Licensed under the Apache License, Version 2.0 (the "License");
   6:  * you may not use this file except in compliance with the License.
   7:  * You may obtain a copy of the License at
   8:  *
   9:  *     http://www.apache.org/licenses/LICENSE-2.0
  10:  *
  11:  * Unless required by applicable law or agreed to in writing, software
  12:  * distributed under the License is distributed on an "AS IS" BASIS,
  13:  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14:  * See the License for the specific language governing permissions and
  15:  * limitations under the License.
  16:  */
  17: package net.dpml.cli;
  18: 
  19: import java.util.Collections;
  20: import java.util.HashSet;
  21: import java.util.Set;
  22: 
  23: /**
  24:  * An enum of possible display settings. These settings are used to control the
  25:  * presence of various features in the String representations of options,
  26:  * CommandLines and usage strings.  Usually a Set of DisplaySetting instances
  27:  * will be passed to a method that will lookup the presence of the values.
  28:  *
  29:  * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
  30:  * @version @PROJECT-VERSION@
  31:  */
  32: public final class DisplaySetting 
  33: {
  34:     private static final Set ALL_SETTINGS = new HashSet();
  35: 
  36:     /**
  37:      * A Set guarenteed to contain all possible DisplaySetting values
  38:      */
  39:     public static final Set ALL = Collections.unmodifiableSet( ALL_SETTINGS );
  40:     
  41:     /**
  42:      * A Set guarenteed to contain no DisplaySetting values
  43:      */
  44:     public static final Set NONE = Collections.EMPTY_SET;
  45:     
  46:     /**
  47:      * Indicates that aliases should be included
  48:      */
  49:     public static final DisplaySetting DISPLAY_ALIASES =
  50:         new DisplaySetting( "DISPLAY_ALIASES" );
  51:     
  52:     /**
  53:      * Indicates that optionality should be included
  54:      */
  55:     public static final DisplaySetting DISPLAY_OPTIONAL =
  56:         new DisplaySetting( "DISPLAY_OPTIONAL" );
  57:     
  58:     /**
  59:      * Indicates that property options should be included
  60:      */
  61:     public static final DisplaySetting DISPLAY_PROPERTY_OPTION =
  62:         new DisplaySetting( "DISPLAY_PROPERTY_OPTION" );
  63:     
  64:     /**
  65:      * Indicates that switches should be included enabled
  66:      */
  67:     public static final DisplaySetting DISPLAY_SWITCH_ENABLED =
  68:         new DisplaySetting( "DISPLAY_SWITCH_ENABLED" );
  69:     
  70:     /**
  71:      * Indicates that switches should be included disabled
  72:      */
  73:     public static final DisplaySetting DISPLAY_SWITCH_DISABLED =
  74:         new DisplaySetting( "DISPLAY_SWITCH_DISABLED" );
  75:     
  76:     /**
  77:      * Indicates that group names should be included
  78:      */
  79:     public static final DisplaySetting DISPLAY_GROUP_NAME =
  80:         new DisplaySetting( "DISPLAY_GROUP_NAME" );
  81:     
  82:     /**
  83:      * Indicates that groups should be included expanded
  84:      */
  85:     public static final DisplaySetting DISPLAY_GROUP_EXPANDED =
  86:         new DisplaySetting( "DISPLAY_GROUP_EXPANDED" );
  87:     
  88:     /**
  89:      * Indicates that group arguments should be included
  90:      */
  91:     public static final DisplaySetting DISPLAY_GROUP_ARGUMENT =
  92:         new DisplaySetting( "DISPLAY_GROUP_ARGUMENT" );
  93:     
  94:     /**
  95:      * Indicates that group outer brackets should be included
  96:      */
  97:     public static final DisplaySetting DISPLAY_GROUP_OUTER =
  98:         new DisplaySetting( "DISPLAY_GROUP_OUTER" );
  99:     
 100:     /**
 101:      * Indicates that arguments should be included numbered
 102:      */
 103:     public static final DisplaySetting DISPLAY_ARGUMENT_NUMBERED =
 104:         new DisplaySetting( "DISPLAY_ARGUMENT_NUMBERED" );
 105:     
 106:     /**
 107:      * Indicates that arguments should be included bracketed
 108:      */
 109:     public static final DisplaySetting DISPLAY_ARGUMENT_BRACKETED =
 110:         new DisplaySetting( "DISPLAY_ARGUMENT_BRACKETED" );
 111:     
 112:     /**
 113:      * Indicates that arguments of Parents should be included
 114:      */
 115:     public static final DisplaySetting DISPLAY_PARENT_ARGUMENT =
 116:         new DisplaySetting( "DISPLAY_PARENT_ARGUMENT" );
 117:     
 118:     /**
 119:      * Indicates that children of Parents should be included
 120:      */
 121:     public static final DisplaySetting DISPLAY_PARENT_CHILDREN =
 122:         new DisplaySetting( "DISPLAY_PARENT_CHILDREN" );
 123:     
 124:     /**
 125:      * The name of the setting
 126:      */
 127:     private final String m_name;
 128:     
 129:     /**
 130:      * The hashCode of the setting
 131:      */
 132:     private final int m_hashCode;
 133: 
 134:     /**
 135:      * Creates a new DisplaySetting with the specified name
 136:      * @param name the name of the setting
 137:      */
 138:     private DisplaySetting( final String name ) 
 139:     {
 140:         m_name = name;
 141:         m_hashCode = name.hashCode();
 142:         ALL_SETTINGS.add( this );
 143:     }
 144: 
 145:    /**
 146:     * Return the instance hashcode value.
 147:     * @return the hash value
 148:     */
 149:     public int hashCode() 
 150:     {
 151:         return m_hashCode;
 152:     }
 153: 
 154:    /**
 155:     * Test this object for equality with the supplied object.
 156:     * @param that the other object
 157:     * @return true if the objects are equal
 158:     */
 159:     public boolean equals( final Object that ) 
 160:     {
 161:         if( that instanceof DisplaySetting )
 162:         {
 163:             return m_name.compareTo( that.toString() ) == 0;
 164:         }
 165:         return false;
 166:     }
 167: 
 168:    /**
 169:     * Return a string representation of the instance.
 170:     * @return the string
 171:     */
 172:     public String toString()
 173:     {
 174:         return m_name;
 175:     }
 176: }