Example #1
0
 public StringBuilder toString(StringBuilder sb, String[] fs, long idx) {
   Vec vecs[] = vecs();
   for (int c = 0; c < fs.length; c++) {
     Vec vec = vecs[c];
     if (vec.isEnum()) {
       String s = "----------";
       if (!vec.isNA(idx)) {
         int x = (int) vec.at8(idx);
         if (x >= 0 && x < vec._domain.length) s = vec._domain[x];
       }
       sb.append(String.format(fs[c], s));
     } else if (vec.isInt()) {
       if (vec.isNA(idx)) {
         Chunk C = vec.elem2BV(0); // 1st Chunk
         int len = C.pformat_len0(); // Printable width
         for (int i = 0; i < len; i++) sb.append('-');
       } else {
         try {
           sb.append(String.format(fs[c], vec.at8(idx)));
         } catch (IllegalFormatException ife) {
           System.out.println("Format: " + fs[c] + " col=" + c + " not for ints");
           ife.printStackTrace();
         }
       }
     } else {
       sb.append(String.format(fs[c], vec.at(idx)));
       if (vec.isNA(idx)) sb.append(' ');
     }
     sb.append(' '); // Column seperator
   }
   sb.append('\n');
   return sb;
 }
  /**
   * Substitutes each {@code %s} in {@code template} with an argument. These are matched by position
   * - the first {@code %s} gets {@code args[0]}, etc.
   */
  private static String format(String template, Object... args) {
    template = String.valueOf(template); // null -> "null"

    try {
      return String.format(template, args);
    } catch (IllegalFormatException exception) {
      MoPubLog.e("MoPub preconditions had a format exception: " + exception.getMessage());
      return template;
    }
  }
 // Extract to NBT
 public boolean writenbt(String[] nbtOperations) {
   try {
     NBTTagCompound entityNBT = new NBTTagCompound();
     entity.writeToNBT(entityNBT);
     new NBTWriter(nbtOperations).writeToNBT(entityNBT);
     entity.readFromNBT(entityNBT);
     return true;
   } catch (IllegalFormatException e) {
     JASLog.log().severe("Skipping NBT Write due to %s", e.getMessage());
   } catch (IllegalArgumentException e) {
     JASLog.log().severe("Skipping NBT Write due to %s", e.getMessage());
   }
   return false;
 }
 @Override
 public CharSequence getSummary() {
   final String summary = super.getSummary().toString();
   int value = minValue;
   try {
     value = Integer.parseInt(getPersistedString(Integer.toString(defaultValue)));
   } catch (NumberFormatException ex) {
   }
   try {
     return String.format(summary, value);
   } catch (IllegalFormatException ex) {
     System.err.println("Error on summary formatting for " + getKey() + ": " + ex.getMessage());
   }
   return summary;
 }
  /**
   * Returns the value of the interpolated validated value.
   *
   * @param expression the expression to interpolate
   * @param validatedValue the value of the object being validated
   * @param locale the {@code Locale} to be used
   * @return the interpolated value
   */
  private String interpolateValidatedValue(
      String expression, Object validatedValue, Locale locale) {
    String interpolatedValue;
    int separatorIndex = expression.indexOf(VALIDATED_VALUE_FORMAT_SEPARATOR);

    if (separatorIndex == -1) {
      interpolatedValue = String.valueOf(validatedValue);
    } else {
      String format = expression.substring(separatorIndex + 1, expression.length() - 1);
      if (format.length() == 0) {
        throw log.getMissingFormatStringInTemplateException(expression);
      }
      try {
        interpolatedValue = String.format(locale, format, validatedValue);
      } catch (IllegalFormatException e) {
        throw log.throwInvalidFormat(e.getMessage(), e);
      }
    }
    return interpolatedValue;
  }
Example #6
0
 public String build() {
   if (ErrorMessageBuilder.this.hasMessage(this.ex)) {
     try {
       return String.format(this.fstring, this.fArgs)
           + ": "
           + ErrorMessageBuilder.this.getMessage(this.ex);
     } catch (IllegalFormatException ex1) {
       LOG.error(
           "Failed to format \""
               + this.fstring
               + "\" with args: "
               + Arrays.asList(this.fArgs)
               + " because of: "
               + ex1.getMessage(),
           ex1);
       return ErrorMessageBuilder.this.getMessage(this.ex);
     }
   } else {
     return this.unknownMessage;
   }
 }