001/**
002 * Copyright 2003-2004 The Apache Software Foundation
003 * Copyright 2005 Stephen McConnell
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package net.dpml.cli;
018
019import java.util.Collections;
020import java.util.HashSet;
021import java.util.Set;
022
023/**
024 * An enum of possible display settings. These settings are used to control the
025 * presence of various features in the String representations of options,
026 * CommandLines and usage strings.  Usually a Set of DisplaySetting instances
027 * will be passed to a method that will lookup the presence of the values.
028 *
029 * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
030 * @version @PROJECT-VERSION@
031 */
032public final class DisplaySetting 
033{
034    private static final Set ALL_SETTINGS = new HashSet();
035
036    /**
037     * A Set guarenteed to contain all possible DisplaySetting values
038     */
039    public static final Set ALL = Collections.unmodifiableSet( ALL_SETTINGS );
040    
041    /**
042     * A Set guarenteed to contain no DisplaySetting values
043     */
044    public static final Set NONE = Collections.EMPTY_SET;
045    
046    /**
047     * Indicates that aliases should be included
048     */
049    public static final DisplaySetting DISPLAY_ALIASES =
050        new DisplaySetting( "DISPLAY_ALIASES" );
051    
052    /**
053     * Indicates that optionality should be included
054     */
055    public static final DisplaySetting DISPLAY_OPTIONAL =
056        new DisplaySetting( "DISPLAY_OPTIONAL" );
057    
058    /**
059     * Indicates that property options should be included
060     */
061    public static final DisplaySetting DISPLAY_PROPERTY_OPTION =
062        new DisplaySetting( "DISPLAY_PROPERTY_OPTION" );
063    
064    /**
065     * Indicates that switches should be included enabled
066     */
067    public static final DisplaySetting DISPLAY_SWITCH_ENABLED =
068        new DisplaySetting( "DISPLAY_SWITCH_ENABLED" );
069    
070    /**
071     * Indicates that switches should be included disabled
072     */
073    public static final DisplaySetting DISPLAY_SWITCH_DISABLED =
074        new DisplaySetting( "DISPLAY_SWITCH_DISABLED" );
075    
076    /**
077     * Indicates that group names should be included
078     */
079    public static final DisplaySetting DISPLAY_GROUP_NAME =
080        new DisplaySetting( "DISPLAY_GROUP_NAME" );
081    
082    /**
083     * Indicates that groups should be included expanded
084     */
085    public static final DisplaySetting DISPLAY_GROUP_EXPANDED =
086        new DisplaySetting( "DISPLAY_GROUP_EXPANDED" );
087    
088    /**
089     * Indicates that group arguments should be included
090     */
091    public static final DisplaySetting DISPLAY_GROUP_ARGUMENT =
092        new DisplaySetting( "DISPLAY_GROUP_ARGUMENT" );
093    
094    /**
095     * Indicates that group outer brackets should be included
096     */
097    public static final DisplaySetting DISPLAY_GROUP_OUTER =
098        new DisplaySetting( "DISPLAY_GROUP_OUTER" );
099    
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}