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

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

Introduction

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

Prototype

public static String uncapitalize(String str) 

Source Link

Document

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

Usage

From source file:org.apache.hadoop.metrics2.lib.MetricMutableQuantiles.java

/**
 * Instantiates a new {@link MetricMutableQuantiles} for a metric that rolls itself over on the
 * specified time interval./* w  ww. ja v  a2  s.  c o  m*/
 *
 * @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 MetricMutableQuantiles(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 = "%s%dthPercentile%dsInterval%s";
    String descTemplate = "%d percentile %s with %d second interval for %s";
    for (int i = 0; i < quantiles.length; i++) {
        int percentile = (int) (100 * quantiles[i].quantile);
        quantileInfos[i] = info(String.format(nameTemplate, ucName, percentile, interval, uvName),
                String.format(descTemplate, percentile, lvName, interval, desc));
    }

    estimator = new MetricSampleQuantiles(quantiles);
    executor = new MetricsExecutorImpl();
    this.interval = interval;
    executor.getExecutor().scheduleAtFixedRate(new RolloverSample(this), interval, interval, TimeUnit.SECONDS);
}

From source file:org.apache.hadoop.metrics2.lib.MutableHistogram.java

public MutableHistogram(String name, String description) {
    this.name = StringUtils.capitalize(name);
    this.desc = StringUtils.uncapitalize(description);
    sample = new ExponentiallyDecayingSample(DEFAULT_SAMPLE_SIZE, DEFAULT_ALPHA);
    count = new AtomicLong();
    min = new AtomicLong(Long.MAX_VALUE);
    max = new AtomicLong(Long.MIN_VALUE);
    sum = new AtomicLong();
}

From source file:org.apache.hadoop.metrics2.lib.MutableQuantiles.java

/**
 * Instantiates a new {@link MutableQuantiles} for a metric that rolls itself
 * over on the specified time interval./*from  w ww  . j  a  va  2s.c o  m*/
 * 
 * @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);
}

From source file:org.apache.hadoop.metrics2.lib.MutableStat.java

/**
 * Construct a sample statistics metric/* ww w  .jav a  2 s. c  om*/
 * @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;
}

From source file:org.apache.hadoop.metrics2.lib.MutableStatShare.java

/**
 * Construct a sample statistics metric//from  www.ja  v  a  2  s.  c  om
 * @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 MutableStatShare(String name, String description, String sampleName, String valueName, boolean extended,
        MutableCounterLong bytes) {
    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);
    initInfo = info(ucName + "Init" + uvName, "Init bytes " + lvName + " for " + desc);
    endInfo = info(ucName + "End" + uvName, "Total bytes " + lvName + " for " + desc);
    intervalInfo = info(ucName + "Interval" + uvName, "Total bytes " + lvName + " for " + desc);
    bytesInfo = info(ucName + "Class" + uvName, "Total bytes " + lvName + " for " + desc);
    sharedInfo = info(ucName + "Shared" + uvName, "Total bytes " + lvName + " for " + desc);
    weightInfo = info(ucName + "Weight" + uvName, "Valor" + lvName + " for " + desc);
    queuedInfo = info(ucName + "Queued" + "Requests", "num requests" + lvName + " for " + desc);
    this.queuedRequests = 0;
    this.totalBytesProcessed = bytes;
    this.initTotalBytesProcessed = bytes.value();
    this.extended = extended;
}

From source file:org.apache.openjpa.lib.util.Options.java

/**
 * Matches a key to an object/setter pair.
 *
 * @param key the key given at the command line; may be of the form
 * 'foo.bar' to signify the 'bar' property of the 'foo' owned object
 * @param match an array of length 2, where the first index is set
 * to the object to retrieve the setter for
 * @return true if a match was made, false otherwise; additionally,
 * the first index of the match array will be set to
 * the matching object and the second index will be
 * set to the setter method or public field for the
 * property named by the key/*  w w w  . ja v a 2  s.c om*/
 */
private static boolean matchOptionToMember(String key, Object[] match) throws Exception {
    if (StringUtils.isEmpty(key))
        return false;

    // unfortunately we can't use bean properties for setters; any
    // setter with more than 1 argument is ignored; calculate setter and getter
    // name to look for
    String[] find = Strings.split(key, ".", 2);
    String base = StringUtils.capitalize(find[0]);
    String set = "set" + base;
    String get = "get" + base;

    // look for a setter/getter matching the key; look for methods first
    Class<? extends Object> type = match[0].getClass();
    Method[] meths = type.getMethods();
    Method setMeth = null;
    Method getMeth = null;
    Class[] params;
    for (int i = 0; i < meths.length; i++) {
        if (meths[i].getName().equals(set)) {
            params = meths[i].getParameterTypes();
            if (params.length == 0)
                continue;
            if (params[0].isArray())
                continue;

            // use this method if we haven't found any other setter, if
            // it has less parameters than any other setter, or if it uses
            // string parameters
            if (setMeth == null)
                setMeth = meths[i];
            else if (params.length < setMeth.getParameterTypes().length)
                setMeth = meths[i];
            else if (params.length == setMeth.getParameterTypes().length && params[0] == String.class)
                setMeth = meths[i];
        } else if (meths[i].getName().equals(get))
            getMeth = meths[i];
    }

    // if no methods found, check for public field
    Member setter = setMeth;
    Member getter = getMeth;
    if (setter == null) {
        Field[] fields = type.getFields();
        String uncapBase = StringUtils.uncapitalize(find[0]);
        for (int i = 0; i < fields.length; i++) {
            if (fields[i].getName().equals(base) || fields[i].getName().equals(uncapBase)) {
                setter = fields[i];
                getter = fields[i];
                break;
            }
        }
    }

    // if no way to access property, give up
    if (setter == null && getter == null)
        return false;

    // recurse on inner object with remainder of key?
    if (find.length > 1) {
        Object inner = null;
        if (getter != null)
            inner = invoke(match[0], getter, null);

        // if no getter or current inner is null, try to create a new
        // inner instance and set it in object
        if (inner == null && setter != null) {
            Class<?> innerType = getType(setter)[0];
            try {
                inner = AccessController.doPrivileged(J2DoPrivHelper.newInstanceAction(innerType));
            } catch (PrivilegedActionException pae) {
                throw pae.getException();
            }
            invoke(match[0], setter, new Object[] { inner });
        }
        match[0] = inner;
        return matchOptionToMember(find[1], match);
    }

    // got match; find setter for property
    match[1] = setter;
    return match[1] != null;
}

