Java Code Examples for org.apache.commons.lang.StringUtils#capitalize()

The following examples show how to use org.apache.commons.lang.StringUtils#capitalize() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: cosmic   File: ExtensionRegistry.java    License: Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {
    if (name == null) {
        for (String part : beanName.replaceAll("([A-Z])", " $1").split("\\s+")) {
            part = StringUtils.capitalize(part.toLowerCase());

            name = name == null ? part : name + " " + part;
        }
    }

    if (preRegistered != null) {
        for (final Object o : preRegistered) {
            register(o);
        }
    }
}
 
Example 2
Source Project: sofa-acts   File: ObjectUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Parse the target object from a string
 * 
 * @param source Source string to be parsed, The format is:billKeyName=testData|status=O</br>
 * @param obj
 * @return
 */
public static Object restoreObject(String source, Object obj) {

    if (StringUtils.isBlank(source)) {
        return obj;
    }
    String[] keyValues = StringUtils.split(source, "|");
    Class clazz = obj.getClass();
    for (String keyValue : keyValues) {

        String[] detail = keyValue.split("=", 2);
        String methodName = "set" + StringUtils.capitalize(detail[0].trim());

        Method method;
        try {
            method = clazz.getMethod(methodName, String.class);
            method.setAccessible(true);
            method.invoke(obj, detail[1]);
        } catch (Exception e) {
            log.error("An exception occurred when parsing domain objects,source=" + source, e);
        }
    }
    return obj;
}
 
Example 3
Source Project: hadoop   File: MutableStat.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Construct a sample statistics metric
 * @param name        of the metric
 * @param description of the metric
 * @param sampleName  of the metric (e.g. "Ops")
 * @param valueName   of the metric (e.g. "Time", "Latency")
 * @param extended    create extended stats (stdev, min/max etc.) by default.
 */
public MutableStat(String name, String description,
                   String sampleName, String valueName, boolean extended) {
  String ucName = StringUtils.capitalize(name);
  String usName = StringUtils.capitalize(sampleName);
  String uvName = StringUtils.capitalize(valueName);
  String desc = StringUtils.uncapitalize(description);
  String lsName = StringUtils.uncapitalize(sampleName);
  String lvName = StringUtils.uncapitalize(valueName);
  numInfo = info(ucName +"Num"+ usName, "Number of "+ lsName +" for "+ desc);
  avgInfo = info(ucName +"Avg"+ uvName, "Average "+ lvName +" for "+ desc);
  stdevInfo = info(ucName +"Stdev"+ uvName,
                   "Standard deviation of "+ lvName +" for "+ desc);
  iMinInfo = info(ucName +"IMin"+ uvName,
                  "Interval min "+ lvName +" for "+ desc);
  iMaxInfo = info(ucName + "IMax"+ uvName,
                  "Interval max "+ lvName +" for "+ desc);
  minInfo = info(ucName +"Min"+ uvName, "Min "+ lvName +" for "+ desc);
  maxInfo = info(ucName +"Max"+ uvName, "Max "+ lvName +" for "+ desc);
  this.extended = extended;
}
 
Example 4
Source Project: big-c   File: MutableStat.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Construct a sample statistics metric
 * @param name        of the metric
 * @param description of the metric
 * @param sampleName  of the metric (e.g. "Ops")
 * @param valueName   of the metric (e.g. "Time", "Latency")
 * @param extended    create extended stats (stdev, min/max etc.) by default.
 */
