/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.uima.util;

import java.util.regex.Pattern;

public class Misc {

  private static final Pattern whitespace = Pattern.compile("\\s");

  public static String replaceWhiteSpace(String s, String replacement) {
    return whitespace.matcher(s).replaceAll(replacement);
  }
  
  
  /**
   * @param s starting frames above invoker
   * @param n max number of callers to return
   * @return  x called by: y ...
   */
  public static StringBuilder getCallers(final int s, final int n) {
    StackTraceElement[] e = Thread.currentThread().getStackTrace();
    StringBuilder sb = new StringBuilder();
    for (int i = s + 2; i < s + n + 3; i++) {
      if (i >= e.length) break;
      if (i != s + 2) {
        sb.append("  called_by: ");
      }
      sb.append(formatcaller(e[i]));      
    }
    return sb;
  }

  /**
   * @return the name of the caller in the stack
   */
  public static String getCaller() {
    StackTraceElement[] e = Thread.currentThread().getStackTrace();
    return formatcaller(e[4]) + "called by: " + formatcaller(e[5]);
  }
  
  private static String formatcaller(StackTraceElement e) {
    String n = e.getClassName();
    return n.substring(1 + n.lastIndexOf('.')) + "." + e.getMethodName() + "[" + e.getLineNumber() + "]";
  }
  

  
  public static final String blanks = "                                                     ";
  public static final String dots = "...";
  
  public static String elide(String s, int n) {
    return elide(s, n, true);
  }
  
  public static String elide(String s, int n, boolean pad) {
    if (s == null) {
      s = "null";
    }
    int sl = s.length();
    if (sl <= n) {
      return s + (pad ? blanks.substring(0, n - sl) : "");
    }
    int dl = 1; // (n < 11) ? 1 : (n < 29) ? 2 : 3;  // number of dots
    int ss = (n - dl) / 2;
    int ss2 = ss + (( ss * 2 == (n - dl)) ? 0 : 1);
    return s.substring(0, ss) + dots.substring(0, dl) + s.substring(sl - ss2);
  }  

  /**
   * 
   * @param name of property
   * @return true if property is defined, or is defined and set to anything 
   * except "false"; false if property is not defined, or is defined and set to
   * "false".
   */
  public static boolean getNoValueSystemProperty(String name) {
    return !System.getProperty(name, "false").equals("false");
  }
  
//  public static void main(String[] args) {
//    System.out.println(elide("uninflectedWord", 11));
//  }
//    System.out.println("should be false - not defined: " + getNoValueSystemProperty("foo"));
//    System.setProperty("foo", "");
//    System.out.println("should be true - defined, 0 len str value: " + getNoValueSystemProperty("foo"));
//    System.setProperty("foo", "true");
//    System.out.println("should be true - defined, true value: " + getNoValueSystemProperty("foo"));
//    System.setProperty("foo", "zzz");
//    System.out.println("should be true - defined, zzz value: " + getNoValueSystemProperty("foo"));
//    System.setProperty("foo", "false");
//    System.out.println("should be false - defined, false value: " + getNoValueSystemProperty("foo"));
//  }
}

@@ -860,1992 +860,29 @@
 %0D%0A%0D%0A
-import java.util.regex.Pattern;%0D%0A%0D%0Apublic class Misc %7B%0D%0A%0D%0A  private static final Pattern whitespace = Pattern.compile(%22%5C%5Cs%22);%0D%0A%0D%0A  public static String replaceWhiteSpace(String s, String replacement) %7B%0D%0A    return whitespace.matcher(s).replaceAll(replacement);%0D%0A  %7D%0D%0A  %0D%0A  %0D%0A  /**%0D%0A   * @param s starting frames above invoker%0D%0A   * @param n max number of callers to return%0D%0A   * @return  x called by: y ...%0D%0A   */%0D%0A  public static StringBuilder getCallers(final int s, final int n) %7B%0D%0A    StackTraceElement%5B%5D e = Thread.currentThread().getStackTrace();%0D%0A    StringBuilder sb = new StringBuilder();%0D%0A    for (int i = s + 2; i %3C s + n + 3; i++) %7B%0D%0A      if (i %3E= e.length) break;%0D%0A      if (i != s + 2) %7B%0D%0A        sb.append(%22  called_by: %22);%0D%0A      %7D%0D%0A      sb.append(formatcaller(e%5Bi%5D));      %0D%0A    %7D%0D%0A    return sb;%0D%0A  %7D%0D%0A%0D%0A  /**%0D%0A   * @return the name of the caller in the stack%0D%0A   */%0D%0A  public static String getCaller() %7B%0D%0A    StackTraceElement%5B%5D e = Thread.currentThread().getStackTrace();%0D%0A    return formatcaller(e%5B4%5D) + %22called by: %22 + formatcaller(e%5B5%5D);%0D%0A  %7D%0D%0A  %0D%0A  private static String formatcaller(StackTraceElement e) %7B%0D%0A    String n = e.getClassName();%0D%0A    return n.substring(1 + n.lastIndexOf('.')) + %22.%22 + e.getMethodName() + %22%5B%22 + e.getLineNumber() + %22%5D%22;%0D%0A  %7D%0D%0A  %0D%0A%0D%0A  %0D%0A  public static final String blanks = %22                                                     %22;%0D%0A  public static final String dots = %22...%22;%0D%0A  %0D%0A  public static String elide(String s, int n) %7B%0D%0A    return elide(s, n, true);%0D%0A  %7D%0D%0A  %0D%0A  public static String elide(String s, int n, boolean pad) %7B%0D%0A    if (s == null) %7B%0D%0A      s = %22null%22;%0D%0A    %7D%0D%0A    int sl = s.length();%0D%0A    if (sl %3C= n) %7B%0D%0A      return s + (pad ? blanks.substring(0, n - sl) : %22%22);%0D%0A    %7D%0D%0A    int dl = 1; // (n %3C 11) ? 1 : (n %3C 29) ? 2 : 3;  // number of dots%0D%0A    int ss = (n - dl) / 2;%0D%0A    int ss2 = ss + (( ss * 2 == (n - dl)) ? 0 : 1);%0D%0A    return s.substring(0, ss) + dots.substring(0, dl) + s.substring(sl - ss2);%0D%0A  %7D  
+%0D%0Apublic class Misc %7B
 %0D%0A%0D%0A
@@ -1294,72 +1294,8 @@
  %7B%0D%0A
-//    System.out.println(elide(%22uninflectedWord%22, 11));%0D%0A//  %7D%0D%0A
 //  

Remove changes to Misc and move them to an "Impl" style class