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

The following are Jave code examples for showing how to use capitalize() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: atlas   File: AtlasProxy.java   Source Code and License Vote up 9 votes
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", "service", "provider");

        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 2
Project: ProjectAres   File: MonumentWoolFactory.java   Source Code and License Vote up 5 votes
static String makeColorName(DyeColor color) {
    String[] name = StringUtils.split(color.toString(), '_');
    for (int i = 0; i < name.length; i++) {
        name[i] = (i > 0 ? " " : "") + StringUtils.capitalize(name[i].toLowerCase());
    }
    return StringUtils.join(name);
}
 
Example 3
Project: logistimo-web-service   File: ReportServiceUtil.java   Source Code and License Vote up 5 votes
protected String getTableKeyByViewType(ReportViewType viewType, String id) throws Exception {
  String key;
  switch (viewType) {
    case BY_MATERIAL:
      key = getTableByMaterialKey(id);
      break;
    case BY_ENTITY:
      key = getTableByEntityKey(id);
      break;
    case BY_ENTITY_TAGS:
      key = TagUtil.getTagById(Long.valueOf(id), ITag.KIOSK_TAG);
      break;
    case BY_USER:
      key = getUserDetailsById(id);
      break;
    case BY_MANUFACTURER:
      key = StringUtils.capitalize(id);
      break;
    case BY_ASSET_TYPE:
      AssetSystemConfig assets = AssetSystemConfig.getInstance();
      key = assets.getAssetsNameByType(2).get(Integer.parseInt(id));
      break;
    default:
      key = id;
  }
  return key;
}
 
Example 4
Project: pds   File: Reflections.java   Source Code and License Vote up 5 votes
/**
 * 调用Setter方法, 仅匹配方法名。
 * 支持多级,如:对象名.对象名.方法
 */
public static void invokeSetter(Object obj, String propertyName, Object value) {
    Object object = obj;
    String[] names = StringUtils.split(propertyName, ".");
    for (int i = 0; i < names.length; i++) {
        if (i < names.length - 1) {
            String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(names[i]);
            object = invokeMethod(object, getterMethodName, new Class[]{}, new Object[]{});
        } else {
            String setterMethodName = SETTER_PREFIX + StringUtils.capitalize(names[i]);
            invokeMethodByName(object, setterMethodName, new Object[]{value});
        }
    }
}
 
Example 5
Project: Hydrograph   File: OutputUiConverter.java   Source Code and License Vote up 5 votes
/**
 * Returns parameter value or TypeTrueFalse as read from engine xml 
 * @param value
 * @param propertyName
 * @return
 */
public Object convertToTrueFalseValue(TypeTrueFalse value, String propertyName) {
	LOGGER.debug("Converting Boolean to String - {}", propertyName);
	Object parsedValue = getValue(PropertyNameConstants.OVER_WRITE.value());
	if (parsedValue != null) {
		return parsedValue;
	} else {
		if(value != null && TrueFalse.FALSE.equals(value.getValue()))
			return StringUtils.capitalize(TrueFalse.FALSE.value());
		else{
			return StringUtils.capitalize(TrueFalse.TRUE.value());
		}
	}
}
 
Example 6
Project: Reer   File: FieldOptionElement.java   Source Code and License Vote up 5 votes
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 7
Project: Reer   File: NameMatcher.java   Source Code and License Vote up 5 votes
public String formatErrorMessage(String singularItemDescription, Object container) {
    String capItem = StringUtils.capitalize(singularItemDescription);
    if (!matches.isEmpty()) {
        return String.format("%s '%s' is ambiguous in %s. Candidates are: %s.", capItem, pattern, container, GUtil.toString(matches));
    }
    if (!candidates.isEmpty()) {
        return String.format("%s '%s' not found in %s. Some candidates are: %s.", capItem, pattern, container, GUtil.toString(candidates));
    }
    return String.format("%s '%s' not found in %s.", capItem, pattern, container);
}
 
Example 8
Project: ditb   File: MetricMutableQuantiles.java   Source Code and License Vote up 5 votes
/**
 * Instantiates a new {@link MetricMutableQuantiles} 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 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);
}
 
Example 9
Project: hadoop-oss   File: MutableMetricsFactory.java   Source Code and License Vote up 5 votes
/**
 * Remove the prefix "get", if any, from the method name. Return the
 * capacitalized method name."
 */
protected String getName(Method method) {
  String methodName = method.getName();
  if (methodName.startsWith("get")) {
    return StringUtils.capitalize(methodName.substring(3));
  }
  return StringUtils.capitalize(methodName);
}
 
Example 10
Project: pds   File: Reflections.java   Source Code and License Vote up 5 votes
/**
 * 调用Getter方法.
 * 支持多级,如:对象名.对象名.方法
 */
