2aaf8ad9 by Nathan Lighthart

Update ages to latest jcf version

- Update jcf library
- Adjust ages for jcf changes
1 parent 420cebd3
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -5,7 +5,7 @@ import annotations.Range;
import gov.usda.jcf.annotations.Description;
import gov.usda.jcf.annotations.Units;
import gov.usda.jcf.core.Context;
import gov.usda.jcf.util.conversion.TypeConverters;
import gov.usda.jcf.util.conversion.TypeConversions;
import java.io.BufferedReader;
import java.io.IOException;
import java.lang.reflect.Field;
......@@ -1200,7 +1200,7 @@ public class AgESParameters {
}
private void setParameter(Field field, Object rawValue) throws IllegalArgumentException, IllegalAccessException {
Object value = TypeConverters.INSTANCE.convert(rawValue, field.getType());
Object value = TypeConversions.INSTANCE.convert(rawValue, field.getType());
field.setAccessible(true);
field.set(this, value);
}
......@@ -2256,7 +2256,7 @@ public class AgESParameters {
if (type == null) {
context.put(name, rawValue);
} else {
Object value = TypeConverters.INSTANCE.convert(rawValue, type);
Object value = TypeConversions.INSTANCE.convert(rawValue, type);
context.put(name, value, type);
}
}
......
......@@ -22,7 +22,7 @@
package io;
import gov.usda.jcf.core.Context;
import gov.usda.jcf.util.conversion.TypeConverters;
import gov.usda.jcf.util.conversion.TypeConversions;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Array;
......@@ -117,7 +117,7 @@ public class OutputWriter {
str.append(']');
return str.toString();
}
return TypeConverters.INSTANCE.convert(object, String.class);
return TypeConversions.INSTANCE.convert(object, String.class);
}
private static Class<?> getType(Object object) {
......
......@@ -22,7 +22,7 @@
package io;
import gov.usda.jcf.core.Context;
import gov.usda.jcf.util.conversion.TypeConverters;
import gov.usda.jcf.util.conversion.TypeConversions;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
......@@ -156,7 +156,7 @@ public class ParameterOverrideReader {
private void setValue(Context hruContext, String parameter, String value) {
Class<?> parameterType = parameterMap.get(parameter);
Object typedValue = TypeConverters.INSTANCE.convert(value, parameterType);
Object typedValue = TypeConversions.INSTANCE.convert(value, parameterType);
try {
hruContext.put(parameter, typedValue, parameterType);
} catch (IllegalArgumentException ex) {
......
......@@ -5,7 +5,7 @@
*/
package io;
import gov.usda.jcf.util.conversion.TypeConverters;
import gov.usda.jcf.util.conversion.TypeConversions;
import java.io.IOException;
import java.lang.reflect.Array;
import java.nio.file.Path;
......@@ -286,7 +286,7 @@ public class ParameterTableReader {
} else if (LocalTime.class == clazz) {
return parseLocalTime(s);
} else {
return TypeConverters.INSTANCE.convert(s, clazz);
return TypeConversions.INSTANCE.convert(s, clazz);
}
}
......
......@@ -2,7 +2,7 @@
package io;
import gov.usda.jcf.core.Context;
import gov.usda.jcf.util.conversion.TypeConverters;
import gov.usda.jcf.util.conversion.TypeConversions;
import java.io.IOException;
import java.nio.file.Path;
import java.util.HashSet;
......@@ -47,7 +47,7 @@ public class SpatialParameterReader {
}
// Make sure ID is an int
int id = TypeConverters.INSTANCE.convert(idObject, int.class);
int id = TypeConversions.INSTANCE.convert(idObject, int.class);
// Check if ID is a duplicate
if (!idSet.add(id)) {
......
......@@ -2,7 +2,7 @@
package io;
import gov.usda.jcf.core.Context;
import gov.usda.jcf.util.conversion.TypeConverters;
import gov.usda.jcf.util.conversion.TypeConversions;
import java.io.IOException;
import java.nio.file.Path;
import java.time.LocalDate;
......@@ -113,7 +113,7 @@ public class TemporalParameterReader {
throw new RuntimeException("Missing time on data row " + rowCount);
}
return TypeConverters.INSTANCE.convert(timeObject, LocalDate.class);
return TypeConversions.INSTANCE.convert(timeObject, LocalDate.class);
}
private void readIntoContext(Map<String, Object> data) {
......
......@@ -5,7 +5,7 @@
*/
package lib;
import gov.usda.jcf.util.conversion.TypeConverters;
import gov.usda.jcf.util.conversion.TypeConversions;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
......@@ -15,93 +15,93 @@ import java.util.List;
* @author Nathan.Lighthart
*/
public class ArrayValueParser {
public static <T> T parseArray(String s, Class<T> clazz) {
List<Object> list = parseArrayList(s);
T array = convertToArray(list, clazz);
return array;
}
public static <T> T parseArray(String s, Class<T> clazz) {
List<Object> list = parseArrayList(s);
T array = convertToArray(list, clazz);
return array;
}
private static List<Object> parseArrayList(String s) {
if (s == null || "".equals(s)) {
return new ArrayList<>();
}
private static List<Object> parseArrayList(String s) {
if (s == null || "".equals(s)) {
return new ArrayList<>();
}
final char[] chars = s.toCharArray();
if (chars[0] != '[') {
throw new IllegalArgumentException("Invalid array syntax: missing starting '['");
}
final char[] chars = s.toCharArray();
if (chars[0] != '[') {
throw new IllegalArgumentException("Invalid array syntax: missing starting '['");
}
List<Object> list = new ArrayList<>();
parseList(chars, 1, list);
List<Object> list = new ArrayList<>();
parseList(chars, 1, list);
return list;
}
return list;
}
private static <T> T convertToArray(List<?> list, Class<T> clazz) {
Class<?> componentType = clazz.getComponentType();
Object array = Array.newInstance(componentType, list.size());
for (int i = 0; i < list.size(); ++i) {
Array.set(array, i, convertValue(list.get(i), componentType));
}
return clazz.cast(array);
}
private static <T> T convertToArray(List<?> list, Class<T> clazz) {
Class<?> componentType = clazz.getComponentType();
Object array = Array.newInstance(componentType, list.size());
for (int i = 0; i < list.size(); ++i) {
Array.set(array, i, convertValue(list.get(i), componentType));
}
return clazz.cast(array);
}
private static <T> T convertValue(Object value, Class<T> clazz) {
if (clazz.isArray()) {
return convertToArray((List<?>) value, clazz);
} else {
return TypeConverters.INSTANCE.convert(value, clazz);
}
}
private static <T> T convertValue(Object value, Class<T> clazz) {
if (clazz.isArray()) {
return convertToArray((List<?>) value, clazz);
} else {
return TypeConversions.INSTANCE.convert(value, clazz);
}
}
private static int parseList(final char[] chars, int index, List<Object> list) {
// empty list
if (chars[index] == ']') {
return index + 1;
} else {
CharLoop:
while (index < chars.length) {
index = parseValue(chars, index, list);
switch (chars[index]) {
case ',':
++index;
while (Character.isWhitespace(chars[index])) {
++index;
}
break;
case ']':
break CharLoop;
default:
throw new IllegalArgumentException("Error parsing at: " + index);
}
}
}
private static int parseList(final char[] chars, int index, List<Object> list) {
// empty list
if (chars[index] == ']') {
return index + 1;
} else {
CharLoop:
while (index < chars.length) {
index = parseValue(chars, index, list);
switch (chars[index]) {
case ',':
++index;
while (Character.isWhitespace(chars[index])) {
++index;
}
break;
case ']':
break CharLoop;
default:
throw new IllegalArgumentException("Error parsing at: " + index);
}
}
}
return index;
}
return index;
}
private static int parseValue(final char[] chars, int index, List<Object> list) {
if (chars[index] == '[') {
List<Object> innerList = new ArrayList<>();
list.add(innerList);
index = parseList(chars, index + 1, innerList);
++index;
} else {
int startIndex = index;
while (index < chars.length
&& chars[index] != ','
&& chars[index] != ']') {
++index;
}
private static int parseValue(final char[] chars, int index, List<Object> list) {
if (chars[index] == '[') {
List<Object> innerList = new ArrayList<>();
list.add(innerList);
index = parseList(chars, index + 1, innerList);
++index;
} else {
int startIndex = index;
while (index < chars.length
&& chars[index] != ','
&& chars[index] != ']') {
++index;
}
if (index == chars.length) {
throw new IllegalArgumentException("Invalid array syntax: missing: missing end ]");
}
if (index == chars.length) {
throw new IllegalArgumentException("Invalid array syntax: missing: missing end ]");
}
String value = new String(chars, startIndex, index - startIndex);
list.add(value);
}
String value = new String(chars, startIndex, index - startIndex);
list.add(value);
}
return index;
}
return index;
}
}
......
......@@ -3,7 +3,7 @@ package weighting;
import gov.usda.jcf.core.Context;
import gov.usda.jcf.util.conversion.TypeConversionException;
import gov.usda.jcf.util.conversion.TypeConverters;
import gov.usda.jcf.util.conversion.TypeConversions;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashSet;
......@@ -157,7 +157,7 @@ public class CatchmentAggregator {
}
return array;
} else {
double d = TypeConverters.INSTANCE.convert(value, double.class);
double d = TypeConversions.INSTANCE.convert(value, double.class);
return d * weight;
}
}
......@@ -193,7 +193,7 @@ public class CatchmentAggregator {
private void AddToAverages(List<AverageAggregator> averages, Object value, int index) {
double d;
try {
d = TypeConverters.INSTANCE.convert(value, double.class);
d = TypeConversions.INSTANCE.convert(value, double.class);
} catch (TypeConversionException ex) {
return;
}
......
......@@ -5,7 +5,7 @@ import ages.types.HRU;
import gov.usda.jcf.core.Context;
import gov.usda.jcf.core.contexts.CombinedContext;
import gov.usda.jcf.core.contexts.MapContext;
import gov.usda.jcf.util.conversion.TypeConverters;
import gov.usda.jcf.util.conversion.TypeConversions;
import java.lang.reflect.Array;
import java.util.HashSet;
import java.util.List;
......@@ -96,7 +96,7 @@ public class HRUAreaWeigher {
}
return array;
} else {
double d = TypeConverters.INSTANCE.convert(value, double.class);
double d = TypeConversions.INSTANCE.convert(value, double.class);
return d / area;
}
}
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!