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

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

Introduction

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

Prototype

public static String capitalize(final 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.sixt.service.framework.protobuf.ProtobufUtil.java

/**
 * Converts a proto file name into a class name according to the rules defined by protobuf:
 * https://developers.google.com/protocol-buffers/docs/reference/java-generated
 *
 * The file name will be camel cased (and underscores, hyphens etc. stripped out).
 * @param protoFileName The file name to process: e.g. my_service.proto
 * @return The class name: MyService/*w  ww . ja v  a  2  s  .c  o  m*/
 */
public static String toClassName(String protoFileName) {

    if (protoFileName == null) {
        return null;
    }
    String fileName = FileUtil.stripPath(protoFileName);
    fileName = FileUtil.stripExtension(fileName);

    String parts[] = fileName.split("[^A-Za-z0-9]");

    StringBuilder classNameBuilder = new StringBuilder();
    for (String part : parts) {
        classNameBuilder.append(StringUtils.capitalize(part));
    }
    return classNameBuilder.toString();
}

From source file:ch.cyberduck.core.worker.AbstractTransferWorker.java

@Override
public Boolean run(final Session<?> source, final Session<?> destination) throws BackgroundException {
    final String lock = sleep.lock();
    try {//from w w w .j a v  a  2s.  c o  m
        // No need for session. Return prematurely to pool
        this.release(source, Connection.source);
        this.release(destination, Connection.destination);
        if (log.isDebugEnabled()) {
            log.debug(String.format("Start transfer with prompt %s and options %s", prompt, options));
        }
        final TransferAction action;
        // Determine the filter to match files against
        action = transfer.action(source, destination, options.resumeRequested, options.reloadRequested, prompt,
                new DisabledListProgressListener() {
                    @Override
                    public void message(final String message) {
                        progress.message(message);
                    }
                });
        if (log.isDebugEnabled()) {
            log.debug(String.format("Selected transfer action %s", action));
        }
        if (action.equals(TransferAction.cancel)) {
            if (log.isInfoEnabled()) {
                log.info(String.format("Transfer %s canceled by user", this));
            }
            throw new ConnectionCanceledException();
        }
        // Reset the cached size of the transfer and progress value
        transfer.reset();
        // Calculate information about the files in advance to give progress information
        for (TransferItem next : transfer.getRoots()) {
            this.prepare(next.remote, next.local, new TransferStatus().exists(true), action);
        }
        this.await();
        meter.reset();
        transfer.pre(source, destination, table, connectionCallback);
        // Transfer all files sequentially
        for (TransferItem next : transfer.getRoots()) {
            this.transfer(next, action);
        }
        this.await();
    } finally {
        transfer.post(source, destination, table, connectionCallback);
        if (transfer.isReset()) {
            growl.notify(transfer.isComplete()
                    ? String.format("%s complete", StringUtils.capitalize(transfer.getType().name()))
                    : "Transfer incomplete", transfer.getName());
        }
        sleep.release(lock);
    }
    return true;
}

From source file:com.adobe.acs.commons.mcp.impl.processes.FolderRelocator.java

@Override
public void buildProcess(ProcessInstance instance, ResourceResolver rr)
        throws LoginException, RepositoryException {
    validateInputs(rr);// w  w w  . j a  va  2 s .c o  m
    Session ses = rr.adaptTo(Session.class);
    requiredFolderPrivileges = getPrivilegesFromNames(ses, requiredFolderPrivilegeNames);
    requiredNodePrivileges = getPrivilegesFromNames(ses, requiredNodePrivilegeNames);
    instance.defineCriticalAction("Validate ACLs", rr, this::validateAllAcls);
    instance.defineCriticalAction("Build target folders", rr, this::buildTargetFolders)
            .onFailure(this::abortStep2);
    instance.defineCriticalAction("Move nodes", rr, this::moveNodes);
    instance.defineCriticalAction("Remove old folders", rr, this::removeSourceFolders);
    if (sourcePaths.length > 1) {
        instance.getInfo().setDescription("Move " + sourcePaths.length + " folders to " + destinationPath);
    } else {
        String verb = StringUtils.capitalize(mode.name().toLowerCase());
        instance.getInfo().setDescription(verb + " " + sourcePaths[0] + " to " + destinationPath);
    }
}

From source file:info.okoshi.visitor.AccessorsGenerateVisitor.java

/**
 * Generate setter method.<br>/*  w  ww . j  av a  2s .  c o m*/
 *
 * @param node
 *          {@link FieldDeclaration} object
 * @param ast
 *          {@link AST} object
 * @param name
 *          name of field variable
 * @return {@link MethodDeclaration} object
 */
@SuppressWarnings("unchecked")
private MethodDeclaration generateSetter(FieldDeclaration node, AST ast, String name) {
    MethodDeclaration setter = ast.newMethodDeclaration();
    if (node.getJavadoc() != null) {
        setter.setJavadoc(createSetterJavadoc(node, ast, name));
    }
    setter.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
    setter.setName(ast.newSimpleName("set" + StringUtils.capitalize(name)));

    SingleVariableDeclaration singleVariable = ast.newSingleVariableDeclaration();
    singleVariable.setType((Type) ASTNode.copySubtree(ast, node.getType()));
    singleVariable.setName(ast.newSimpleName(name));
    setter.parameters().add(singleVariable);

    Block block = ast.newBlock();
    Assignment assignment = ast.newAssignment();
    FieldAccess fieldAccess = ast.newFieldAccess();
    fieldAccess.setExpression(ast.newThisExpression());
    fieldAccess.setName(ast.newSimpleName(name));
    assignment.setLeftHandSide(fieldAccess);
    assignment.setOperator(Assignment.Operator.ASSIGN);
    assignment.setRightHandSide(ast.newSimpleName(name));
    block.statements().add(ast.newExpressionStatement(assignment));
    setter.setBody(block);

    return setter;
}

From source file:com.qtplaf.library.util.Calendar.java

/**
 * Returns an array of localized names of months.
 *
 * @return An array of names.//from   ww w  .ja  v  a 2s . c  o  m
 * @param locale The desired locale.
 * @param capitalized A boolean to capitalize the name.
 */
public static String[] getLongMonths(Locale locale, boolean capitalized) {

    DateFormatSymbols sysd = new DateFormatSymbols(locale);
    String[] dsc = sysd.getMonths();
    if (capitalized) {
        for (int i = 0; i < dsc.length; i++) {
            dsc[i] = StringUtils.capitalize(dsc[i]);
        }
    }
    return dsc;
}

From source file:com.wrmsr.wava.compile.memory.LoadStoreCompilerImpl.java

private JMethod createLengthSignedLoad(Class<?> p, Class<?> t, int len) {
    return new JMethod(immutableEnumSet(JAccess.PROTECTED, JAccess.FINAL), JTypeSpecifier.of(p.getName()),
            JName.of("_load" + StringUtils.capitalize(p.getName()) + len + "s"),
            ImmutableList.of(new JArg(JTypeSpecifier.of("int"),
                    JName.of("ptr"))),
            Optional.of(//from   w ww  . j  a v  a  2 s  . co m
                    new JBlock(
                            ImmutableList
                                    .of(new JReturn(
                                            Optional.of(
                                                    new JCast(JTypeSpecifier.of(p.getName()),
                                                            JMethodInvocation.of(
                                                                    JQualifiedName.of("this", "_memory",
                                                                            "get" + (t == byte.class ? ""
                                                                                    : StringUtils.capitalize(
                                                                                            t.getName()))),
                                                                    ImmutableList.of(new JIdent(
                                                                            JQualifiedName.of("ptr")))))))))));
}

From source file:com.moviejukebox.scanner.artwork.FanartTvScanner.java

/**
 * Determine the overwrite property from the artwork type
 *
 * @return//w ww.  j a v  a 2  s.c o  m
 */
private boolean setOverwrite() {
    String propName = "mjb.force" + StringUtils.capitalize(artworkTypeName) + "Overwrite";
    artworkOverwrite = PropertiesUtil.getBooleanProperty(propName, Boolean.FALSE);
    //        logger.debug(logMessage + propName + "=" + artworkOverwrite);
    return artworkOverwrite;
}

From source file:at.gridtec.lambda4j.generator.processors.impl.NameProcessor.java

@Override
@Nonnull/* w ww.  j  a va2 s .c  om*/
protected List<LambdaEntity> process(@Nonnull final LambdaEntity lambda) {
    final List<LambdaEntity> lambdas = new LinkedList<LambdaEntity>();
    final LambdaEntity copy = LambdaUtils.copy(lambda);
    StringBuilder nameBuilder = new StringBuilder();

    // Lambdas which are throwable will have throwable identifier
    if (lambda.isThrowable()) {
        nameBuilder.append(THROWABLE_IDENTIFIER);
    }

    // Special Rule: Operators will have special arity identifiers
    if (LambdaUtils.isOfTypeOperator(lambda)) {
        if (LambdaUtils.isPrimitiveType(lambda.getReturnType())) {
            nameBuilder.append(cap(lambda.getReturnType().getTypeSimpleName()));
        }
        if (lambda.getArity() == 1) {
            nameBuilder.append(OPERATOR_ARITY_ONE_IDENTIFIER);
        } else if (lambda.getArity() == 2) {
            nameBuilder.append(OPERATOR_ARITY_TWO_IDENTIFIER);
        } else if (lambda.getArity() == 3) {
            nameBuilder.append(OPERATOR_ARITY_THREE_IDENTIFIER);
        }
    }

    // Special Rule: Lambda is of type supplier and has primitive return, append primitive identifier
    else if (LambdaUtils.isOfTypeSupplier(lambda) && LambdaUtils.isPrimitiveType(lambda.getReturnType())) {
        nameBuilder.append(cap(lambda.getReturnType().getTypeSimpleName()));
    }

    // All other types will be named using normal schema, unless Comparator or Runnable
    else if (!LambdaUtils.isOfTypeComparator(lambda) && !LambdaUtils.isOfTypeRunnable(lambda)) {

        // Lambda with arity 1
        if (lambda.getArity() == 1) {

            // Special Rule: Lambda is of type function and input one type is not primitive, but return type is it,
            // then append 'To' identifier at start (needed as some lambda require arity after 'To' identifier)
            notToIdentifier(nameBuilder, lambda, lambda.getFirstInputType());

            // Lambda input one is primitive, so append primitive type name
            if (LambdaUtils.isPrimitiveType(lambda.getFirstInputType())) {
                nameBuilder.append(cap(lambda.getFirstInputType().getTypeSimpleName()));
            }

            // Special Rule: Lambda is of type function which has primitive input one and return type, so append 'To'
            // identifier at end (normal for lambda with primitive return)
            toIdentifier(nameBuilder, lambda, lambda.getFirstInputType());
        }

        // Lambda with arity 2
        else if (lambda.getArity() == 2) {

            // Special Rule: Lambda is of type function and input two type is not primitive, but return type is it,
            // then append 'To' identifier at start (needed as some lambda require arity after 'To' identifier)
            notToIdentifier(nameBuilder, lambda, lambda.getSecondInputType());

            // Lambda input one type is generic and input two type is primitive, so append 'Obj' identifier;
            // otherwise just append normal 'Bi' identifier
            if (!LambdaUtils.isPrimitiveType(lambda.getFirstInputType())
                    && LambdaUtils.isPrimitiveType(lambda.getSecondInputType())) {
                objIdentifier(nameBuilder, null, null);
            } else {
                nameBuilder.append(ARITY_TWO_IDENTIFIER);
            }

            // Lambda input two is primitive, so append primitive type name
            if (LambdaUtils.isPrimitiveType(lambda.getSecondInputType())) {
                nameBuilder.append(cap(lambda.getSecondInputType().getTypeSimpleName()));
            }

            // Special Rule: Lambda is of type function which has primitive input two and return type, so append 'To'
            // identifier at end (normal for lambda with primitive return)
            toIdentifier(nameBuilder, lambda, lambda.getSecondInputType());
        }

        // Lambda with arity 3
        else if (lambda.getArity() == 3) {

            // Special Rule: Lambda is of type function and input three type is not primitive, but return type is it,
            // then append 'To' identifier at start (needed as some lambda require arity after 'To' identifier)
            notToIdentifier(nameBuilder, lambda, lambda.getThirdInputType());

            // Lambda input one and two types are generic and input three type is primitive, so append 'BiObj' identifier
            if (!LambdaUtils.isPrimitiveType(lambda.getFirstInputType())
                    && !LambdaUtils.isPrimitiveType(lambda.getSecondInputType())
                    && LambdaUtils.isPrimitiveType(lambda.getThirdInputType())) {
                objIdentifier(nameBuilder, ARITY_TWO_IDENTIFIER, null);
            }
            // Lambda input one is generic and input two and three types are primitive, so append 'ObjBi' identifier
            else if (!LambdaUtils.isPrimitiveType(lambda.getFirstInputType())
                    && LambdaUtils.isPrimitiveType(lambda.getSecondInputType())
                    && LambdaUtils.isPrimitiveType(lambda.getThirdInputType())) {
                objIdentifier(nameBuilder, null, ARITY_TWO_IDENTIFIER);
            } else {
                nameBuilder.append(ARITY_THREE_IDENTIFIER);
            }

            // Lambda input three is primitive, so append primitive type name
            if (LambdaUtils.isPrimitiveType(lambda.getThirdInputType())) {
                nameBuilder.append(cap(lambda.getThirdInputType().getTypeSimpleName()));
            }

            // Special Rule: Lambda is of type function which has primitive input three and return type, so append 'To'
            // identifier at end (normal for lambda with primitive return)
            toIdentifier(nameBuilder, lambda, lambda.getThirdInputType());
        }
    }

    // Append lambda type simple name in name
    nameBuilder.append(StringUtils.capitalize(lambda.getType().getSimpleName()));

    // Apply builder name to name field in lambda copy
    copy.setName(nameBuilder.toString());
    lambdas.addAll(next(copy));
    return lambdas;
}

From source file:com.moviejukebox.plugin.FilmwebPlugin.java

/**
 * Get the actor information from the /cast/actors page
 *
 * @param movie//from www.  ja v a 2s.  c om
 * @param xml
 * @return
 */
private static boolean scanCastInformation(Movie movie, String xmlCast) {
    boolean overrideNormal = OverrideTools.checkOverwriteActors(movie, FILMWEB_PLUGIN_ID);
    boolean overridePeople = OverrideTools.checkOverwritePeopleActors(movie, FILMWEB_PLUGIN_ID);

    String jobActor = StringUtils.capitalize(Filmography.JOB_ACTOR);

    if (overrideNormal || overridePeople) {
        Matcher mActors = P_ACTORS.matcher(xmlCast);

        while (mActors.find()) {
            String name = mActors.group(1);
            String id = mActors.group(2);
            String role = mActors.group(3);
            String url = FILMWEB_URL + "/person/" + id;

            if (overrideNormal) {
                movie.addActor(name, FILMWEB_PLUGIN_ID);
                movie.addActor(id, name, role, url, Movie.UNKNOWN, FILMWEB_PLUGIN_ID);
            }
            if (overridePeople) {
                movie.addPerson(id, name, url, jobActor, role, Movie.UNKNOWN, FILMWEB_PLUGIN_ID);
            }
        }

    }

    return Boolean.TRUE;
}

From source file:com.qtplaf.library.util.Calendar.java

/**
 * Returns an array of localized names of week days.
 *
 * @return An array of names.//from   w  w w .j a v  a 2s .co  m
 * @param locale The desired locale.
 * @param capitalized A boolean to capitalize the name.
 */
public static String[] getShortDays(Locale locale, boolean capitalized) {

    DateFormatSymbols sysd = new DateFormatSymbols(locale);
    String[] dsc = sysd.getShortWeekdays();
    if (capitalized) {
        for (int i = 0; i < dsc.length; i++) {
            dsc[i] = StringUtils.capitalize(dsc[i]);
        }
    }
    return dsc;
}