public static Object invokeGetter(Object obj, String propertyName) {
    Object object = obj;
    for (String name : StringUtils.split(propertyName, ".")) {
        String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name);
        object = invokeMethod(object, getterMethodName, new Class[]{}, new Object[]{});
    }
    return object;
}
 
Example 11
Project: sql-first-mapper   File: DaoWriter.java   Source Code and License Vote up 5 votes
/**
 * Write Dto class to disk
 *
 * @param queryDesc description of query
 * @param isReq write request (true) or response (false)
 * @param baseDtoClassName name of parent dto class
 */
private void writeDtoClass(
        QueryDesc queryDesc,
        boolean isReq,
        String baseDtoClassName
) {
    if (isReq && CollectionUtils.isEmpty(queryDesc.getRequestParamList())
            || !isReq && CollectionUtils.isEmpty(queryDesc.getResponseParamList())) {
        return;
    }
    try {
        VelocityContext context = new VelocityContext();

        context.put("fields", isReq ? queryDesc.getRequestParamList() : queryDesc.getResponseParamList());

        String methodNameUpper = StringUtils.capitalize(queryDesc.getMethodName());
        String dtoClassName = methodNameUpper + (isReq ? "Req" : "Res");
        String packageName = queryDesc.getPackageName() + ".dto";

        List<String> implementsList = isReq ? queryDesc.getReqImplementsList() : queryDesc.getResImplementsList();
        processImplementsList(context, new HashSet<>(implementsList));

        context.put("dtoClassName", dtoClassName);
        context.put("classPackage", packageName);
        context.put("classJavadoc", queryDesc.getClassJavadoc());
        context.put("baseDtoClass", baseDtoClassName);

        JavaFileObject builderFile = processingEnv.getFiler().createSourceFile(packageName + "." + dtoClassName);

        try (PrintWriter writer = new PrintWriter(builderFile.openWriter())) {
            Template template = Velocity.getTemplate("dto-class-template.vm", MiscUtils.UTF_8);
            template.merge(context, writer);
        }

    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 12
Project: Reer   File: DefaultBinaryTasksCollection.java   Source Code and License Vote up 4 votes
@Override
public String taskName(String verb) {
    return verb + StringUtils.capitalize(binary.getProjectScopedName());
}
 
Example 13
Project: Ins_fb_pictureSpider_WEB   File: ReflectionUtils.java   Source Code and License Vote up 4 votes
/**
 * 调用Setter方法.
 *
 * @param propertyType 用于查找Setter方法,为空时使用value的Class替代.
 */
public static void invokeSetterMethod(Object obj, String propertyName, Object value, Class<?> propertyType) {
    Class<?> type = propertyType != null ? propertyType : value.getClass();
    String setterMethodName = "set" + StringUtils.capitalize(propertyName);
    invokeMethod(obj, setterMethodName, new Class[] { type }, new Object[] { value });
}
 
Example 14
Project: Reer   File: ResourceOperation.java   Source Code and License Vote up 4 votes
public String getCapitalized() {
    return StringUtils.capitalize(toString());
}
 
Example 15
Project: Reer   File: NativeComponents.java   Source Code and License Vote up 4 votes
private static String getBuildDependentComponentsTaskName(ComponentSpec component) {
    return BUILD_DEPENDENTS_TASK_NAME + StringUtils.capitalize(component.getName());
}
 
Example 16
Project: Reer   File: AbstractBinaryRenderer.java   Source Code and License Vote up 4 votes
@Override
public void render(BinarySpec binary, TextReportBuilder builder) {
    String heading = StringUtils.capitalize(binary.getDisplayName());
    if (!binary.isBuildable()) {
        heading += " (not buildable)";
    }
    builder.heading(heading);

    builder.item("build using task", binary.getBuildTask().getPath());

    T specialized = getTargetType().cast(binary);

    renderTasks(specialized, builder);

    renderVariants(specialized, builder);

    renderDetails(specialized, builder);

    renderOutputs(specialized, builder);

    renderBuildAbility(specialized, builder);

    renderOwnedSourceSets(specialized, builder);
}
 
Example 17
Project: hadoop   File: MutableMetricsFactory.java   Source Code and License Vote up 4 votes
protected String getName(Field field) {
  return StringUtils.capitalize(field.getName());
}
 
Example 18
Project: sql-first-mapper   File: ParamDesc.java   Source Code and License Vote up 4 votes
public String getNameFirstUpper() {
    return StringUtils.capitalize(this.name);
}
 
Example 19
Project: idea-php-typo3-plugin   File: CreateInjectorQuickFix.java   Source Code and License Vote up 4 votes
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
    PhpDocComment docCommentElement = (PhpDocComment) element.getElement().getParent();
    PsiElement owner = docCommentElement.getOwner();
    if (!(owner instanceof Field)) {
        return;
    }
    Field field = (Field) owner;

    final String fieldName = field.getName();
    final PhpClass containingClass = PsiTreeUtil.getParentOfType(element.getElement(), PhpClass.class);
    if (containingClass == null) {
        return;
    }

    PhpType type = field.getType();
    if (type == PhpType.SCALAR) {
        // Scalar type - can't inject those, heh.
        return;
    }

    final String methodName = "inject" + StringUtils.capitalize(fieldName);
    Method injectorFunction = PhpPsiElementFactory.createMethod(
            project,
            "public function " + methodName + " (" + type + " $" + fieldName + ") {" +
                    "  $this->" + fieldName + " = $" + fieldName + ";" +
                    "}"

    );

    final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, element.getContainingFile().getVirtualFile()), true);
    if (editor == null) {
        return;
    }

    PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
    PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());

    final int insertPos = CodeUtil.getMethodInsertPosition(containingClass, methodName);
    if (insertPos == -1) {
        return;
    }

    new WriteCommandAction(project) {
        @Override
        protected void run(@NotNull Result result) throws Throwable {
            StringBuffer textBuf = new StringBuffer();
            textBuf.append("\n");
            textBuf.append(injectorFunction.getText());

            editor.getDocument().insertString(insertPos, textBuf);
            final int endPos = insertPos + textBuf.length();

            CodeStyleManager.getInstance(project).reformatText(containingClass.getContainingFile(), insertPos, endPos);
            PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());

            Method insertedMethod = containingClass.findMethodByName(methodName);
            if (insertedMethod != null) {
                editor.getCaretModel().moveToOffset(insertedMethod.getTextRange().getStartOffset());
                editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);

                element.getElement().delete();
            }
        }

        @Override
        public String getGroupID() {
            return "Create Injection Method";
        }
    }.execute();
}
 
