m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/pl/edu/mimuw/cloudatlas/model/ValueString.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/pl/edu/mimuw/cloudatlas/model/ValueString.java')
-rw-r--r--src/pl/edu/mimuw/cloudatlas/model/ValueString.java168
1 files changed, 84 insertions, 84 deletions
diff --git a/src/pl/edu/mimuw/cloudatlas/model/ValueString.java b/src/pl/edu/mimuw/cloudatlas/model/ValueString.java
index 34af8d1..e6fe9dd 100644
--- a/src/pl/edu/mimuw/cloudatlas/model/ValueString.java
+++ b/src/pl/edu/mimuw/cloudatlas/model/ValueString.java
@@ -33,88 +33,88 @@ import pl.edu.mimuw.cloudatlas.model.ValueString;
* A class that wraps a Java <code>String</code> object.
*/
public class ValueString extends ValueSimple<String> {
- /**
- * A result of conversion values representing null to <code>ValueString</code>.
- */
- protected static final ValueString NULL_STRING = new ValueString("NULL");
-
- /**
- * Constructs a new <code>ValueString</code> object wrapping the specified <code>value</code>.
- *
- * @param value the value to wrap
- */
- public ValueString(String value) {
- super(value);
- }
-
- @Override
- public Type getType() {
- return TypePrimitive.STRING;
- }
-
- @Override
- public Value getDefaultValue() {
- return new ValueString("");
- }
-
- @Override
- public ValueBoolean isLowerThan(Value value) {
- sameTypesOrThrow(value, Operation.COMPARE);
- if(isNull() || value.isNull())
- return new ValueBoolean(null);
- return new ValueBoolean(getValue().compareTo(((ValueString)value).getValue()) < 0);
- }
-
- @Override
- public ValueString addValue(Value value) {
- sameTypesOrThrow(value, Operation.ADD);
- if(isNull() || value.isNull())
- return new ValueString(null);
- return new ValueString(getValue().concat(((ValueString)value).getValue()));
- }
-
- @Override
- public ValueBoolean regExpr(Value value) {
- sameTypesOrThrow(value, Operation.REG_EXPR);
- if(isNull() || value.isNull())
- return new ValueBoolean(null);
- return new ValueBoolean(getValue().matches(((ValueString)value).getValue()));
- }
-
- @Override
- public Value convertTo(Type type) {
- switch(type.getPrimaryType()) {
- case BOOLEAN:
- return new ValueBoolean(Boolean.parseBoolean(getValue()));
- case DOUBLE:
- try {
- return new ValueDouble(Double.parseDouble(getValue()));
- } catch(NumberFormatException exception) {
- return new ValueDouble(null);
- }
- case DURATION:
- return new ValueDuration(getValue());
- case INT:
- try {
- return new ValueInt(Long.parseLong(getValue()));
- } catch(NumberFormatException exception) {
- return new ValueInt(null);
- }
- case STRING:
- return getValue() == null? ValueString.NULL_STRING : this;
- case TIME:
- try {
- return new ValueTime(getValue());
- } catch(ParseException exception) {
- return new ValueTime((Long)null);
- }
- default:
- throw new UnsupportedConversionException(getType(), type);
- }
- }
-
- @Override
- public ValueInt valueSize() {
- return new ValueInt(getValue() == null? null : (long)getValue().length());
- }
+ /**
+ * A result of conversion values representing null to <code>ValueString</code>.
+ */
+ protected static final ValueString NULL_STRING = new ValueString("NULL");
+
+ /**
+ * Constructs a new <code>ValueString</code> object wrapping the specified <code>value</code>.
+ *
+ * @param value the value to wrap
+ */
+ public ValueString(String value) {
+ super(value);
+ }
+
+ @Override
+ public Type getType() {
+ return TypePrimitive.STRING;
+ }
+
+ @Override
+ public Value getDefaultValue() {
+ return new ValueString("");
+ }
+
+ @Override
+ public ValueBoolean isLowerThan(Value value) {
+ sameTypesOrThrow(value, Operation.COMPARE);
+ if(isNull() || value.isNull())
+ return new ValueBoolean(null);
+ return new ValueBoolean(getValue().compareTo(((ValueString)value).getValue()) < 0);
+ }
+
+ @Override
+ public ValueString addValue(Value value) {
+ sameTypesOrThrow(value, Operation.ADD);
+ if(isNull() || value.isNull())
+ return new ValueString(null);
+ return new ValueString(getValue().concat(((ValueString)value).getValue()));
+ }
+
+ @Override
+ public ValueBoolean regExpr(Value value) {
+ sameTypesOrThrow(value, Operation.REG_EXPR);
+ if(isNull() || value.isNull())
+ return new ValueBoolean(null);
+ return new ValueBoolean(getValue().matches(((ValueString)value).getValue()));
+ }
+
+ @Override
+ public Value convertTo(Type type) {
+ switch(type.getPrimaryType()) {
+ case BOOLEAN:
+ return new ValueBoolean(Boolean.parseBoolean(getValue()));
+ case DOUBLE:
+ try {
+ return new ValueDouble(Double.parseDouble(getValue()));
+ } catch(NumberFormatException exception) {
+ return new ValueDouble(null);
+ }
+ case DURATION:
+ return new ValueDuration(getValue());
+ case INT:
+ try {
+ return new ValueInt(Long.parseLong(getValue()));
+ } catch(NumberFormatException exception) {
+ return new ValueInt(null);
+ }
+ case STRING:
+ return getValue() == null? ValueString.NULL_STRING : this;
+ case TIME:
+ try {
+ return new ValueTime(getValue());
+ } catch(ParseException exception) {
+ return new ValueTime((Long)null);
+ }
+ default:
+ throw new UnsupportedConversionException(getType(), type);
+ }
+ }
+
+ @Override
+ public ValueInt valueSize() {
+ return new ValueInt(getValue() == null? null : (long)getValue().length());
+ }
}