コード例 #1
0
 public Locale getLocale(String text) {
   if (Strings.isBlank(text)) {
     return null;
   }
   LanguageIdentifier id = new LanguageIdentifier(text);
   String language = id.getLanguage();
   if (Strings.isBlank(language)) {
     return null;
   }
   return new Locale(language);
 }
コード例 #2
0
  public static String simplifyURL(String url) {
    if (Strings.isBlank(url)) {
      return "";
    }
    if (url.indexOf("?") != -1) {
      url = url.substring(0, url.indexOf("?"));
    }
    if (url.indexOf("#") != -1) {
      url = url.substring(0, url.indexOf("#"));
    }

    url = url.trim();
    url = url.replaceFirst("^[a-z]+://", "");
    url = url.replaceFirst("^www\\.", "");
    String[] parts = url.split("/");
    StringBuilder simplified = new StringBuilder();

    for (int i = 0; i < parts.length; i++) {
      if (i == 0) {
        simplified.append(parts[i]);
      } else if (i == parts.length - 1) {
        simplified.append(" : ");
        String part = parts[i];
        simplified.append(Strings.decodeURL(part).trim());
      }
    }

    return simplified.toString();
  }
コード例 #3
0
 public Language getLanguageForCode(String code) {
   if (Strings.isBlank(code)) {
     return null;
   }
   Query<Language> query = Query.of(Language.class).withField(Language.CODE, code);
   return modelService.search(query).getFirst();
 }
コード例 #4
0
 public LexicalCategory getLexcialCategoryForCode(String code) {
   if (Strings.isBlank(code)) {
     return null;
   }
   Query<LexicalCategory> query =
       Query.of(LexicalCategory.class).withField(LexicalCategory.CODE, code);
   return modelService.search(query).getFirst();
 }
コード例 #5
0
 public static String[] getWords(String query) {
   if (Strings.isBlank(query)) {
     return new String[] {};
   }
   return query.trim().split("\\s+");
 }
コード例 #6
0
 public static String fallback(String str, String defaultValue) {
   if (Strings.isBlank(str)) {
     return defaultValue;
   }
   return str;
 }