public MutableStat(String name, String description,
                   String sampleName, String valueName, boolean extended) {
  String ucName = StringUtils.capitalize(name);
  String usName = StringUtils.capitalize(sampleName);
  String uvName = StringUtils.capitalize(valueName);
  String desc = StringUtils.uncapitalize(description);
  String lsName = StringUtils.uncapitalize(sampleName);
  String lvName = StringUtils.uncapitalize(valueName);
  numInfo = info(ucName +"Num"+ usName, "Number of "+ lsName +" for "+ desc);
  avgInfo = info(ucName +"Avg"+ uvName, "Average "+ lvName +" for "+ desc);
  stdevInfo = info(ucName +"Stdev"+ uvName,
                   "Standard deviation of "+ lvName +" for "+ desc);
  iMinInfo = info(ucName +"IMin"+ uvName,
                  "Interval min "+ lvName +" for "+ desc);
  iMaxInfo = info(ucName + "IMax"+ uvName,
                  "Interval max "+ lvName +" for "+ desc);
  minInfo = info(ucName +"Min"+ uvName, "Min "+ lvName +" for "+ desc);
  maxInfo = info(ucName +"Max"+ uvName, "Max "+ lvName +" for "+ desc);
  this.extended = extended;
}
 
Example 5
private void testAnnotationMethod(Method method, String methodNamePrefix, String methodName, Class<?> getArg,
		Class<?> setArg) throws NoSuchMethodException {
	if (isObjectMethodName(methodName)) {
		return;
	}
	if (methodNamePrefix != null) {
		methodName = methodNamePrefix + StringUtils.capitalize(methodName);
	}
	// test getter
	if (method.getReturnType() == boolean.class) {
		DatabaseFieldConfig.class.getMethod("is" + StringUtils.capitalize(methodName));
	} else {
		if (getArg == null) {
			DatabaseFieldConfig.class.getMethod("get" + StringUtils.capitalize(methodName));
		} else {
			DatabaseFieldConfig.class.getMethod("get" + StringUtils.capitalize(methodName), getArg);
		}
	}
	// test setter
	DatabaseFieldConfig.class.getMethod("set" + StringUtils.capitalize(methodName), setArg);
}
 
Example 6
private void processField(KieProcessFormField field, String langCode) throws ApsSystemException {
    String bpmLabel = KieApiUtil.getFieldProperty(field, "label");
    String fieldName = KieApiUtil.getI18nLabelProperty(field);
    if (org.apache.commons.lang.StringUtils.isNotBlank(bpmLabel)) {
        if (null == this.getI18nManager().getLabel(fieldName, langCode)) {
            this.saveEntandoLabel(fieldName, bpmLabel);
        }
    } else {
        if (null == this.getI18nManager().getLabel(fieldName, langCode)) {
            fieldName = StringUtils.capitalize(field.getName().replace("_"," "));

            int index =fieldName.lastIndexOf(" ");
            fieldName = fieldName.substring(index);

            this.saveEntandoLabel(fieldName, StringUtils.capitalize(field.getName().replace("_"," ")));
        }
    }
}
 
Example 7
/**
 * This method creates one option for every file that is found in the sounds directory.
 * As a label, the file extension is removed and the string is capitalized.
 *
 * @return a list of parameter options representing the sound files
 */
private List<ParameterOption> getSoundOptions() {
    List<ParameterOption> options = new ArrayList<>();
    File soundsDir = Paths.get(ConfigConstants.getConfigFolder(), AudioManager.SOUND_DIR).toFile();
    if (soundsDir.isDirectory()) {
        for (String fileName : soundsDir.list()) {
            if (fileName.contains(".") && !fileName.startsWith(".")) {
                String soundName = StringUtils.capitalize(fileName.substring(0, fileName.lastIndexOf(".")));
                options.add(new ParameterOption(fileName, soundName));
            }
        }
    }
    return options;
}
 
Example 8
Source Project: DotCi   File: GithubReposController.java    License: MIT License 5 votes vote down vote up
public void doRepoAction(final StaplerRequest req, final StaplerResponse rsp) throws InvocationTargetException, IllegalAccessException {
    final String[] tokens = StringUtils.split(req.getRestOfPath(), "/");
    final GithubRepoAction repoAction = getRepoAction(tokens[0]);
    if (repoAction != null) {
        final String methodToken = tokens.length > 1 ? tokens[1] : "index";
        final String methodName = "do" + StringUtils.capitalize(methodToken);
        final Method method = ReflectionUtils.getPublicMethodNamed(repoAction.getClass(), methodName);
        method.invoke(repoAction, req, rsp);
    }
}
 
