blob: 286d74a6684db6e36f2b147284003b768ebb18d2 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.skynet.core.attribute;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Strings;
/**
* @author Ryan D. Brooks
*/
public class FloatingPointAttribute extends CharacterBackedAttribute<Double> {
private static final Double DEFAULT_DOUBLE = Double.MIN_VALUE;
@Override
public Double getValue() throws OseeCoreException {
return (Double) getAttributeDataProvider().getValue();
}
@Override
public boolean subClassSetValue(Double value) throws OseeCoreException {
if (value == null) {
throw new OseeArgumentException("Attribute value was null");
}
return getAttributeDataProvider().setValue(value);
}
@Override
public Double convertStringToValue(String value) {
Double toReturn = null;
if (isValidDouble(value)) {
toReturn = Double.valueOf(value);
} else {
toReturn = getDefaultValue();
}
return toReturn;
}
public Double getDefaultValue() {
Double toReturn = DEFAULT_DOUBLE;
String defaultValue = getAttributeType().getDefaultValue();
if (isValidDouble(defaultValue)) {
toReturn = Double.valueOf(defaultValue);
}
return toReturn;
}
private boolean isValidDouble(String value) {
boolean result = false;
if (Strings.isValid(value)) {
try {
Double.parseDouble(value);
result = true;
} catch (NumberFormatException ex) {
// Do Nothing;
}
}
return result;
}
}