001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.migration.model22.other;
023:
024: /**
025: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
026: * @version $Revision: 8784 $
027: */
028: public class FloatValue extends Value {
029:
030: /** The Float array. */
031: private Float[] values;
032:
033: public FloatValue() {
034: this ((Float) null);
035: }
036:
037: public FloatValue(Float integer) {
038: this (new Float[] { integer });
039: }
040:
041: public FloatValue(float _value) {
042: this (new float[] { _value });
043: }
044:
045: public FloatValue(String value) {
046: this (new String[] { value });
047: }
048:
049: public FloatValue(Float[] values) {
050: if (values == null) {
051: throw new IllegalArgumentException();
052: }
053: this .values = values;
054: }
055:
056: public FloatValue(float[] _values) {
057: if (_values == null) {
058: throw new IllegalArgumentException();
059: }
060: values = new Float[_values.length];
061: for (int i = 0; i < _values.length; i++) {
062: values[i] = new Float(_values[i]);
063: }
064: }
065:
066: public FloatValue(String[] values) throws IllegalArgumentException {
067: if (values == null) {
068: throw new IllegalArgumentException();
069: }
070: try {
071: this .values = new Float[values.length];
072: for (int i = 0; i < values.length; i++) {
073: String value = values[i];
074: if (value != null) {
075: this .values[i] = new Float(value);
076: }
077: }
078: } catch (NumberFormatException e) {
079: throw new IllegalArgumentException();
080: }
081: }
082:
083: public boolean isInstanceOf(Class clazz) {
084: return clazz != null && clazz.isAssignableFrom(Integer.class);
085: }
086:
087: public String[] asStringArray() {
088: try {
089: return Helper.toStringArray(values, Helper.FLOAT_CONVERTER);
090: } catch (ConversionException impossible) {
091: throw new Error(impossible);
092: }
093: }
094:
095: public String asString() {
096: if (isNull()) {
097: return null;
098: }
099: return values[0].toString();
100: }
101:
102: public Object[] asObjectArray() {
103: return values;
104: }
105: }
|