Example 9
/**
 * <p>Returns a description of the location of where this exception occurred.</p>
 *
 * @return The location description. May return null.
 */
public String getLocation() {
    if (source == null) {
        return null;
    }
    String sourceMsg = StringUtils.capitalize(source.getDisplayName());
    if (lineNumber == null) {
        return sourceMsg;
    }
    return String.format("%s line: %d", sourceMsg, lineNumber);
}
 
Example 10
public AbstractLanguageSourceSet(String name, FunctionalSourceSet parent, String typeName, SourceDirectorySet source) {
    this.name = name;
    this.fullName = parent.getName() + StringUtils.capitalize(name);
    this.displayName = String.format("%s '%s:%s'", typeName, parent.getName(), name);
    this.source = source;
    super.builtBy(source.getBuildDependencies());
}
 
Example 11
private Method getSetter() {
    try{
        String setterName = "set" + StringUtils.capitalize(field.getName());
        return field.getDeclaringClass().getMethod(setterName, field.getType());
    } catch (NoSuchMethodException e) {
        throw new OptionValidationException(String.format("No setter for Option annotated field '%s' in class '%s'.",
                getElementName(), getDeclaredClass()));
    }
}
 
Example 12
Source Project: rice   File: RuleImpl.java    License: Educational Community License v2.0 5 votes vote down vote up
protected RuleExpression loadRuleExpression(String type) {
    if (type == null) {
        type = DEFAULT_RULE_EXPRESSION;
    }
    // type is of the format 'category:qualifier'
    // we just want the category
    int colon = type.indexOf(':');
    if (colon == -1) colon = type.length();
    type = type.substring(0, colon);
    type = StringUtils.capitalize(type);

    // load up the rule expression implementation
    String className = RULE_EXPRESSION_PACKAGE + "." + type + RULE_EXPRESSION_SUFFIX;
    Class<?> ruleExpressionClass;
    try {
        ruleExpressionClass = ClassLoaderUtils.getDefaultClassLoader().loadClass(className);
    } catch (ClassNotFoundException cnfe) {
        throw new RiceIllegalStateException("Rule expression implementation '" + className + "' not found", cnfe);
    }
    if (!RuleExpression.class.isAssignableFrom(ruleExpressionClass)) {
        throw new RiceIllegalStateException("Specified class '" + ruleExpressionClass + "' does not implement RuleExpression interface");
    }
    RuleExpression ruleExpression;
    try {
        ruleExpression = ((Class<RuleExpression>) ruleExpressionClass).newInstance();
    } catch (Exception e) {
    	if (e instanceof RuntimeException) {
    		throw (RuntimeException)e;
    	}
        throw new RiceIllegalStateException("Error instantiating rule expression implementation '" + ruleExpressionClass + "'", e);
    }

    return ruleExpression;
}
 
Example 13
Source Project: big-c   File: MutableQuantiles.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new {@link MutableQuantiles} for a metric that rolls itself
 * over on the specified time interval.
 * 
 * @param name
 *          of the metric
 * @param description
 *          long-form textual description of the metric
 * @param sampleName
 *          type of items in the stream (e.g., "Ops")
 * @param valueName
 *          type of the values
 * @param interval
 *          rollover interval (in seconds) of the estimator
 */
