Example usage for org.apache.commons.lang StringUtils capitalize

List of usage examples for org.apache.commons.lang StringUtils capitalize

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils capitalize.

Prototype

public static String capitalize(String str) 

Source Link

Document

Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char) .

Usage

From source file:com.zauberlabs.commons.mom.NaiveProperties.java

/**
 * Answers the setter of a given property and class, or null, if such
 * property is not writable or inexistent
 *//*ww  w.  j  av  a 2  s.  c o  m*/
public static Method setterOrNull(@NonNull final Class<?> clazz, @NotEmpty final String propertyName) {
    String capitalizedName = StringUtils.capitalize(propertyName);
    return findMethodOrNull(clazz, 1, Predicates.equal("set" + capitalizedName));
}

From source file:com.censoredsoftware.library.util.StringUtil2.java

/**
 * Automatically removes underscores and returns a capitalized version of the given <code>string</code>.
 *
 * @param string the string the beautify.
 *//*from w w  w.  ja  v  a 2s.  com*/
public static String beautify(String string) {
    return StringUtils.capitalize(string.toLowerCase().replace("_", " "));
}

From source file:fr.ritaly.dungeonmaster.champion.ChampionFactory.java

/**
 * Creates and returns a new champion from the given name.
 *
 * @param name//from w  w  w.j a v  a 2s  .  c  om
 *            the name of the champion to create. Can't be null.
 * @return a champion. Never returns null.
 */
public Champion newChampion(Champion.Name name) {
    Validate.notNull(name, "The given champion name is null");

    final Champion champion = new Champion(StringUtils.capitalize(name.name().toLowerCase()), name.getGender());

    // Set the champion's skills
    final Map<Skill, Level> skills = name.getSkills();

    for (Skill skill : skills.keySet()) {
        champion.setSkill(skill, skills.get(skill));
    }

    final Stats stats = champion.getStats();

    // TODO Add some items in the champion's inventory
    switch (name) {
    case ALEX:
        stats.init(50, 57, 13, 47, 44, 55, 45, 40, 40, 35);
        break;
    case AZIZI:
        stats.init(61, 77, 7, 47, 47, 48, 42, 45, 35, 30);
        break;
    case BORIS:
        stats.init(35, 65, 28, 35, 35, 45, 55, 40, 40, 45);
        break;
    case CHANI:
        stats.init(47, 67, 20, 57, 37, 47, 57, 37, 37, 47);
        break;
    case DAROOU:
        stats.init(100, 65, 6, 35, 50, 30, 35, 45, 45, 30);
        break;
    case ELIJA:
        stats.init(60, 58, 22, 50, 42, 40, 42, 36, 40, 53);
        break;
    case GANDO:
        stats.init(39, 63, 26, 50, 39, 45, 47, 33, 43, 48);
        break;
    case GOTHMOG:
        stats.init(60, 55, 18, 30, 40, 43, 48, 34, 59, 80);
        break;
    case HALK:
        stats.init(90, 75, 0, 40, 55, 43, 30, 46, 48, 38);
        break;
    case HAWK:
        stats.init(70, 85, 10, 40, 45, 35, 38, 55, 35, 35);
        break;
    case HISSA:
        stats.init(80, 61, 5, 40, 58, 48, 35, 35, 55, 43);
        break;
    case IAIDO:
        stats.init(48, 65, 11, 40, 43, 55, 40, 35, 50, 45);
        break;
    case LEIF:
        stats.init(75, 70, 7, 35, 46, 40, 39, 50, 45, 45);
        break;
    case LEYLA:
        stats.init(48, 60, 3, 50, 40, 53, 45, 47, 35, 45);
        break;
    case LINFLAS:
        stats.init(65, 50, 12, 45, 45, 45, 47, 35, 35, 50);
        break;
    case MOPHUS:
        stats.init(55, 55, 19, 40, 42, 35, 40, 48, 45, 40);
        break;
    case NABI:
        stats.init(55, 65, 15, 40, 41, 36, 45, 45, 55, 55);
        break;
    case SONJA:
        stats.init(65, 70, 2, 40, 54, 45, 39, 49, 40, 40);
        break;
    case STAMM:
        stats.init(75, 80, 0, 35, 52, 43, 35, 50, 55, 35);
        break;
    case SYRA:
        stats.init(53, 72, 15, 55, 38, 35, 43, 45, 40, 42);
        break;
    case TIGGY:
        stats.init(25, 45, 36, 45, 30, 45, 50, 35, 40, 59);
        break;
    case WUTSE:
        stats.init(45, 47, 20, 40, 38, 35, 53, 45, 40, 47);
        break;
    case WUUF:
        stats.init(40, 50, 30, 60, 33, 57, 45, 40, 40, 35);
        break;
    case ZED:
        stats.init(30, 30, 10, 58, 40, 40, 40, 50, 40, 40);
        break;

    default:
        break;
    }

    return champion;
}

