diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libjava/classpath/javax/management/openmbean/SimpleType.java | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libjava/classpath/javax/management/openmbean/SimpleType.java')
-rw-r--r-- | libjava/classpath/javax/management/openmbean/SimpleType.java | 350 |
1 files changed, 350 insertions, 0 deletions
diff --git a/libjava/classpath/javax/management/openmbean/SimpleType.java b/libjava/classpath/javax/management/openmbean/SimpleType.java new file mode 100644 index 000000000..81b991bdf --- /dev/null +++ b/libjava/classpath/javax/management/openmbean/SimpleType.java @@ -0,0 +1,350 @@ +/* SimpleType.java -- Open type descriptor for the base types. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.management.openmbean; + +import java.io.InvalidObjectException; +import java.io.ObjectStreamException; + +import java.math.BigDecimal; +import java.math.BigInteger; + +import java.util.Date; + +import javax.management.ObjectName; + +/** + * The open type descriptor for data values that are members + * of one of the simple types (such as an integer or a string). + * The other open types ({@link ArrayType}, {@link CompositeType}, + * {@link TabularType}) are constructed from one or more of these + * types. The simple types are formed from a small subset of + * basic Java types. As a result, the valid instances of this + * class are predefined, and no constructor is given for creating + * new instances. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public final class SimpleType<T> + extends OpenType<T> +{ + + /** + * The {@link SimpleType} representation of + * <code>java.math.BigDecimal</code>. + */ + public static final SimpleType<BigDecimal> BIGDECIMAL; + + /** + * The {@link SimpleType} representation of + * <code>java.math.BigInteger</code>. + */ + public static final SimpleType<BigInteger> BIGINTEGER; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Boolean</code>. + */ + public static final SimpleType<Boolean> BOOLEAN; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Byte</code>. + */ + public static final SimpleType<Byte> BYTE; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Character</code>. + */ + public static final SimpleType<Character> CHARACTER; + + /** + * The {@link SimpleType} representation of + * <code>java.util.Date</code>. + */ + public static final SimpleType<Date> DATE; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Double</code>. + */ + public static final SimpleType<Double> DOUBLE; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Float</code>. + */ + public static final SimpleType<Float> FLOAT; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Integer</code>. + */ + public static final SimpleType<Integer> INTEGER; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Long</code>. + */ + public static final SimpleType<Long> LONG; + + /** + * The {@link SimpleType} representation of + * <code>javax.management.ObjectName</code>. + */ + public static final SimpleType<ObjectName> OBJECTNAME; + + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Short</code>. + */ + public static final SimpleType<Short> SHORT; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.String</code>. + */ + public static final SimpleType<String> STRING; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Void</code>. + */ + public static final SimpleType<Void> VOID; + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 2215577471957694503L; + + /** + * The hash code of this instance. + */ + private transient Integer hashCode; + + /** + * The <code>toString()</code> result of this instance. + */ + private transient String string; + + /** + * Static construction of the {@link SimpleType} instances. + */ + static + { + try + { + BIGDECIMAL = new SimpleType<BigDecimal>("java.math.BigDecimal"); + BIGINTEGER = new SimpleType<BigInteger>("java.math.BigInteger"); + BOOLEAN = new SimpleType<Boolean>("java.lang.Boolean"); + BYTE = new SimpleType<Byte>("java.lang.Byte"); + CHARACTER = new SimpleType<Character>("java.lang.Character"); + DATE = new SimpleType<Date>("java.util.Date"); + DOUBLE = new SimpleType<Double>("java.lang.Double"); + FLOAT = new SimpleType<Float>("java.lang.Float"); + INTEGER = new SimpleType<Integer>("java.lang.Integer"); + LONG = new SimpleType<Long>("java.lang.Long"); + OBJECTNAME = + new SimpleType<ObjectName>("javax.management.ObjectName"); + SHORT = new SimpleType<Short>("java.lang.Short"); + STRING = new SimpleType<String>("java.lang.String"); + VOID = new SimpleType<Void>("java.lang.Void"); + } + catch (OpenDataException e) + { + /* In normal circumstances, this shouldn't be possible. */ + throw new IllegalStateException("A invalid class name " + + "was passed to the SimpleType " + + "constructor.", e); + } + } + + /** + * Constructs a new {@link SimpleType} instance for the given + * class name. The class name is also used as the type name + * and description of the {@link OpenType} instance. + * + * @param name the name of the class this instance should + * represent. + * @throws OpenDataException if somehow the constructor of the + * superclass is passed an invalid + * class name. + */ + private SimpleType(String name) + throws OpenDataException + { + super(name, name, name); + } + + /** + * <p> + * Compares this simple data type with another object + * for equality. The objects are judged to be equal if: + * </p> + * <ul> + * <li><code>obj</code> is not null.</li> + * <li><code>obj</code> is an instance of + * {@link SimpleType}.</li> + * <li>The class names are equal.</li> + * </ul> + * + * @param obj the object to compare with. + * @return true if the conditions above hold. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof SimpleType)) + return false; + SimpleType<?> sType = (SimpleType<?>) obj; + return sType.getClassName().equals(getClassName()); + } + + /** + * <p> + * Returns the hash code of the simple data type. + * This is simply the hash code of the class name, + * which is the same element of the type compared + * as part of the + * {@link #equals(java.lang.Object)} method, thus ensuring + * that the hashcode is compatible with the equality + * test. + * </p> + * <p> + * As instances of this class are immutable, the hash code + * is computed just once for each instance and reused + * throughout its life. + * </p> + * + * @return the hash code of this instance. + */ + public int hashCode() + { + if (hashCode == null) + hashCode = Integer.valueOf(getClassName().hashCode()); + return hashCode.intValue(); + } + + /** + * Returns true if the specified object is a member of this + * simple type. The object is judged to be so if it is + * non-null and its class name is the same as that returned + * by {@link SimpleType#getClassName()}. + * + * @param obj the object to test for membership. + * @return true if the object is a member of this type. + */ + public boolean isValue(Object obj) + { + if (obj == null) + return false; + return obj.getClass().getName().equals(getClassName()); + } + + /** + * Replaces instances of this class read from an + * {@link java.io.ObjectInputStream} with one of the predefined + * values. This ensures that each existing instance of + * this class is one of these unique instances. + * + * @return the replacement object. + * @throws ObjectStreamException if the object can not be + * resolved. + */ + public Object readResolve() + throws ObjectStreamException + { + if (equals(BIGDECIMAL)) + return BIGDECIMAL; + if (equals(BIGINTEGER)) + return BIGINTEGER; + if (equals(BOOLEAN)) + return BOOLEAN; + if (equals(BYTE)) + return BYTE; + if (equals(CHARACTER)) + return CHARACTER; + if (equals(DATE)) + return DATE; + if (equals(DOUBLE)) + return DOUBLE; + if (equals(FLOAT)) + return FLOAT; + if (equals(INTEGER)) + return INTEGER; + if (equals(LONG)) + return LONG; + if (equals(OBJECTNAME)) + return OBJECTNAME; + if (equals(SHORT)) + return SHORT; + if (equals(STRING)) + return STRING; + if (equals(VOID)) + return VOID; + throw new InvalidObjectException("Invalid simple type instance " + + "deserialized."); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.SimpleType</code>) + * and the name of the class the type represents. + * </p> + * <p> + * As instances of this class are immutable, the return value + * is computed just once for each instance and reused + * throughout its life. + * </p> + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + public String toString() + { + if (string == null) + string = getClass().getName() + + "[name=" + getClassName() + + "]"; + return string; + } + +} |