public MutableQuantiles(String name, String description, String sampleName,
    String valueName, int interval) {
  String ucName = StringUtils.capitalize(name);
  String usName = StringUtils.capitalize(sampleName);
  String uvName = StringUtils.capitalize(valueName);
  String desc = StringUtils.uncapitalize(description);
  String lsName = StringUtils.uncapitalize(sampleName);
  String lvName = StringUtils.uncapitalize(valueName);

  numInfo = info(ucName + "Num" + usName, String.format(
      "Number of %s for %s with %ds interval", lsName, desc, interval));
  // Construct the MetricsInfos for the quantiles, converting to percentiles
  quantileInfos = new MetricsInfo[quantiles.length];
  String nameTemplate = ucName + "%dthPercentile" + uvName;
  String descTemplate = "%d percentile " + lvName + " with " + interval
      + " second interval for " + desc;
  for (int i = 0; i < quantiles.length; i++) {
    int percentile = (int) (100 * quantiles[i].quantile);
    quantileInfos[i] = info(String.format(nameTemplate, percentile),
        String.format(descTemplate, percentile));
  }

  estimator = new SampleQuantiles(quantiles);

  this.interval = interval;
  scheduler.scheduleAtFixedRate(new RolloverSample(this), interval, interval,
      TimeUnit.SECONDS);
}
 
Example 14
public void show(List<ComponentDto> components) {
    this.components = components;

    removeAllItems();

    if (components == null) {
        return;
    }

    for (ComponentDto component : components) {
        // チェックボックス
        CheckBox checkBox = new CheckBox();
        checkBox.setImmediate(true);
        checkBox.setEnabled(false);
        if (selectedComponentNos.contains(component.getComponent().getComponentNo())) {
            checkBox.setValue(true);
        } else {
            checkBox.setValue(false);
        }

        checkBox.addListener(new Property.ValueChangeListener() {
            @Override
            public void valueChange(Property.ValueChangeEvent event) {
                // チェックボックスの有効/無効を制御
                changeCheckEnabled();

                // テーブル再描画
                requestRepaint();
            }
        });

        // サービス名
        String serviceName = component.getComponent().getComponentName();
        if (StringUtils.isNotEmpty(component.getComponent().getComment())) {
            serviceName = component.getComponent().getComment() + "\n[" + serviceName + "]";
        }
        Label serviceNameLabel = new Label(serviceName, Label.CONTENT_PREFORMATTED);
        serviceNameLabel.setHeight(COLUMN_HEIGHT);

        // ステータス
        String status = null;
        if (instance != null) {
            for (ComponentInstanceDto componentInstance : instance.getComponentInstances()) {
                if (componentInstance.getComponentInstance().getComponentNo()
                        .equals(component.getComponent().getComponentNo())) {
                    status = componentInstance.getComponentInstance().getStatus();
                    break;
                }
            }
        }
        if (StringUtils.isEmpty(status)) {
            status = "Stopped";
        } else {
            status = StringUtils.capitalize(StringUtils.lowerCase(status));
        }

        Icons statusIcon = Icons.fromName(status);
        Label statusLabel = new Label(IconUtils.createImageTag(getApplication(), statusIcon, status),
                Label.CONTENT_XHTML);
        statusLabel.setHeight(COLUMN_HEIGHT);

        addItem(new Object[] { checkBox, serviceNameLabel, statusLabel },
                component.getComponent().getComponentNo());
    }

    changeCheckEnabled();
}
 
Example 15
Source Project: restcommander   File: UniqueCheck.java    License: Apache License 2.0 4 votes vote down vote up
/**
 *
 * {@inheritDoc}
 */
