001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  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 org.apache.commons.cli2;
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 */
029public class DisplaySetting {
030
031    private static final Set all = new HashSet();
032
033    /**
034     * A Set guaranteed to contain all possible DisplaySetting values
035     */
036    public static final Set ALL = Collections.unmodifiableSet(all);
037
038    /**
039     * A Set guaranteed to contain no DisplaySetting values
040     */
041    public static final Set NONE = Collections.EMPTY_SET;
042
043    /**
044     * Indicates that aliases should be included
045     */
046    public static final DisplaySetting DISPLAY_ALIASES =
047        new DisplaySetting("DISPLAY_ALIASES");
048
049    /**
050     * Indicates that optionality should be included
051     */
052    public static final DisplaySetting DISPLAY_OPTIONAL =
053        new DisplaySetting("DISPLAY_OPTIONAL");
054
055    /**
056     * Indicates that optional child groups should be displayed in square
057     * brackets.
058     */
059    public static final DisplaySetting DISPLAY_OPTIONAL_CHILD_GROUP =
060        new DisplaySetting("DISPLAY_OPTIONAL_CHILD_GROUP");
061
062    /**
063     * Indicates that property options should be included
064     */
065    public static final DisplaySetting DISPLAY_PROPERTY_OPTION =
066        new DisplaySetting("DISPLAY_PROPERTY_OPTION");
067
068    /**
069     * Indicates that switches should be included enabled
070     */
071    public static final DisplaySetting DISPLAY_SWITCH_ENABLED =
072        new DisplaySetting("DISPLAY_SWITCH_ENABLED");
073
074    /**
075     * Indicates that switches should be included disabled
076     */
077    public static final DisplaySetting DISPLAY_SWITCH_DISABLED =
078        new DisplaySetting("DISPLAY_SWITCH_DISABLED");
079
080    /**
081     * Indicates that group names should be included
082     */
083    public static final DisplaySetting DISPLAY_GROUP_NAME =
084        new DisplaySetting("DISPLAY_GROUP_NAME");
085
086    /**
087     * Indicates that groups should be included expanded
088     */
089    public static final DisplaySetting DISPLAY_GROUP_EXPANDED =
090        new DisplaySetting("DISPLAY_GROUP_EXPANDED");
091
092    /**
093     * Indicates that group arguments should be included
094     */
095    public static final DisplaySetting DISPLAY_GROUP_ARGUMENT =
096        new DisplaySetting("DISPLAY_GROUP_ARGUMENT");
097
098    /**
099     * Indicates that group outer brackets should be included
100     */
101    public static final DisplaySetting DISPLAY_GROUP_OUTER =
102        new DisplaySetting("DISPLAY_GROUP_OUTER");
103
104    /**
105     * Indicates that arguments should be included numbered
106     */
107    public static final DisplaySetting DISPLAY_ARGUMENT_NUMBERED =
108        new DisplaySetting("DISPLAY_ARGUMENT_NUMBERED");
109
110    /**
111     * Indicates that arguments should be included bracketed
112     */
113    public static final DisplaySetting DISPLAY_ARGUMENT_BRACKETED =
114        new DisplaySetting("DISPLAY_ARGUMENT_BRACKETED");
115
116    /**
117     * Indicates that arguments of Parents should be included
118     */
119    public static final DisplaySetting DISPLAY_PARENT_ARGUMENT =
120        new DisplaySetting("DISPLAY_PARENT_ARGUMENT");
121
122    /**
123     * Indicates that children of Parents should be included
124     */
125    public static final DisplaySetting DISPLAY_PARENT_CHILDREN =
126        new DisplaySetting("DISPLAY_PARENT_CHILDREN");
127
128    /**
129     * The name of the setting
130     */
131    private final String name;
132
133    /**
134     * The hashCode of the setting
135     */
136    private final int hashCode;
137
138    /**
139     * Creates a new DisplaySetting with the specified name
140     * @param name the name of the setting
141     */
142    private DisplaySetting(final String name) {
143        this.name = name;
144        this.hashCode = name.hashCode();
145        all.add(this);
146    }
147
148    public int hashCode() {
149        return hashCode;
150    }
151
152    public boolean equals(final Object that) {
153        if (that instanceof DisplaySetting) {
154            return name.compareTo(that.toString()) == 0;
155        }
156        return false;
157    }
158
159    public String toString() {
160        return name;
161    }
162}