001    package org.bukkit;
002    
003    import java.util.Map;
004    
005    import com.google.common.collect.Maps;
006    
007    /**
008     * Represents the different growth states of crops
009     */
010    public enum CropState {
011    
012        /**
013         * State when first seeded
014         */
015        SEEDED(0x0),
016        /**
017         * First growth stage
018         */
019        GERMINATED(0x1),
020        /**
021         * Second growth stage
022         */
023        VERY_SMALL(0x2),
024        /**
025         * Third growth stage
026         */
027        SMALL(0x3),
028        /**
029         * Fourth growth stage
030         */
031        MEDIUM(0x4),
032        /**
033         * Fifth growth stage
034         */
035        TALL(0x5),
036        /**
037         * Almost ripe stage
038         */
039        VERY_TALL(0x6),
040        /**
041         * Ripe stage
042         */
043        RIPE(0x7);
044    
045        private final byte data;
046        private final static Map<Byte, CropState> BY_DATA = Maps.newHashMap();
047    
048        private CropState(final int data) {
049            this.data = (byte) data;
050        }
051    
052        /**
053         * Gets the associated data value representing this growth state
054         *
055         * @return A byte containing the data value of this growth state
056         * @deprecated Magic value
057         */
058        @Deprecated
059        public byte getData() {
060            return data;
061        }
062    
063        /**
064         * Gets the CropState with the given data value
065         *
066         * @param data Data value to fetch
067         * @return The {@link CropState} representing the given value, or null if
068         *     it doesn't exist
069         * @deprecated Magic value
070         */
071        @Deprecated
072        public static CropState getByData(final byte data) {
073            return BY_DATA.get(data);
074        }
075    
076        static {
077            for (CropState cropState : values()) {
078                BY_DATA.put(cropState.getData(), cropState);
079            }
080        }
081    }