@Override
public boolean isSatisfied(Object validatedObject, Object value,
        OValContext context, Validator validator) {
    requireMessageVariablesRecreation();
    if (value == null) {
        return true;
    }
    final String[] propertyNames = getPropertyNames(
            ((FieldContext) context).getField().getName());
    final GenericModel model = (GenericModel) validatedObject;
    final Model.Factory factory =  Model.Manager.factoryFor(model.getClass());
    final String keyProperty = StringUtils.capitalize(factory.keyName());
    final Object keyValue = factory.keyValue(model);
    //In case of an update make sure that we won't read the current record from database.
    final boolean isUpdate = (keyValue != null);
    final String entityName = model.getClass().getName();
    final StringBuffer jpql = new StringBuffer("SELECT COUNT(o) FROM ");
    jpql.append(entityName).append(" AS o where ");
    final Object[] values = new Object[isUpdate ? propertyNames.length + 1 :
            propertyNames.length];
    final Class clazz = validatedObject.getClass();
    for (int i = 0; i < propertyNames.length; i++) {
        Field field = getField(clazz, propertyNames[i]);
        field.setAccessible(true);
        try {
            values[i] = field.get(model);
        } catch (Exception ex) {
            throw new UnexpectedException(ex);
        }
        if (i > 0) {
            jpql.append(" And ");
        }
        jpql.append("o.").append(propertyNames[i]).append(" = ? ");
    }
    if (isUpdate) {
        values[propertyNames.length] = keyValue;
        jpql.append(" and ").append(keyProperty).append(" <>  ?");
    }
    return JPQL.instance.count(entityName, jpql.toString(), values) == 0L;
}
 
Example 16
Source Project: systemds   File: CNodeUnary.java    License: Apache License 2.0 4 votes vote down vote up
public String getVectorPrimitiveName() {
	String [] tmp = this.name().split("_");
	return StringUtils.capitalize(tmp[1].toLowerCase());
}
 
Example 17
protected String getCapDisplayName() {
    return StringUtils.capitalize(getDisplayName());
}
 
Example 18
Source Project: bdf3   File: SubQueryParser.java    License: Apache License 2.0 4 votes vote down vote up
public SubQueryParser(Linq linq, Class<?> domainClass) {
	this.linq = linq;
	this.domainClass = domainClass;	
	this.foreignKeys = new String[]{ Introspector.decapitalize(domainClass.getSimpleName()) 
			+ StringUtils.capitalize(JpaUtil.getIdName(domainClass)) };
}
 
Example 19
Source Project: atlas   File: AtlasProxy.java    License: Apache License 2.0 4 votes vote down vote up
public static void addAtlasProxyClazz(Document document, Set<String> nonProxyChannels,  Result result) {

        Element root = document.getRootElement();// Get the root node

        List<? extends Node> serviceNodes = root.selectNodes("//@android:process");

        String packageName = root.attribute("package").getStringValue();

        Set<String> processNames = new HashSet<>();
        processNames.add(packageName);

        for (Node node : serviceNodes) {
            if (null != node && StringUtils.isNotEmpty(node.getStringValue())) {
                String value = node.getStringValue();
                processNames.add(value);
            }
        }

        processNames.removeAll(nonProxyChannels);

        List<String> elementNames = Lists.newArrayList("activity");

        Element applicationElement = root.element("application");

        for (String processName : processNames) {

            boolean isMainPkg = packageName.equals(processName);
            //boolean isMainPkg = true;
            String processClazzName = processName.replace(":", "").replace(".", "_");

            for (String elementName : elementNames) {

                String fullClazzName = "ATLASPROXY_" +  (isMainPkg ? "" : (packageName.replace(".", "_") + "_" )) +  processClazzName + "_" + StringUtils.capitalize(elementName);

                if ("activity".equals(elementName)) {
                    result.proxyActivities.add(fullClazzName);
                } else if ("service".equals(elementName)) {
                    result.proxyServices.add(fullClazzName);
                } else {
                    result.proxyProviders.add(fullClazzName);
                }

                Element newElement = applicationElement.addElement(elementName);
                newElement.addAttribute("android:name", ATLAS_PROXY_PACKAGE + "." + fullClazzName);

                if (!packageName.equals(processName)) {
                    newElement.addAttribute("android:process", processName);
                }

                boolean isProvider = "provider".equals(elementName);
                if (isProvider) {
                    newElement.addAttribute("android:authorities",
                                            ATLAS_PROXY_PACKAGE + "." + fullClazzName);
                }

            }

        }

    }
 
Example 20
protected String getCapDisplayName() {
    return StringUtils.capitalize(getDisplayName());
}