Exemplo n.º 1
0
 /** @see {@link LocaleUtility#fromSpecification(String)} */
 @Test
 @Verifies(
     value = "should get locale from language code country code and variant",
     method = "fromSpecification(String)")
 public void fromSpecification_shouldGetLocaleFromLanguageCodeCountryCodeAndVariant()
     throws Exception {
   Locale locale = LocaleUtility.fromSpecification("en_US_Traditional_WIN");
   Assert.assertEquals(Locale.US.getLanguage(), locale.getLanguage());
   Assert.assertEquals(Locale.US.getCountry(), locale.getCountry());
   Assert.assertEquals("Traditional,WIN", locale.getDisplayVariant());
 }
  /**
   * Produces a java map that maps a {@link Country} to it's ISO 3166 country code.<br>
   * Each map entry consists of:<br>
   *
   * <table border=1>
   * <tr>
   * <td>key:</td>
   * <td>ISO 3166 country code</td>
   * </tr>
   * <tr>
   * <td>value:</td>
   * <td>the corresponding country as {@link Country}-instance</td>
   * </table>
   *
   * @return
   */
  public static Map<String, Country> createCountryMap() {
    // ISO3166-ALPHA-2 codes
    String[] countryCodes = Locale.getISOCountries();

    // Key = CountryCode
    // Value = Country
    Map<String, Country> countries = new HashMap<String, Country>(countryCodes.length);

    for (String cc : countryCodes) {

      Locale.setDefault(Locale.US);
      String countryNameEnglish = new Locale(Locale.US.getLanguage(), cc).getDisplayCountry();

      Locale.setDefault(Locale.GERMANY);
      String countryNameGerman = new Locale(Locale.GERMANY.getLanguage(), cc).getDisplayCountry();

      Country country = new Country(cc.toUpperCase(), countryNameEnglish, countryNameGerman);

      countries.put(cc, country);
    }

    if (logger.isInfoEnabled()) {
      logger.info(
          "Created a country-iso3166Code Map<String, Country> with {} entries.", countries.size());
    }

    return countries;
  }
Exemplo n.º 3
0
  @SuppressWarnings("deprecation")
  private void showActions() {
    String textColumn = CommandDao.Properties.Text.columnName;
    String orderBy = textColumn + " COLLATE LOCALIZED ASC";
    String whereBy =
        CommandDao.Properties.Lang.columnName
            + "=\""
            + prefs.getString(CommandActivity.PREFS_LANGUAGE, Locale.US.toString())
            + "\"";
    cursor =
        db.query(
            commandDao.getTablename(),
            commandDao.getAllColumns(),
            whereBy,
            null,
            null,
            null,
            orderBy);
    String[] from = {textColumn, CommandDao.Properties.Lang.columnName};
    int[] to = {android.R.id.text1, android.R.id.text2};

    SimpleCursorAdapter adapter =
        new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor, from, to);
    setListAdapter(adapter);
  }
