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.event;
019    
020    import java.util.HashMap;
021    import java.util.Map;
022    
023    /**
024     * Enumerates instrument types.
025     */
026    public enum InstrumentEnum {
027            /** Stock */
028            STOCK(1),
029    
030            /** Index */
031            INDEX(2),
032    
033            /** Option */
034            OPTION(3),
035    
036            /** Future */
037            FUTURE(4),
038            
039            /** Single Stock Future */
040            SSFUTURE(5);
041    
042            public final int code;
043            
044            private InstrumentEnum(int code) {
045                    this.code = code;
046            }
047            
048            public final static Map<Integer,InstrumentEnum> decoder
049                            = new HashMap<Integer,InstrumentEnum>();
050            static {
051                    InstrumentEnum []v = values();
052                    
053                    for(int i = 0; i < v.length; i++) {
054                            if(decoder.put(v[i].code, v[i]) != null) {
055                                    throw new AssertionError("duplicate code in: " + v[i]);
056                            }
057                    }
058            }
059    }