From source file:com.alibaba.otter.shared.communication.core.impl.AbstractCommunicationEndpoint.java

/**
 * ?//  w ww.ja  va 2  s .  c  o  m
 */
public Object acceptEvent(Event event) {
    if (event instanceof HeartEvent) {
        return event; // ??
    }

    try {
        Object action = CommunicationRegistry.getAction(event.getType());
        if (action != null) {

            // ???
            String methodName = "on" + StringUtils.capitalize(event.getType().toString());
            Method method = ReflectionUtils.findMethod(action.getClass(), methodName,
                    new Class[] { event.getClass() });
            if (method == null) {
                methodName = DEFAULT_METHOD; // ?
                method = ReflectionUtils.findMethod(action.getClass(), methodName,
                        new Class[] { event.getClass() });

                if (method == null) { // ??Event?
                    method = ReflectionUtils.findMethod(action.getClass(), methodName,
                            new Class[] { Event.class });
                }
            }
            // ?,????
            if (method != null) {
                try {
                    ReflectionUtils.makeAccessible(method);
                    return method.invoke(action, new Object[] { event });
                } catch (Throwable e) {
                    throw new CommunicationException("method_invoke_error:" + methodName, e);
                }
            } else {
                throw new CommunicationException(
                        "no_method_error for[" + StringUtils.capitalize(event.getType().toString())
                                + "] in Class[" + action.getClass().getName() + "]");
            }

        }

        throw new CommunicationException("eventType_no_action", event.getType().name());
    } catch (RuntimeException e) {
        logger.error("endpoint_error", e);
        throw e;
    } catch (Exception e) {
        logger.error("endpoint_error", e);
        throw new CommunicationException(e);
    }
}

From source file:com.abiquo.server.core.common.GenericEntityTestBase.java

private <V> boolean executeIsValidXXXMethod(Class<?> entityClass, String property, Class<V> valueClass, V value)
        throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException,
        NoSuchMethodException {/*from  w  w  w.jav  a 2s .c  om*/
    assert entityClass != null;
    assert !StringUtils.isEmpty(property);
    assert valueClass != null;

    Class<?>[] noGroups = new Class[] {};
    Method isValidMethod = entityClass.getMethod("isValid" + StringUtils.capitalize(property), valueClass,
            Class[].class);
    return ((Boolean) isValidMethod.invoke(null, value, noGroups)).booleanValue();

}

From source file:edu.northwestern.bioinformatics.studycalendar.domain.ScheduledActivityState.java

@Transient
public String getTextSummary() {
    StringBuilder sb = new StringBuilder();
    sb.append(StringUtils.capitalize(getMode().getName()));
    appendSummaryMiddle(sb);/*from www .j a va 2s .c om*/
    if (getReason() != null)
        sb.append(" - ").append(getReason());
    return sb.toString();
}

From source file:ips1ap101.lib.core.jsf.component.Etiqueta.java

/**
 * {@inheritDoc}/* w  ww . j  a v  a  2  s  .  c om*/
 */