Exemplo n.º 4
0
 static {
   GOOGLE_COUNTRY_TLD = new HashMap<String, String>();
   GOOGLE_COUNTRY_TLD.put("AR", "com.ar"); // ARGENTINA
   GOOGLE_COUNTRY_TLD.put("AU", "com.au"); // AUSTRALIA
   GOOGLE_COUNTRY_TLD.put("BR", "com.br"); // BRAZIL
   GOOGLE_COUNTRY_TLD.put("BG", "bg"); // BULGARIA
   GOOGLE_COUNTRY_TLD.put(Locale.CANADA.getCountry(), "ca");
   GOOGLE_COUNTRY_TLD.put(Locale.CHINA.getCountry(), "cn");
   GOOGLE_COUNTRY_TLD.put("CZ", "cz"); // CZECH REPUBLIC
   GOOGLE_COUNTRY_TLD.put("DK", "dk"); // DENMARK
   GOOGLE_COUNTRY_TLD.put("FI", "fi"); // FINLAND
   GOOGLE_COUNTRY_TLD.put(Locale.FRANCE.getCountry(), "fr");
   GOOGLE_COUNTRY_TLD.put(Locale.GERMANY.getCountry(), "de");
   GOOGLE_COUNTRY_TLD.put("GR", "gr"); // GREECE
   GOOGLE_COUNTRY_TLD.put("HU", "hu"); // HUNGARY
   GOOGLE_COUNTRY_TLD.put("ID", "co.id"); // INDONESIA
   GOOGLE_COUNTRY_TLD.put("IL", "co.il"); // ISRAEL
   GOOGLE_COUNTRY_TLD.put(Locale.ITALY.getCountry(), "it");
   GOOGLE_COUNTRY_TLD.put(Locale.JAPAN.getCountry(), "co.jp");
   GOOGLE_COUNTRY_TLD.put(Locale.KOREA.getCountry(), "co.kr");
   GOOGLE_COUNTRY_TLD.put("NL", "nl"); // NETHERLANDS
   GOOGLE_COUNTRY_TLD.put("PL", "pl"); // POLAND
   GOOGLE_COUNTRY_TLD.put("PT", "pt"); // PORTUGAL
   GOOGLE_COUNTRY_TLD.put("RU", "ru"); // RUSSIA
   GOOGLE_COUNTRY_TLD.put("SK", "sk"); // SLOVAK REPUBLIC
   GOOGLE_COUNTRY_TLD.put("SI", "si"); // SLOVENIA
   GOOGLE_COUNTRY_TLD.put("ES", "es"); // SPAIN
   GOOGLE_COUNTRY_TLD.put("SE", "se"); // SWEDEN
   GOOGLE_COUNTRY_TLD.put(Locale.TAIWAN.getCountry(), "tw");
   GOOGLE_COUNTRY_TLD.put("TR", "com.tr"); // TURKEY
   GOOGLE_COUNTRY_TLD.put(Locale.UK.getCountry(), "co.uk");
   GOOGLE_COUNTRY_TLD.put(Locale.US.getCountry(), "com");
 }
  /** @see DATADOC-130 */
  @Test
  public void convertsMapTypeCorrectly() {

    Map<Locale, String> map = Collections.singletonMap(Locale.US, "Foo");

    BasicDBObject dbObject = new BasicDBObject();
    converter.write(map, dbObject);

    assertThat(dbObject.get(Locale.US.toString()).toString(), is("Foo"));
  }
Exemplo n.º 6
0
  private void recordVoiceCommand() {
    final Intent newCommandIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    newCommandIntent.putExtra(
        RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    newCommandIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak command phrase");

    String languagePref = prefs.getString(CommandActivity.PREFS_LANGUAGE, Locale.US.toString());
    newCommandIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, languagePref);
    newCommandIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, languagePref);
    newCommandIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, languagePref);

    startActivityForResult(newCommandIntent, VOICE_RECOGNITION_REQUEST_CODE);
  }
Exemplo n.º 7
0
 static {
   GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD = new HashMap<String, String>();
   GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put("AU", "com.au"); // AUSTRALIA
   GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.CHINA.getCountry(), "cn");
   GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.FRANCE.getCountry(), "fr");
   GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.GERMANY.getCountry(), "de");
   GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.ITALY.getCountry(), "it");
   GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.JAPAN.getCountry(), "co.jp");
   GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put("NL", "nl"); // NETHERLANDS
   GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put("ES", "es"); // SPAIN
   GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.UK.getCountry(), "co.uk");
   GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.US.getCountry(), "com");
 }
Exemplo n.º 8
0
  /**
   * Return the Accept-Language header. Use the current locale plus US if we are in a different
   * locale than US. This code copied from the browser's WebSettings.java
   *
   * @return Current AcceptLanguage String.
   */
  public static String getCurrentAcceptLanguage(Locale locale) {
    StringBuilder buffer = new StringBuilder();
    addLocaleToHttpAcceptLanguage(buffer, locale);

    if (!Locale.US.equals(locale)) {
      if (buffer.length() > 0) {
        buffer.append(", ");
      }
      buffer.append(ACCEPT_LANG_FOR_US_LOCALE);
    }

    return buffer.toString();
  }
 AmazonInfoRetriever(
     TextView textView,
     String type,
     String productID,
     HistoryManager historyManager,
     Context context) {
   super(textView, historyManager);
   String country = LocaleManager.getCountry(context);
   if ("ISBN".equals(type) && !Locale.US.getCountry().equals(country)) {
     type = "EAN";
   }
   this.type = type;
   this.productID = productID;
   this.country = country;
 }
