You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2016/05/25 13:59:16 UTC

svn commit: r1745489 - /uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/Misc.java

Author: schor
Date: Wed May 25 13:59:16 2016
New Revision: 1745489

URL: http://svn.apache.org/viewvc?rev=1745489&view=rev
Log:
[UIMA-4674] add trivial conversion of iterator to iterable, support convert to next higher power of 2^x, add formatter for stack trace record

Modified:
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/Misc.java

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/Misc.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/Misc.java?rev=1745489&r1=1745488&r2=1745489&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/Misc.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/Misc.java Wed May 25 13:59:16 2016
@@ -30,6 +30,7 @@ import java.lang.ref.WeakReference;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 import java.util.WeakHashMap;
 import java.util.function.Consumer;
@@ -82,6 +83,10 @@ public class Misc {
     String n = e.getClassName();
     return n.substring(1 + n.lastIndexOf('.')) + "." + e.getMethodName() + "[" + e.getLineNumber() + "]";
   }
+  
+  public static String formatcaller(String className, String methodName, int lineNumber) {
+    return className.substring(1 + className.lastIndexOf('.')) + "." + methodName + "[" + lineNumber + "]";
+  }
 
   public static String elide(String s, int n) {
     return elide(s, n, true);
@@ -191,6 +196,12 @@ public class Misc {
     return (i < 1) ? 1 : Integer.highestOneBit(i) << ( (Integer.bitCount(i) == 1 ? 0 : 1));
   }
   
+  /**
+   * Convert an int argument to the next higher power of 2 to the x power
+   * @param i the value to convert
+   * @param x the power of 2 to use
+   * @return the next higher power of 2 to the x, or i if it is already == to 2 to the x
+   */
   static public int nextHigherPowerOfX(int i, int x) {
     int shft = 31 - Integer.numberOfLeadingZeros(x);  // x == 8, shft = 3
     return (i < 1) ? x : ((i+(x - 1)) >>> shft) << shft;
@@ -488,6 +499,14 @@ public class Misc {
     }
   }
   
+  public static <T> Iterable<T> iterable(Iterator<T> iterator) {
+    return new Iterable<T>() {
+      @Override
+      public Iterator<T> iterator() {
+        return iterator;
+      }
+    };
+  }
 //private static final Function<String, Class> uimaSystemFindLoadedClass;
 //static {
 //  try {