package com.enderio.core.common;

import lombok.AllArgsConstructor;
import lombok.Getter;
import net.minecraft.util.StatCollector;

@AllArgsConstructor
@Getter
public class Lang {

  private static final String REGEX = "\\" + '|';
  public static final char CHAR = '|';

  private String locKey;

  /**
   * Adds the stored prefix to this string, separating with a period. Using this
   * method returns the string that is used for localizing if you passed this
   * arg into {@link #localize(String, Object...)}.
   * 
   * @param suffix
   *          The suffix string
   * @return The full string
   */
  public String addPrefix(String suffix) {
    return locKey + "." + suffix;
  }

  /**
   * Localizes the string passed, first appending the prefix stored in this
   * instance of the class.
   * 
   * @param unloc
   *          The unlocalized string.
   * @param args
   *          The args to format the localized text withi.
   * 
   * @return A localized string.
   */
  public String localize(String unloc, Object... args) {
    // Compat for old EIO code
    if (args.length == 1 && args[0] instanceof Boolean && !((Boolean) args[0]).booleanValue()) {
      return localizeExact(unloc);
    }
    return localizeExact(addPrefix(unloc), args);
  }

  /**
   * Ignores the prefix stored in this instance of the class and localizes the
   * raw string passed.
   * 
   * @param unloc
   *          The unlocalized string.
   * @param args
   *          The args to format the localized text withi.
   * 
   * @return A localized string.
   */
  public String localizeExact(String unloc, Object... args) {
    return StatCollector.translateToLocalFormatted(unloc, args);
  }

  /**
   * Splits the localized text on "|" into a String[].
   * 
   * @param unloc
   *          The unlocalized string.
   * @param args
   *          The args to format the localized text withi.
   * @return A localized list of strings.
   */
  public String[] localizeList(String unloc, String... args) {
    return splitList(localize(unloc, true, args));
  }

  /**
   * Splits a list of strings based on {@value #CHAR}
   * 
   * @param list
   *          The list of strings to split
   * @return An array of strings split on {@value #CHAR}
   */
  public String[] splitList(String list) {
    return list.split(REGEX);
  }

  public String[] splitList(String list, String split) {
    return list.split(split);
  }

  /**
   * Checks if the passed string (plus the prefix) has a localization mapped.
   * 
   * @param unloc
   *          The unlocalized suffix
   * @return True if there is a localization mapped, false otherwise.
   */
  public boolean canLocalize(String unloc) {
    return canLocalizeExact(addPrefix(unloc));
  }

  /**
   * Checks if the passed string has a localization mapped. Does not use the
   * prefix.
   * 
   * @param unloc
   *          The unlocalized string
   * @return True if there is a localization mapped, false otherwise.
   */
  public boolean canLocalizeExact(String unloc) {
    return StatCollector.canTranslate(unloc);
  }
}

@@ -31,42 +31,8 @@
 n;%0A%0A
-import lombok.AllArgsConstructor;%0A
 impo
@@ -95,28 +95,8 @@
 r;%0A%0A
-@AllArgsConstructor%0A
 @Get
@@ -224,22 +224,102 @@
 ate 
-String locKey;
+final String prefix;%0A%0A  public Lang(String locKey) %7B%0A    this.prefix = locKey.concat(%22.%22);%0A  %7D
 %0A%0A  
@@ -683,29 +683,29 @@
 urn 
-locKey + %22.%22 + 
+prefix.concat(
 suffix
+)
 ;%0A  
@@ -944,33 +944,32 @@
 alized text with
-i
 .%0A   * %0A   * @re
@@ -1064,70 +1064,145 @@
     
-// Compat for old EIO code%0A    if (args.le
+return localizeExact(addPrefix(unloc), args);%0A  %7D%0A%0A  /**%0A   * Localizes the string passed, first appendi
 ng
+ 
 th
- == 1 && args%5B0%5D
+e prefix stored in this%0A   *
  ins
@@ -1210,82 +1210,112 @@
 ance
+ 
 of 
-Boolean && !((Boolean) args%5B0%5D).booleanValue()) %7B
+the class.%0A   *%0A   * @param unloc%0A   *          The unlocalized string.
 %0A   
+*%0A
    
+* @
 return 
+A 
 localize
 Exac
@@ -1314,27 +1314,64 @@
 lize
-Exact(unloc);%0A    %7D
+d string.%0A   */%0A  public String localize(String unloc) %7B
 %0A   
@@ -1400,38 +1400,32 @@
 addPrefix(unloc)
-, args
 );%0A  %7D%0A%0A  /**%0A  
@@ -1656,25 +1656,24 @@
 ed text with
-i
 .%0A   * %0A   *
@@ -1831,32 +1831,347 @@
 oc, args);%0A  %7D%0A%0A
+  /**%0A   * Ignores the prefix stored in this instance of the class and localizes the%0A   * raw string passed.%0A   *%0A   * @param unloc%0A   *          The unlocalized string.%0A   *%0A   * @return A localized string.%0A   */%0A  public String localizeExact(String unloc) %7B%0A    return StatCollector.translateToLocal(unloc);%0A  %7D%0A%0A
   /**%0A   * Split
@@ -2350,17 +2350,16 @@
 ext with
-i
 .%0A   * @
@@ -2504,18 +2504,284 @@
 oc, 
-true, args
+(Object%5B%5D) args));%0A  %7D%0A%0A  /**%0A   * Splits the localized text on %22%7C%22 into a String%5B%5D.%0A   *%0A   * @param unloc%0A   *          The unlocalized string.%0A   * @return A localized list of strings.%0A   */%0A  public String%5B%5D localizeList(String unloc) %7B%0A    return splitList(localize(unloc
 ));%0A

add methods without varargs