From source file:org.apache.tika.server.resource.TikaResource.java

/**
 * Utility method to set a property on a class via reflection.
 *
 * @param httpHeaders the HTTP headers set.
 * @param object      the <code>Object</code> to set the property on.
 * @param key         the key of the HTTP Header.
 * @param prefix      the name of the HTTP Header prefix used to find property.
 * @throws WebApplicationException thrown when field cannot be found.
 *//*from  w  w  w  . j ava  2 s. c  om*/
private static void processHeaderConfig(MultivaluedMap<String, String> httpHeaders, Object object, String key,
        String prefix) {
    try {
        String property = StringUtils.removeStart(key, prefix);
        Field field = object.getClass().getDeclaredField(StringUtils.uncapitalize(property));

        field.setAccessible(true);
        if (field.getType() == String.class) {
            field.set(object, httpHeaders.getFirst(key));
        } else if (field.getType() == int.class) {
            field.setInt(object, Integer.parseInt(httpHeaders.getFirst(key)));
        } else if (field.getType() == double.class) {
            field.setDouble(object, Double.parseDouble(httpHeaders.getFirst(key)));
        } else if (field.getType() == boolean.class) {
            field.setBoolean(object, Boolean.parseBoolean(httpHeaders.getFirst(key)));
        } else {
            //couldn't find a directly accessible field
            //try for setX(String s)
            String setter = StringUtils.uncapitalize(property);
            setter = "set" + setter.substring(0, 1).toUpperCase(Locale.US) + setter.substring(1);
            Method m = null;
            try {
                m = object.getClass().getMethod(setter, String.class);
            } catch (NoSuchMethodException e) {
                //swallow
            }
            if (m != null) {
                m.invoke(object, httpHeaders.getFirst(key));
            }
        }
    } catch (Throwable ex) {
        throw new WebApplicationException(
                String.format(Locale.ROOT, "%s is an invalid %s header", key, X_TIKA_OCR_HEADER_PREFIX));
    }
}

From source file:org.apache.torque.templates.transformer.om.FieldHelper.java

/**
 * Returns the name of the field from a setter name.
 * Removes the "set" prefix and decapitalizes the remainder.
 *
 * @param setterName the name of the setterName, not null, length > 3.
 *
 * @return the field name, not null.// w  w w . j  av a 2s .c o  m
 */
public static String getFieldNameFromSetterName(String setterName) {
    String fieldName = StringUtils.uncapitalize(setterName.substring(SET.length()));
    return fieldName;
}

From source file:org.apache.torque.templates.transformer.om.OMColumnTransformer.java

/**
 * Sets the fieldName attribute of the column element if it is not
 * already set./* ww  w .  ja v  a  2s  .  c  o m*/
 * The javaName attribute of the column must be set.
 *
 * @param columnElement the column element, not null.
 */
protected void setFieldNameAttribute(SourceElement columnElement) {
    if (columnElement.getAttribute(JavaFieldAttributeName.FIELD_NAME) != null) {
        return;
    }
    String javaName = (String) columnElement.getAttribute(TorqueSchemaAttributeName.JAVA_NAME);
    String fieldName = StringUtils.uncapitalize(javaName);
    fieldName = reservedJavaWordsWrapper.process(fieldName);
    columnElement.setAttribute(JavaFieldAttributeName.FIELD_NAME, fieldName);
}

From source file:org.apache.torque.templates.transformer.om.OMTableAndViewTransformer.java

/**
 * Sets the fieldName attribute of the table element if it is not
 * already set. The field name can be used to contain a database object
 * corresponding to the table.//from  w w w . ja  va 2 s  .co m
 * The javaName attribute of the column must be set.
 *
 * @param tableElement the table element, not null.
 */
protected void setFieldNameAttribute(SourceElement tableElement) {
    if (tableElement.getAttribute(JavaFieldAttributeName.FIELD_NAME) != null) {
        return;
    }
    String javaName = (String) tableElement.getAttribute(TorqueSchemaAttributeName.JAVA_NAME);
    String fieldName = StringUtils.uncapitalize(javaName);
    fieldName = reservedJavaWordsWrapper.process(fieldName);
    tableElement.setAttribute(JavaFieldAttributeName.FIELD_NAME, fieldName);
}