List of usage examples for org.apache.commons.lang3 StringUtils uncapitalize
public static String uncapitalize(final String str)
Uncapitalizes a String, changing the first letter to lower case as per Character#toLowerCase(char) .
From source file:com.quartercode.femtoweb.impl.ActionUriResolver.java
/** * Returns the URI of the given {@link Action} which must be located in the given package. * See {@link Context#getUri(Class)} for more information. * * @param actionBasePackage The package name which will be removed from the start of the action class name. * Thereby, package names like {@code com.quartercode.femtowebtest.actions} are not included in URIs. * @param action The action class whose URI should be returned. * @return The URI the given action class is mapped to. */// w w w .j a v a 2s. com public static String getUri(String actionBasePackage, Class<? extends Action> action) { String actionFQCN = action.getName(); // Verify that the action class is // - not an inner class // - not called "Action" // - ends with action Validate.isTrue(!StringUtils.contains(actionFQCN, '$'), "Action classes are not allowed to be inner classes; '%s' is therefore invalid", actionFQCN); Validate.isTrue(!actionFQCN.endsWith(".Action"), "Actions classes which are just called 'Action' are disallowed"); Validate.isTrue(actionFQCN.endsWith("Action"), "Actions classes must end with 'Action'; '%s' is therefore invalid", actionFQCN); // Verify that the action class is inside the base package Validate.isTrue(actionFQCN.startsWith(actionBasePackage), "Cannot retrieve URI of action class '%s' because it doesn't start with the set action base package '%s'", actionFQCN, actionBasePackage); // Retrieve the name of the action class without the base package String actionName = actionFQCN.substring(actionBasePackage.length() + 1); // Replace all "." with "/", add an "/" to the front, uncapitalize the last URI part, remove "Action" from the last URI part // Example: "path.to.SomeTestAction" -> "/path/to/someTest") String[] actionNameComponents = splitAtLastSeparator(actionName, "."); String uriDir = actionNameComponents[0].replace('.', '/'); String uriName = StringUtils.uncapitalize(StringUtils.removeEnd(actionNameComponents[1], "Action")); return "/" + joinNonBlankItems("/", uriDir, uriName); }
From source file:eu.crisis_economics.abm.dashboard.AvailableParameter.java
public AvailableParameter(final ParameterInfo info, final Class<?> modelClass) { if (info == null) throw new IllegalArgumentException("AvailableParameter(): null parameter."); this.info = info; Class<?> parentClass = modelClass; if (info.isSubmodelParameter()) { parentClass = ((ISubmodelGUIInfo) info).getParentValue(); }/*from ww w . ja v a 2s . c om*/ Field declaredField = null; while (declaredField == null) { try { declaredField = parentClass.getDeclaredField(StringUtils.uncapitalize(info.getName())); } catch (NoSuchFieldException e) { parentClass = parentClass.getSuperclass(); if (parentClass == null) { // throw new IllegalStateException("Could not find field for parameter " + info.getName() + " in " + startClass); break; } } } if (declaredField != null) { for (final Annotation element : declaredField.getAnnotations()) { if (element.annotationType().getName() != Layout.class.getName()) // Proxies continue; final Class<? extends Annotation> type = element.annotationType(); try { displayName = (String) (type.getMethod("FieldName").invoke(element)); } catch (IllegalArgumentException e) { } catch (SecurityException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } catch (NoSuchMethodException e) { } } } if (displayName == null) { displayName = info.getName().replaceAll("([A-Z])", " $1"); } }
From source file:com.iorga.iraj.json.ContextParamsContextCaller.java
public ContextParamsContextCaller(final String elementName, final AnnotatedElement annotatedElement, final Class<?> declaringClass, final ContextParams contextParamsAnnotation) { final ContextPath contextPathAnnotation = annotatedElement.getAnnotation(ContextPath.class); // First we have to know what is the first context path part of the target annotated member final String nextPath; if (contextPathAnnotation != null) { // the context path is not null, let's take the first element as a key for the context map final String contextPath = contextPathAnnotation.value(); contextMapKey = StringUtils.substringBefore(contextPath, "."); nextPath = StringUtils.substringAfter(contextPath, "."); } else {//from w w w. j a v a 2 s . c om // No @ContextPath, let's take the elementName contextMapKey = elementName; nextPath = null; } // Now search the @ContextParam corresponding to the targetAnnotatedMember ContextCaller nextContextCaller = null; Type returnType = null; for (final ContextParam contextParam : contextParamsAnnotation.value()) { String contextName = contextParam.name(); final Class<?> contextClass = contextParam.value(); if (StringUtils.isBlank(contextName)) { contextName = StringUtils.uncapitalize(contextClass.getSimpleName()); } if (contextMapKey.equals(contextName)) { // we have our @ContextParam now let's try to know if there is a "nextContextCaller" if (StringUtils.isEmpty(nextPath)) { // finished to handle the path, there is no other caller nextContextCaller = null; returnType = TemplateUtils.getGenericType(contextParam); } else { nextContextCaller = new ObjectContextCaller(contextClass, nextPath); returnType = nextContextCaller.getReturnType(); } break; } } if (returnType == null) { throw new IllegalArgumentException( "Couln't find the @ContextParam corresponding to " + contextMapKey + " in " + declaringClass); } else { this.nextContextCaller = nextContextCaller; this.returnType = returnType; } }
From source file:com.threewks.thundr.bind.http.request.RequestHeaderBinder.java
String normaliseHeaderName(String header) { String capitalised = WordUtils.capitalizeFully(header, '-'); String withoutDashes = capitalised.replaceAll(StringPool.DASH, StringPool.EMPTY); return StringUtils.uncapitalize(withoutDashes); }
From source file:com.ppcxy.cyfm.showcase.demos.utilities.string.ApacheStringUtilsDemo.java
@Test public void otherUtils() { // ignoreCase:contains/startWith/EndWith/indexOf/lastIndexOf assertThat(StringUtils.containsIgnoreCase("Aaabbb", "aaa")).isTrue(); assertThat(StringUtils.indexOfIgnoreCase("Aaabbb", "aaa")).isEqualTo(0); // 0/* w ww. ja v a 2 s . co m*/ assertThat(StringUtils.leftPad("1", 3, '0')).isEqualTo("001"); assertThat(StringUtils.leftPad("12", 3, '0')).isEqualTo("012"); // ??? assertThat(StringUtils.abbreviate("abcdefg", 7)).isEqualTo("abcdefg"); assertThat(StringUtils.abbreviate("abcdefg", 6)).isEqualTo("abc..."); // ?/? assertThat(StringUtils.capitalize("abc")).isEqualTo("Abc"); assertThat(StringUtils.uncapitalize("Abc")).isEqualTo("abc"); }
From source file:com.google.dart.java2dart.processor.PropertySemanticProcessor.java
@Override public void process(final CompilationUnit unit) { unit.accept(new GeneralizingASTVisitor<Void>() { @Override// w w w . j a va2 s . c o m public Void visitFieldDeclaration(FieldDeclaration node) { if (context.getPrivateClassMembers().contains(node)) { for (VariableDeclaration field : node.getFields().getVariables()) { SimpleIdentifier name = field.getName(); context.renameIdentifier(name, "_" + name.getName()); } } return super.visitFieldDeclaration(node); } @Override public Void visitMethodDeclaration(MethodDeclaration node) { if (node.getName() instanceof SimpleIdentifier && node.getParameters() != null) { SimpleIdentifier nameNode = node.getName(); String name = context.getIdentifierOriginalName(nameNode); List<FormalParameter> parameters = node.getParameters().getParameters(); // getter if (name.startsWith("get") && parameters.isEmpty()) { String propertyName = StringUtils.uncapitalize(name.substring("get".length())); // rename references context.renameIdentifier(nameNode, propertyName); // replace MethodInvocation with PropertyAccess for (SimpleIdentifier reference : context.getReferences(nameNode)) { if (reference.getParent() instanceof MethodInvocation) { MethodInvocation invocation = (MethodInvocation) reference.getParent(); if (invocation.getMethodName() == reference) { Expression invocationTarget = invocation.getTarget(); // prepare replacement Expression replacement; if (invocationTarget != null) { replacement = propertyAccess(invocationTarget, reference); } else { replacement = reference; } // do replace replaceNode(invocation, replacement); } } } // convert method to getter node.setPropertyKeyword(token(Keyword.GET)); node.setParameters(null); } // setter if (name.startsWith("set") && parameters.size() == 1 && isValidSetterType(node.getReturnType())) { String propertyName = StringUtils.uncapitalize(name.substring("set".length())); // rename references context.renameIdentifier(nameNode, propertyName); // replace MethodInvocation with AssignmentExpression for (SimpleIdentifier reference : context.getReferences(nameNode)) { if (reference.getParent() instanceof MethodInvocation) { MethodInvocation invocation = (MethodInvocation) reference.getParent(); if (invocation.getMethodName() == reference) { Expression invocationTarget = invocation.getTarget(); List<Expression> arguments = invocation.getArgumentList().getArguments(); // prepare assignment target Expression assignmentTarget; if (invocationTarget != null) { assignmentTarget = propertyAccess(invocationTarget, reference); } else { assignmentTarget = reference; } // do replace replaceNode(invocation, assignmentExpression(assignmentTarget, TokenType.EQ, arguments.get(0))); } } } // convert method to setter node.setPropertyKeyword(token(Keyword.SET)); } } return super.visitMethodDeclaration(node); } }); }
From source file:net.rptools.layercontrol.LayerStackLayer.java
/** * Add a layer./*from ww w. j av a 2s .c om*/ * @param i index to add at * @param layer layer to add */ @ThreadPolicy(ThreadPolicy.ThreadId.ANY) public synchronized void addLayer(final int i, final Layer layer) { if (!Platform.isFxApplicationThread()) { Platform.runLater(new Runnable() { @Override public void run() { addLayer(i, layer); } }); } // Now on JFX thread Pane pane = new Pane(); final String resource = "layer" + layer.getName() + ".fxml"; try { pane = component.getFramework().getFXMLLoader(layer.getClass().getResource(resource)).load(); } catch (final Exception e) { LOGGER.warn("no layer pane found resource={}", resource); } pane.getStyleClass().add(layer.getName().toLowerCase()); pane.setId(StringUtils.uncapitalize(layer.getName())); pane.minWidthProperty().bind(getDrawable().widthProperty()); pane.minHeightProperty().bind(getDrawable().heightProperty()); final int size = getDrawable().getChildren().size(); getDrawable().getChildren().add(size - i, pane); layer.setDrawable(pane); }
From source file:com.mirth.connect.model.Rule.java
@Override public Map<String, Object> getPurgedProperties() { // The original value for the "Equals" is not to be purged. Map<String, Object> purgedData = (Map<String, Object>) PurgeUtil.getPurgedMap(data); String equals = "Equals"; if (data.containsKey(equals)) { purgedData.put(StringUtils.uncapitalize(equals), data.get(equals)); }// ww w . j a v a 2 s.com Map<String, Object> purgedProperties = new HashMap<String, Object>(); purgedProperties.put("sequenceNumber", sequenceNumber); purgedProperties.put("data", purgedData); purgedProperties.put("type", type); purgedProperties.put("scriptLines", PurgeUtil.countLines(script)); purgedProperties.put("operator", operator); return purgedProperties; }
From source file:com.threewks.thundr.bigmetrics.controller.EventQueueControllerTest.java
@Test public void shouldCorrectlyFormatHeader() { // Check logic, by using Thundr code String originalHeader = "X-AppEngine-TaskName"; String parameterHeader = "xAppengineTaskname"; String capitalised = WordUtils.capitalizeFully(originalHeader, '-'); String withoutDashes = capitalised.replaceAll(StringPool.DASH, StringPool.EMPTY); String formattedHeader = StringUtils.uncapitalize(withoutDashes); assertThat(formattedHeader, is(parameterHeader)); }
From source file:com.wavemaker.tools.apidocs.tools.parser.util.MethodUtils.java
/** * It will removes the getter part, gives the parameter name. * <p/>/*from www . j a v a2 s . c o m*/ * For eg: method name is getUser, it will return 'user'. * * @param getterMethodName method name to scan. * @return parameter name * @throws IllegalArgumentException if given method is not a proper getter method. */ public static String getPropertyName(String getterMethodName) throws IllegalArgumentException { if (isGetterMethod(getterMethodName)) { Matcher matcher = getterPattern.matcher(getterMethodName); String propName = ""; if (matcher.find(0)) { // to fill the groups propName = matcher.group(3); } return StringUtils.isNotBlank(propName) ? StringUtils.uncapitalize(propName) : DEFAULT_PROPERTY_NAME; } else { throw new IllegalArgumentException("Given method is not a valid getter method:" + getterMethodName); } }