Author: schor Date: Wed Nov 4 14:42:12 2015 New Revision: 1712556 URL: http://svn.apache.org/viewvc?rev=1712556&view=rev Log: [UIMA-4674] add setWithExpand for lists, change getStaticIntField to not throw if not found
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/util/Misc.java Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/util/Misc.java URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/util/Misc.java?rev=1712556&r1=1712555&r2=1712556&view=diff ============================================================================== --- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/util/Misc.java (original) +++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/util/Misc.java Wed Nov 4 14:42:12 2015 @@ -29,10 +29,9 @@ import java.lang.invoke.MethodHandles.Lo import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Collection; +import java.util.List; import java.util.function.Consumer; -import org.apache.uima.cas.impl.TypeImpl; - public class Misc { public final static MethodHandles.Lookup UIMAlookup = MethodHandles.lookup(); @@ -175,15 +174,22 @@ public class Misc { } } + /** + * Gets an int from a named field. + * If the field isn't present, returns Integer.MIN_VALUE; + * @param clazz the class where the field is + * @param fieldName the name of the field + * @return the value or Integer.MIN_VALUE if not present + */ static public int getStaticIntField(Class<?> clazz, String fieldName) { try { - Field f; - - f = clazz.getField(fieldName); - return f.getInt(null); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + Field f = clazz.getField(fieldName); + return f.getInt(null); + } catch (NoSuchFieldException e) { + return Integer.MIN_VALUE; + } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { throw new RuntimeException(e); - } + } } static public void addAll(Collection<String> c, String ... v) { @@ -226,6 +232,12 @@ public class Misc { return h1; } + public static <T> void setWithExpand(List<T> a, int i, T value) { + while (i >= a.size()) { + a.add(null); + } + a.set(i, value); + } //private static final Function<String, Class> uimaSystemFindLoadedClass; //static {