001 /**
002 * Copyright 2007 Mike Kroutikov.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the Lesser GNU General Public License as
006 * published by the Free Software Foundation; either version 3 of
007 * the License, or (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 * Lesser GNU General Public License for more details.
013 *
014 * You should have received a copy of the Lesser GNU General Public License
015 * along with this program. If not, see <http://www.gnu.org/licenses/>.
016 */
017
018 package org.otfeed.command;
019
020 import java.util.EnumSet;
021 import java.util.Set;
022 import java.util.Collections;
023
024 /**
025 * Enumerates symbol types.
026 * <p/>
027 * See also: {@link org.otfeed.event.OTSymbol}.
028 */
029 public enum ListSymbolEnum {
030
031 /** Stock */
032 STOCK (0x01),
033
034 /** Index */
035 INDEX (0x02),
036
037 /** Option */
038 OPTION (0x04),
039
040 /** Future */
041 FUTURE (0x08),
042
043 /** Single stock future */
044 SSFUTURE (0x10),
045
046 /** Top ten */
047 TOP_TEN (0x20);
048
049 public static final int CONTAINS_FLAG = 0x20000;
050
051 public final int code;
052
053 private ListSymbolEnum(int code) {
054 this.code = code;
055 }
056
057 /**
058 * Allows caller to build a set from a list of ListSymbolEnum values.
059 * <p>
060 * Example:
061 * <pre>
062 * Set<ListSymbolEnum> indexAndOption = ListSymbolEnum.combine(
063 * ListSymbolEnum.INDEX, ListSymbolEnum.OPTION);
064 * </pre>
065 *
066 * @param symbol list of symbol types.
067 * @throws IllegalArgumentException if same symbol type appears more
068 * than once in the parameter list.
069 */
070 public static final Set<ListSymbolEnum> combine(ListSymbolEnum ... symbol) {
071 Set<ListSymbolEnum> set = EnumSet.noneOf(ListSymbolEnum.class);
072
073 for(int i = 0; i < symbol.length; i++) {
074 if(set.add(symbol[i]) == false) {
075 throw new IllegalArgumentException(
076 "dumplicate symbol: " + symbol[i]);
077 }
078 }
079
080 return Collections.unmodifiableSet(set);
081 }
082
083 /**
084 * Set of all possible symbol types.
085 */
086 public static final Set<ListSymbolEnum> ALL
087 = combine(STOCK, INDEX, OPTION, SSFUTURE, TOP_TEN);
088 }