    001    /**
    002     * This software is provided under the terms of the Minecraft Forge Public
    003     * License v1.0.
    004     */
    005
    006    package net.minecraftforge.common;
    007
    008    public class Property
    009    {
    010        public enum Type
    011        {
    012            STRING,
    013            INTEGER,
    014            BOOLEAN
    015        }
    016
    017        private String name;
    018        public String value;
    019        public String comment;
    020        private Type type; //Currently does nothing, need to design a way to save/load from the file.
    021
    022        public Property(){}
    023
    024        public Property(String name, String value, Type type)
    025        {
    026            setName(name);
    027            this.value = value;
    028            this.type = type;
    029        }
    030
    031        /**
    032         * Returns the value in this property as a integer,
    033         * if the value is not a valid integer, it will return -1.
    034         *
    035         * @return The value
    036         */
    037        public int getInt()
    038        {
    039            return getInt(-1);
    040        }
    041
    042        /**
    043         * Returns the value in this property as a integer,
    044         * if the value is not a valid integer, it will return the
    045         * provided default.
    046         *
    047         * @param _default The default to provide if the current value is not a valid integer
    048         * @return The value
    049         */
    050        public int getInt(int _default)
    051        {
    052            try
    053            {
    054                return Integer.parseInt(value);
    055            }
    056            catch (NumberFormatException e)
    057            {
    058                return _default;
    059            }
    060        }
    061
    062        /**
    063         * Checks if the current value stored in this property can be converted to an integer.
    064         * @return True if the vslue can be converted to an integer
    065         */
    066        public boolean isIntValue()
    067        {
    068            try
    069            {
    070                Integer.parseInt(value);
    071                return true;
    072            }
    073            catch (NumberFormatException e)
    074            {
    075                return false;
    076            }
    077        }
    078
    079        /**
    080         * Returns the value in this property as a boolean,
    081         * if the value is not a valid boolean, it will return the
    082         * provided default.
    083         *
    084         * @param _default The default to provide
    085         * @return The value as a boolean, or the default
    086         */
    087        public boolean getBoolean(boolean _default)
    088        {
    089            if (isBooleanValue())
    090            {
    091                return Boolean.parseBoolean(value);
    092            }
    093            else
    094            {
    095                return _default;
    096            }
    097        }
    098
    099        /**
    100         * Checks if the current value held by this property is a valid boolean value.
    101         * @return True if it is a boolean value
    102         */
    103        public boolean isBooleanValue()
    104        {
    105            return ("true".equals(value.toLowerCase()) || "false".equals(value.toLowerCase()));
    106        }
    107
    108        public String getName()
    109        {
    110            return name;
    111        }
    112
    113        public void setName(String name)
    114        {
    115            this.name = name;
    116        }
    117    }