@Override
public Object getValue() {
    Object superobj = super.getValue();
    String superstr = superobj == null ? null : superobj.toString();
    if (StringUtils.isBlank(superstr)) {
        return superobj;
    } else if (superstr != null && superstr.startsWith("BundleParametros.")) {
        int i = superstr.indexOf('.');
        String key = superstr.substring(i + 1).trim();
        if (key.length() > 0) {
            return BundleParametros.getShortLabel(key);
        }
    } else if (superstr != null && superstr.startsWith("BundleDominios.")) {
        int i = superstr.indexOf('.');
        String key = superstr.substring(i + 1).trim();
        if (key.length() > 0) {
            return StringUtils.capitalize(BundleDominios.getLabel(key));
        }
    } else if (getValueExpression("value") != null) {
        return superobj;
    }
    String webuistr = JSF.getWebuiString(this, "text");
    //      if (webuistr == null) {
    //          String prefix = "label";
    //          String thisid = StringUtils.trimToEmpty(this.getId());
    //          String altkey = thisid.startsWith(prefix) ? thisid.substring(prefix.length()) : null;
    //          String styles = StringUtils.trimToEmpty(this.getStyleClass());
    //          webuistr = StringUtils.lowerCase(JSF.getWebuiString(superstr, altkey, styles));
    //      }
    return webuistr == null ? superobj : webuistr;
}

From source file:com.github.jdot.file.builder.BuilderBuilder.java

@Override
public JavaFile build() {
    String typeName = type.getQualifiedName();
    if (forOriginalType) {
        typeName = originalType.getQualifiedName();
    }// www .j  a  v  a  2 s. c  om
    statics.line("    public final static class Builder {");
    statics.line("        private " + typeName + " template;");

    statics.line("        public Builder() {");
    statics.line("            this.template = new " + typeName + "();");
    statics.line("        }");

    // Clone-based constructor to modify existing instance
    statics.line("        public Builder(" + typeName + " o) {");
    statics.line("            try {");
    statics.line("                this.template = (" + typeName + ") o.clone();");
    statics.line("            } catch (Exception e) {");
    statics.line("                throw new RuntimeException(\"Cloning failed: \" + o, e);");
    statics.line("            }");
    statics.line("        }");

    for (State state : type.getStates()) {
        statics.nl();
        statics.line("        public Builder with" + StringUtils.capitalize(state.getName()) + "("
                + state.getType() + " " + state.getName() + ") {");
        statics.line("            template." + state.getName() + " = " + state.getName() + ";");
        statics.line("            return this;");
        statics.line("        }");
    }
    statics.nl();
    statics.line("        public " + typeName + " build() {");
    statics.line("            return this.template;");
    statics.line("        }");
    statics.line("    }");
    statics.nl();
    return javaFile;
}

From source file:com.byraphaelmedeiros.autosubdown.AutoSubDown.java

/**
 * Efetua a leitura dos provedores e download dos arquivos
 *///www .j av  a 2  s  .  co m