Exemplo n.º 10
0
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    String locale = "";
    String path = req.getPathInfo();
    if (!Helper.isEmpty(path) && path.startsWith("/")) locale = path.substring(1);

    if (Helper.isEmpty(locale)) {
      // fall back to language specified in header e.g. via browser settings
      String acceptLang = req.getHeader("Accept-Language");
      if (!Helper.isEmpty(acceptLang)) locale = acceptLang.split(",")[0];
    }

    Translation tr = map.get(locale);
    JSONObject json = new JSONObject();
    if (tr != null && !Locale.US.equals(tr.getLocale())) json.put("default", tr.asMap());

    json.put("locale", locale.toString());
    json.put("en", map.get("en").asMap());
    writeJson(req, res, json);
  }
  protected Status processCommunicateAction(
      final Exchange exchange, final CommunicateAction communicateAction) throws IOException {
    final EmotionKind emotionKind =
        Optional.ofNullable(communicateAction.getEmotionKind()).orElse(EmotionKind.NEUTRAL);
    final Locale lang = Optional.ofNullable(communicateAction.getInLanguage()).orElse(Locale.US);
    log.info("Got speech lang-legacy={}: {}", lang.getLanguage(), communicateAction);
    final String avatarId = Optional.ofNullable(communicateAction.getAvatarId()).orElse("nao1");

    // final File wavFile = File.createTempFile("lumen-speech-synthesis_", ".wav");
    //                        final File oggFile = File.createTempFile("lumen-speech-synthesis_",
    // ".ogg");
    try {
      byte[] wavBytes = null;
      if (INDONESIAN.getLanguage().equals(lang.getLanguage())) {
        // Expressive speech (for now, Indonesian only)
        try {
          PhonemeDoc phonemeDoc;
          if (EmotionKind.NEUTRAL == emotionKind) {
            phonemeDoc = speechProsody.performNeutral(communicateAction.getObject());
          } else {
            try {
              final EmotionProsody emotionProsody =
                  emotionProsodies
                      .getEmotion(emotionKind)
                      .orElseThrow(
                          () ->
                              new SpeechSynthesisException(
                                  "Emotion " + emotionKind + " not supported"));
              phonemeDoc = speechProsody.perform(communicateAction.getObject(), emotionProsody);
            } catch (Exception e) {
              log.error(
                  "Cannot speak with emotion "
                      + emotionKind
                      + ", falling back to NEUTRAL: "
                      + communicateAction.getObject(),
                  e);
              phonemeDoc = speechProsody.performNeutral(communicateAction.getObject());
            }
          }

          try (final ByteArrayInputStream objectIn =
                  new ByteArrayInputStream(phonemeDoc.toString().getBytes(StandardCharsets.UTF_8));
              final ByteArrayOutputStream wavStream = new ByteArrayOutputStream();
              final ByteArrayOutputStream err = new ByteArrayOutputStream()) {
            final CommandLine cmdLine = new CommandLine("mbrola");
            cmdLine.addArgument("-v");
            cmdLine.addArgument(String.valueOf(INDONESIAN_AMPLITUDE / 100f));
            cmdLine.addArgument(new File(mbrolaShareFolder, "id1/id1").toString());
            cmdLine.addArgument("-");
            cmdLine.addArgument("-.wav");
            executor.setStreamHandler(new PumpStreamHandler(wavStream, err, objectIn));
            final int executed;
            try {
              executed = executor.execute(cmdLine);
              wavBytes = wavStream.toByteArray();
            } finally {
              log.info("{}: {}", cmdLine, err.toString());
            }
          }
        } catch (Exception e) {
          log.error(
              "Cannot speak Indonesian using prosody engine, falling back to direct espeak: "
                  + communicateAction.getObject(),
              e);
        }
      }
      if (wavBytes == null) {
        // Neutral speech using direct espeak
        try {
          wavBytes = performEspeak(communicateAction, lang);
        } catch (Exception e) {
          if (!Locale.US.getLanguage().equals(lang.getLanguage())) {
            // Indonesian sometimes fails especially "k-k", e.g. "baik koq".
            // retry using English as last resort, as long as it says something!
            log.error(
                "Cannot speak using "
                    + lang.toLanguageTag()
                    + ", falling back to English (US): "
                    + communicateAction.getObject(),
                e);
            wavBytes = performEspeak(communicateAction, Locale.US);
          } else {
            throw e;
          }
        }
      }

      log.info("espeak/mbrola generated {} bytes WAV", wavBytes.length);
      try (final ByteArrayInputStream wavIn = new ByteArrayInputStream(wavBytes);
          final ByteArrayOutputStream bos = new ByteArrayOutputStream();
          final ByteArrayOutputStream err = new ByteArrayOutputStream()) {
        // flac.exe doesn't support mp3, and that's a problem for now (note: mp3 patent is expiring)
        final CommandLine cmdLine = new CommandLine(ffmpegExecutable);
        cmdLine.addArgument("-i");
        cmdLine.addArgument("-"); // cmdLine.addArgument(wavFile.toString());
        cmdLine.addArgument("-ar");
        cmdLine.addArgument(String.valueOf(SAMPLE_RATE));
        cmdLine.addArgument("-ac");
        cmdLine.addArgument("1");
        cmdLine.addArgument("-f");
        cmdLine.addArgument("ogg");
        // without this you'll get FLAC instead, which browsers do not support
        cmdLine.addArgument("-acodec");
        cmdLine.addArgument("libvorbis");
        //                                cmdLine.addArgument("-y"); // happens, weird!
        //                                cmdLine.addArgument(oggFile.toString());
        cmdLine.addArgument("-");
        executor.setStreamHandler(new PumpStreamHandler(bos, err, wavIn));
        final int executed;
        try {
          executed = executor.execute(cmdLine);
        } finally {
          log.info("{}: {}", cmdLine, err.toString());
        }
        //                                Preconditions.checkState(oggFile.exists(), "Cannot convert
        // %s bytes WAV to OGG",
        //                                        wavBytes.length);

        // Send
        //                                final byte[] audioContent =
        // FileUtils.readFileToByteArray(oggFile);
        final byte[] audioContent = bos.toByteArray();
        final String audioContentType = "audio/ogg";

        final AudioObject audioObject = new AudioObject();
        audioObject.setTranscript(communicateAction.getObject());
        audioObject.setInLanguage(lang);
        audioObject.setMediaLayer(MediaLayer.SPEECH);
        audioObject.setContentType(audioContentType + "; rate=" + SAMPLE_RATE);
        audioObject.setContentUrl(
            "data:" + audioContentType + ";base64," + Base64.encodeBase64String(audioContent));
        audioObject.setContentSize((long) audioContent.length);
        //
        // audioObject.setName(FilenameUtils.getName(oggFile.getName()));
        audioObject.setName("lumen-speech-" + new DateTime() + ".ogg");
        audioObject.setDateCreated(new DateTime());
        audioObject.setDatePublished(audioObject.getDateCreated());
        audioObject.setDateModified(audioObject.getDateCreated());
        audioObject.setUploadDate(audioObject.getDateCreated());
        final String audioOutUri =
            "rabbitmq://dummy/amq.topic?connectionFactory=#amqpConnFactory&exchangeType=topic&autoDelete=false&skipQueueDeclare=true&routingKey="
                + AvatarChannel.AUDIO_OUT.key(avatarId);
        log.info("Sending {} to {} ...", audioObject, audioOutUri);
        producer.sendBodyAndHeader(
            audioOutUri,
            toJson.getMapper().writeValueAsBytes(audioObject),
            RabbitMQConstants.EXPIRATION,
            String.valueOf(MESSAGE_EXPIRATION.getMillis()));
      }
    } finally {
      //                            oggFile.delete();
      // wavFile.delete();
    }

    // reply
    log.trace("Exchange {} is {}", exchange.getIn().getMessageId(), exchange.getPattern());
    final Status status = new Status();
    exchange.getOut().setBody(status);
    return status;
    //                        final String replyTo = exchange.getIn().getHeader("rabbitmq.REPLY_TO",
    // String.class);
    //                        if (replyTo != null) {
    //                            log.debug("Sending reply to {} ...", replyTo);
    //                            exchange.getOut().setHeader("rabbitmq.ROUTING_KEY", replyTo);
    //                            exchange.getOut().setHeader("rabbitmq.EXCHANGE_NAME", "");
    //                            exchange.getOut().setHeader("recipients",
    //
    // "rabbitmq://dummy/dummy?connectionFactory=#amqpConnFactory&autoDelete=false,log:OUT." +
    // LumenChannel.SPEECH_SYNTHESIS);
    //                        } else {
    //                            exchange.getOut().setHeader("recipients");
    //                        }
  }
  public void testMoreKeysOfEnterKey() {
    final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
    final InputMethodSubtype subtype =
        richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
            Locale.US.toString(), SubtypeLocaleUtils.QWERTY);

    // Password field.
    doTestNavigationMoreKeysOf(
        Constants.CODE_ENTER,
        subtype,
        KeyboardId.ELEMENT_ALPHABET,
        InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    // Email field.
    doTestNavigationMoreKeysOf(
        Constants.CODE_ENTER,
        subtype,
        KeyboardId.ELEMENT_ALPHABET,
        InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    // Url field.
    doTestNavigationMoreKeysOf(
        Constants.CODE_ENTER,
        subtype,
        KeyboardId.ELEMENT_ALPHABET,
        InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    // Phone number field.
    doTestNavigationMoreKeysOf(
        Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_PHONE, InputType.TYPE_CLASS_PHONE);
    // Number field.
    doTestNavigationMoreKeysOf(
        Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_NUMBER, InputType.TYPE_CLASS_NUMBER);
    // Date-time field.
    doTestNavigationMoreKeysOf(
        Constants.CODE_ENTER,
        subtype,
        KeyboardId.ELEMENT_NUMBER,
        InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_NORMAL);
    // Date field.
    doTestNavigationMoreKeysOf(
        Constants.CODE_ENTER,
        subtype,
        KeyboardId.ELEMENT_NUMBER,
        InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_DATE);
    // Time field.
    doTestNavigationMoreKeysOf(
        Constants.CODE_ENTER,
        subtype,
        KeyboardId.ELEMENT_NUMBER,
        InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_TIME);
    // Text field.
    if (isPhone()) {
      // The enter key has an Emoji key as one of more keys.
      doTestNavigationWithEmojiMoreKeysOf(
          Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, InputType.TYPE_CLASS_TEXT);
    } else {
      // Tablet has a dedicated Emoji key, so the Enter key has no Emoji more key.
      doTestNavigationMoreKeysOf(
          Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, InputType.TYPE_CLASS_TEXT);
    }
    // Short message field.
    if (isPhone()) {
      // Enter key is switched to Emoji key on a short message field.
      // Emoji key has no navigation more keys.
      doTestNoNavigationMoreKeysOf(
          Constants.CODE_EMOJI,
          subtype,
          KeyboardId.ELEMENT_ALPHABET,
          InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
    } else {
      doTestNavigationMoreKeysOf(
          Constants.CODE_ENTER,
          subtype,
          KeyboardId.ELEMENT_ALPHABET,
          InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
    }
  }
Exemplo n.º 13
0
public class TypeAdapter {
  public enum DataType {
    BOOLEAN,
    DATE,
    DOUBLE,
    FLOAT,
    INTEGER,
    INT,
    LONG,
    SHORT,
    STRING
  }

  private DataType type = DataType.STRING;
  private String dateFormat = "MM/dd/yyyy hh:mm:ss aaa";
  private String locale = Locale.US.toString();
  private DateFormat format;

  public void setType(String type) {
    this.type = DataType.valueOf(type.trim().toUpperCase());
  }

  public void setFormat(String format) {
    dateFormat = format;
  }

  public void setLocale(String locale) {
    this.locale = locale;
  }

  protected Object convertToPrimaryObject(String value) throws IllegalArgumentException {
    switch (type) {
      case BOOLEAN:
        return parseBoolean(value);
      case DATE:
        return parseDate(value);
      case DOUBLE:
        return parseDouble(value);
      case FLOAT:
        return parseFloat(value);
      case INTEGER:
        return parseInteger(value);
      case INT:
        return parseInteger(value);
      case LONG:
        return parseLong(value);
      case SHORT:
        return parseShort(value);
      case STRING:
        return value;
    }

    throw new IllegalStateException("Illegal primitive type '" + type + "' specified");
  }

  private DateFormat getDateFormat() {
    if (format != null) {
      return format;
    }

    try {
      return format = new SimpleDateFormat(dateFormat, new Locale(locale));
    } catch (Throwable e) {
      throw new BuildException("Incorrect time format/locale specified", e);
    }
  }

  private Boolean parseBoolean(String value) throws IllegalArgumentException {
    if (value == null || value.trim().isEmpty()) {
      throw new IllegalArgumentException("Can't convert null value to boolean");
    }

    String val = value.trim().toLowerCase();

    if (val.equals("false") || val.equals("no") || val.equals("0")) {
      return false;
    }

    if (val.equals("true") || val.equals("yes") || val.equals("1")) {
      return true;
    }

    throw new IllegalArgumentException("Invalid boolean value '" + value + "' specified");
  }

  private Date parseDate(String value) throws IllegalArgumentException {
    if (value == null || value.trim().length() == 0) {
      return null;
    }

    try {
      return getDateFormat().parse(value);
    } catch (ParseException e) {
    }

    try {
      return new Date(Long.parseLong(value));
    } catch (NumberFormatException e) {
    }

    throw new IllegalArgumentException("Invalid date value '" + value + "' specified");
  }

  private Double parseDouble(String value) throws IllegalArgumentException {
    if (value == null || value.trim().length() == 0) {
      return null;
    }

    try {
      return Double.parseDouble(value);
    } catch (NumberFormatException e) {
      throw new IllegalArgumentException("Invalid double value '" + value + "' specified");
    }
  }

  private Float parseFloat(String value) throws IllegalArgumentException {
    if (value == null || value.trim().length() == 0) {
      return null;
    }

    try {
      return Float.parseFloat(value);
    } catch (NumberFormatException e) {
      throw new IllegalArgumentException("Invalid float value '" + value + "' specified");
    }
  }

  private Integer parseInteger(String value) throws IllegalArgumentException {
    if (value == null || value.trim().length() == 0) {
      return null;
    }

    try {
      return Integer.parseInt(value);
    } catch (NumberFormatException e) {
      throw new IllegalArgumentException("Invalid int value '" + value + "' specified");
    }
  }

  private Long parseLong(String value) throws IllegalArgumentException {
    if (value == null || value.trim().length() == 0) {
      return null;
    }

    try {
      return Long.parseLong(value);
    } catch (NumberFormatException e) {
      throw new IllegalArgumentException("Invalid long value '" + value + "' specified");
    }
  }

  private Short parseShort(String value) throws IllegalArgumentException {
    if (value == null || value.trim().length() == 0) {
      return null;
    }

    try {
      return Short.parseShort(value);
    } catch (NumberFormatException e) {
      throw new IllegalArgumentException("Invalid short value '" + value + "' specified");
    }
  }
}
 public static String capitalize(String input) {
   return input.toUpperCase(new Locale(Locale.ENGLISH.getLanguage(), Locale.US.getCountry()));
 }
 public void timeToLowerCase_ICU(int reps) {
   for (int i = 0; i < reps; ++i) {
     libcore.icu.ICU.toLowerCase(s.value, Locale.US.toString());
   }
 }