Example 20
Project: Arcadia-Spigot   File: ColorShuffleGame.java   Source Code and License Vote up 4 votes
public void nextEvent() {
    if(getAPI().getGameManager().getGameState() != GameState.INGAME) return;
    this.currentLevel++;
    this.shuffleColors();
    final int totalTicks = 100-(5*currentLevel);
    final MaterialData nextColor = fetchRandomColor();
    ItemStack itemStack = new ItemStack(nextColor.getItemType(), 1, nextColor.getData());
    ItemMeta itemMeta = itemStack.getItemMeta();
    if(itemStack.getType() == Material.WOOL) {
        DyeColor dye = DyeColor.getByWoolData(itemStack.getData().getData());
        String name = dye.toString().toLowerCase().replace("_", " ");
        name = StringUtils.capitalize(name);
        itemMeta.setDisplayName(Utils.convertDyeColor(dye) + "" + ChatColor.BOLD + name);
    } else {
        if(itemMeta.getLocalizedName() != null) {
            itemMeta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + itemMeta.getLocalizedName());
        }
    }
    itemStack.setItemMeta(itemMeta);
    Bukkit.getOnlinePlayers().forEach(player -> {
        if(getAPI().getGameManager().isAlive(player)) {
            player.setExp(1f);
            player.setLevel(currentLevel);
            for(int i=0; i<9; i++) {
                player.getInventory().setItem(i, itemStack);
            }
        }
    });
    new BukkitRunnable() {
        int ticks = 0;
        public void run() {
            if(getAPI().getGameManager().getGameState() != GameState.INGAME) {
                this.cancel();
                return;
            }
            if(ticks >= totalTicks) {
                this.cancel();
                removeColors(nextColor);
                Bukkit.getOnlinePlayers().forEach(player -> {
                    if(getAPI().getGameManager().isAlive(player)) {
                        player.setExp(0F);
                        for(int i=0; i<9; i++) {
                            player.getInventory().setItem(i, new ItemStack(Material.AIR, 1));
                        }
                    }
                });
                new BukkitRunnable() {
                    public void run() {
                        nextEvent();
                    }
                }.runTaskLater(Arcadia.getPlugin(Arcadia.class), 40L);
            } else {
                double percent = (100D-(((double) ticks/(double) totalTicks)*100D));
                float xp = ((Double.valueOf(percent).floatValue() % 100) / 100);
                Bukkit.getOnlinePlayers().forEach(player -> {
                    if(getAPI().getGameManager().isAlive(player)) {
                        player.setExp(xp);
                    }
                });
            }
            ticks++;
        }
    }.runTaskTimer(this.getAPI().getPlugin(), 0, 1L);
}