public static void download() {
    LOGGER.log(Level.INFO, "Starting downloads...");

    Config config = Config.getInstance();

    config.load();

    List<Provider> providers = config.getProviders();

    if (!providers.isEmpty()) {
        LOGGER.log(Level.INFO, "Retrieving providers (twitter/rss)...");

        Rule rule = null;

        for (Provider p : providers) {
            if (ProviderType.TWITTER.equals(p.getType())) {
                List<Tweet> userTimeline = TAPI.timelineOperations().getUserTimeline(p.getName());

                if (userTimeline != null && !userTimeline.isEmpty()) {
                    LOGGER.log(Level.INFO,
                            "Recovering messages for " + StringUtils.capitalize(p.getName()) + "...");

                    String content = null;

                    for (Tweet t : userTimeline) {
                        content = t.getText();

                        //content = "Nova legenda disponivel: http://www.insubs.com/legendas/the.big.bang.theory.S02E09.DVDRip.xVid.InSubs.zip #AutoSubDown";

                        if (config.inRule(content)) {
                            LOGGER.log(Level.INFO, "Valid message!");

                            rule = config.getRule(content);

                            download(rule, content);

                            if (rule.isTVShow()) {
                                rule.addEpisodeDownloaded(rule.getEpisode(content));

                                config.save();
                            }
                        }
                    }
                }

            } else if (ProviderType.RSS.equals(p.getType())) {
                String title = null, link = null;

                try {
                    ChannelIF rssChannel = FeedParser.parse(new ChannelBuilder(), new URL(p.getUrl()));

                    Collection<ItemIF> items = rssChannel.getItems();

                    if (items != null && !items.isEmpty()) {
                        LOGGER.log(Level.INFO,
                                "Recovering messages for " + StringUtils.capitalize(p.getName()) + "...");

                        for (ItemIF item : items) {
                            title = item.getTitle();

                            if (config.inRule(title)) {
                                LOGGER.log(Level.INFO, "Valid message!");

                                rule = config.getRule(title);

                                if (item.getLink() != null) {
                                    link = item.getLink().toString();

                                    downloadTo(rule, link);
                                    extract(config, rule, link);

                                    if (rule.isTVShow()) {
                                        rule.addEpisodeDownloaded(rule.getEpisode(title));

                                        config.save();
                                    }
                                } else {
                                    LOGGER.log(Level.INFO, "Invalid link!");
                                }
                            }
                        }
                    }
                } catch (MalformedURLException e) {
                    //e.printStackTrace();
                    LOGGER.log(Level.WARNING, "Invalid URL! (" + link + ")");
                } catch (IOException e) {
                    //e.printStackTrace();
                    LOGGER.log(Level.WARNING, "Invalid URL! (" + link + ")");
                } catch (ParseException e) {
                    //e.printStackTrace();
                    LOGGER.log(Level.WARNING, "Invalid URL! (" + link + ")");
                }
            }
        }
    }

    /*
    List<SiteProvider> siteProviders = config.getSiteProviders();
            
    if (!siteProviders.isEmpty()) {
       LOGGER.log(Level.INFO, "Retrieving site providers (websites)...");
               
       try {
    Rule rule = null;
            
    HttpClient httpClient = new DefaultHttpClient();
    HttpContext httpContext = new BasicHttpContext();
            
    HttpPost httpPost = null;
    UrlEncodedFormEntity entityPost = null;
    HttpResponse httpResponse = null;
    HttpEntity entityResponse = null;
    String htmlContent = null;
            
    // action = login_verificar.php, txtLogin, txtSenha
            
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("param1", "value1"));
    params.add(new BasicNameValuePair("param2", "value2"));
            
    for (SiteProvider sp : siteProviders) {
       entityPost = new UrlEncodedFormEntity(params, "UTF-8");
               
       httpPost = new HttpPost(sp.getUrlLoginAction());
       httpPost.setEntity(entityPost);
               
       httpResponse = httpClient.execute(httpPost, httpContext);
               
       entityResponse = httpResponse.getEntity();
               
       htmlContent = EntityUtils.toString(entityResponse);
               
       // pegar link do botao DOWNLOAD
               
       // executar link do botao DOWNLOAD e salvar o arquivo
    }
       } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    //LOGGER.log(Level.WARNING, "Invalid URL! (" + link + ")");
       } catch (ClientProtocolException e) {
    e.printStackTrace();
       } catch (IOException e) {
    e.printStackTrace();
       }
    }
    */

    LOGGER.log(Level.INFO, "Done!");
}

From source file:info.magnolia.cms.taglibs.util.TableTagBeanInfo.java

/**
 * Instantiate a property descriptor for the given property.
 * @param propertyName property name// w  w  w .  j  ava  2  s.  co  m
 * @return property descriptor
 * @throws IntrospectionException if the given property is not valid
 */
private PropertyDescriptor createPropertyDescriptor(String propertyName) throws IntrospectionException {
    return new PropertyDescriptor(propertyName, TableTag.class, null,
            "set" + StringUtils.capitalize(propertyName));
}