/*
 * This file is released under terms of BSD license
 * See LICENSE file for more information
 */

package cx2x.translator.misc;

import xcodeml.util.XmOption;

import java.util.Iterator;
import java.util.List;

/**
 * This class contains utilities methods that are useful in the whole project.
 * Mostly to implements java 1.8 features that are not present in java 1.7.
 * 
 * @author clementval
 */
public class Utility {
  /**
   * Join an array of String elements into a single String.
   * @param delimiter Delimiter to be placed between each element.
   * @param elements  Array of String elements.
   * @return A joined string of all elements separated by the delimiter.
   */
  public static String join(String delimiter, String[] elements){
    StringBuilder ret = new StringBuilder();
    boolean firstIteration = true;
    for(String s : elements){
      if(!firstIteration){
        ret.append(delimiter);
      } else {
        firstIteration = false;
      }
      ret.append(s);
    }
    return ret.toString();
  }

  /**
   * Join a list of String elements into a single String.
   * @param delimiter Delimiter to be placed between each element.
   * @param elements  List of String elements.
   * @param <T>       Type of element in the list.
   * @return A joined string of all elements separated by the delimiter.
   */
  public static <T> String join(String delimiter, List<T> elements){
    StringBuilder ret = new StringBuilder();
    Iterator<T> it = elements.iterator();
    while(it.hasNext()){
      ret.append(it.next().toString());
      if(it.hasNext()) {
        ret.append(delimiter);
      }
    }
    return ret.toString();
  }

  /**
   * Print debugging information on the standard output if option is active.
   * @param value Value to be printed.
   */
  public static void debug(String value){
    if(XmOption.isDebugOutput()) {
      System.out.println(value);
    }
  }
}

@@ -372,10 +372,9 @@
 .%0A *
- 
 %0A
+
  * @
@@ -418,16 +418,17 @@
 ility %7B%0A
+%0A
   /**%0A  
@@ -477,32 +477,37 @@
  single String.%0A
+   *%0A
    * @param deli
@@ -740,32 +740,33 @@
 ring%5B%5D elements)
+ 
 %7B%0A    StringBuil
@@ -855,24 +855,25 @@
  : elements)
+ 
 %7B%0A      if(!
@@ -887,16 +887,17 @@
 eration)
+ 
 %7B%0A      
@@ -1095,24 +1095,29 @@
 gle String.%0A
+   *%0A
    * @param 
@@ -1415,16 +1415,17 @@
 lements)
+ 
 %7B%0A    St
@@ -1528,16 +1528,17 @@
 sNext())
+ 
 %7B%0A      
@@ -1756,16 +1756,21 @@
 active.%0A
+   *%0A
    * @pa
@@ -1798,32 +1798,32 @@
  printed.%0A   */%0A
-
   public static 
@@ -1846,16 +1846,17 @@
 g value)
+ 
 %7B%0A    if

Format translator.misc package