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

The following are Jave code examples for showing how to use capitalize() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: InComb   File: QueryUtil.java   View Source Code Vote up 6 votes
/**
 * Returns a {@link BooleanQuery} for the given search text.
 *
 * @param indexType the type in which should be searched.
 * @param search the search text.
 * @param baseBoost highest possible boost of the query. The more the match is exact
 * 			than a bigger boost will be used.
 */
private static BooleanQuery buildSearchTermQuery(final IIndexTypeConf indexType, final String search,
		final float baseBoost) {
	final BooleanQuery subQuery = new BooleanQuery();

	final String lowerCase = StringUtils.lowerCase(search);
	final String capitalized = StringUtils.capitalize(search);

	addSearchTermQueries(indexType, search, subQuery, baseBoost);

	if(!lowerCase.equals(search)) {
		addSearchTermQueries(indexType, lowerCase, subQuery, 0.8f*baseBoost);
	}

	if(!capitalized.equals(search)) {
		addSearchTermQueries(indexType, capitalized, subQuery, 0.8f*baseBoost);
	}

	return subQuery;
}
 
Example 2
Project: AEM   File: AddTransformedImagePathFromGlobalContextProcessor.java   View Source Code Vote up 6 votes
@Override
public void process(final ExecutionContext executionContext, TemplateContentModel contentModel)
        throws ProcessException {
    try {
        SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);

        if (contentModel.has(CONFIG_GLOBAL_IMAGE_KEY)) {
            String globalImageName = contentModel.getAsString(CONFIG_GLOBAL_IMAGE_KEY);

            if (contentModel.has(COMPONENT_GLOBAL_DIALOG_PATH) && StringUtils.isNotEmpty(globalImageName)) {
                String imageResourcePath = contentModel.getAsString(COMPONENT_GLOBAL_DIALOG_PATH) + SLASH + globalImageName;
                Resource imageResource = request.getResourceResolver().getResource(request.getResource(),
                        imageResourcePath);

                if (null != imageResource) {
                    String imagePath = assetPathService.getComponentImagePath(imageResource);
                    String globalImagePathPropertyName = globalImageName + StringUtils.capitalize(IMAGE_PATH);
                    contentModel.set(GLOBAL_PROPERTIES_KEY + DOT + globalImagePathPropertyName, imagePath);
                }
            }
        }
    } catch (Exception e) {
        throw new ProcessException(e);
    }
}
 
Example 3
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: BeanUtils.java   View Source Code Vote up 6 votes
public static <T> T populate(final Properties properties, final T obj) {
    Class<?> clazz = obj.getClass();
    try {

        Set<Map.Entry<Object, Object>> entries = properties.entrySet();
        for (Map.Entry<Object, Object> entry : entries) {
            String entryKey = entry.getKey().toString();
            String[] keyGroup = entryKey.split("\\.");
            for (int i = 0; i < keyGroup.length; i++) {
                keyGroup[i] = keyGroup[i].toLowerCase();
                keyGroup[i] = StringUtils.capitalize(keyGroup[i]);
            }
            String beanFieldNameWithCapitalization = StringUtils.join(keyGroup);
            try {
                setProperties(clazz, obj, "set" + beanFieldNameWithCapitalization, entry.getValue());
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
                //ignored...
            }
        }
    } catch (RuntimeException e) {
        log.warn("Error occurs !", e);
    }
    return obj;
}
 
Example 4
Project: cyberduck   File: Preferences.java   View Source Code Vote up 6 votes
/**
 * @param locale ISO Language identifier
 * @return Human readable language name in the target language
 */
public String getDisplayName(final String locale) {
    java.util.Locale l;
    if(StringUtils.contains(locale, "_")) {
        l = new java.util.Locale(locale.split("_")[0], locale.split("_")[1]);
    }
    else {
        l = new java.util.Locale(locale);
    }
    return StringUtils.capitalize(l.getDisplayName(l));
}
 
Example 5
Project: sentry   File: CronExpressionDescriptor.java   View Source Code Vote up 6 votes
/**
 * @param description
 * @return
 */
private static String transformCase(String description, Options options) {
    String descTemp = description;
    switch (options.getCasingType()) {
        case Sentence:
            descTemp = StringUtils.upperCase("" + descTemp.charAt(0)) + descTemp.substring(1);
            break;
        case Title:
            descTemp = StringUtils.capitalize(descTemp);
            break;
        default:
            descTemp = descTemp.toLowerCase();
            break;
    }
    return descTemp;
}
 
Example 6
Project: nixmash-blog   File: AdminPostsController.java   View Source Code Vote up 6 votes
@RequestMapping(value = "/update/{postId}", method = GET)
public String updatePost(@PathVariable("postId") Long postId,
                         Model model, HttpServletRequest request) throws PostNotFoundException {
    Post post = postService.getPostById(postId);
    String postType = StringUtils.capitalize(post.getPostType().name().toLowerCase());
    String pageTitle = webUI.getMessage(MESSAGE_ADMIN_UPDATE_POSTLINK_TITLE, postType);
    String pageHeading = webUI.getMessage(MESSAGE_ADMIN_UPDATE_POSTLINK_HEADING, postType);

    PostDTO postDTO = getUpdatedPostDTO(post);
    if (post.getPostType() == PostType.LINK) {
        postDTO.setHasImages(post.getPostImage() != null);
        postDTO.setPostImage(post.getPostImage());
        if (postDTO.getHasImages()) {
            model.addAttribute("hasLinkImage", true);
        }
    }
    model.addAttribute("postName", post.getPostName());
    model.addAttribute("postDTO", postDTO);
    model.addAttribute("pageTitle", pageTitle);
    model.addAttribute("pageHeading", pageHeading);
    model.addAttribute("categories", postService.getAdminSelectionCategories());

    model.addAllAttributes(getPostLinkAttributes(request, post.getPostType()));

    return ADMIN_POSTLINK_UPDATE_VIEW;
}
 
Example 7
Project: ace-cache   File: ReflectionUtils.java   View Source Code 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 8
Project: angit   File: Reflections.java   View Source Code Vote up 5 votes
/**
 * 调用Setter方法, 仅匹配方法名。
 * 支持多级,如:对象名.对象名.方法
 *
 * @param obj          the obj
 * @param propertyName the property name
 * @param value        the value
 */
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 9
Project: athena   File: SystemMetricsCollectorWebResource.java   View Source Code Vote up 5 votes
private static String toCamelCase(String value, boolean startWithLowerCase) {
    String[] strings = StringUtils.split(value.toLowerCase(), "_");
    for (int i = startWithLowerCase ? 1 : 0; i < strings.length; i++) {
        strings[i] = StringUtils.capitalize(strings[i]);
    }
    return StringUtils.join(strings);
}
 
Example 10
Project: liteBatch   File: Reflections.java   View Source Code 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: ExcelHandle   File: Reflections.java   View Source Code 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 12
Project: Got-Wood   File: WoodMaterial.java   View Source Code Vote up 5 votes
public WoodMaterial(String name, float hardness, float strength, int meta) {
	this.hardness = hardness;
	this.strength = strength;
	this.identifier = name;
	this.titleName = StringUtils.capitalize(name);
	this.enumName = (GotWood.ID + "_" + name).toUpperCase(Locale.ENGLISH);
	this.blastResistance = 2.5f * this.strength;
	this.meta = meta;
}
 
Example 13
Project: gen_code   File: AnalysisObject.java   View Source Code Vote up 5 votes
/**
 * 调用Setter方法, 仅匹配方法名。
 * 支持多级,如:对象名.对象名.方法
 * @param obj 执行对象
 * @param propertyName 属性名称
 * @param value 属性值
 */
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 14
Project: util   File: ClassUtil.java   View Source Code Vote up 5 votes
/**
 * 循环遍历,按属性名获取前缀为set的函数,并设为可访问
 */
public static Method getGetterMethod(Class<?> clazz, String propertyName) {
	String getterMethodName = ClassUtil.GETTER_PREFIX + StringUtils.capitalize(propertyName);

	Method method = ClassUtil.getAccessibleMethod(clazz, getterMethodName);

	// retry on another name
	if (method == null) {
		getterMethodName = ClassUtil.IS_PREFIX + StringUtils.capitalize(propertyName);
		method = ClassUtil.getAccessibleMethod(clazz, getterMethodName);
	}
	return method;
}
 
Example 15
Project: ace-cache   File: ReflectionUtils.java   View Source Code 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 16
Project: hibernate-ogm-ignite   File: IgniteDatastoreProvider.java   View Source Code Vote up 5 votes
/**
 * Finds key type name for cache for entities with composite id
 * @param keyMetadata
 * @return
 */
private String findKeyType(EntityKeyMetadata keyMetadata) {
	String result = compositeIdTypes.get( keyMetadata.getTable() );
	if ( result == null ) {
		String cacheType = getEntityTypeName( keyMetadata.getTable() );
		IgniteCache<Object, BinaryObject> cache = getEntityCache( keyMetadata );
		CacheConfiguration cacheConfig = cache.getConfiguration( CacheConfiguration.class );
		if ( cacheConfig.getQueryEntities() != null ) {
			for ( QueryEntity qe : (Collection<QueryEntity>) cacheConfig.getQueryEntities() ) {
				if ( qe.getValueType() != null && cacheType.equalsIgnoreCase( qe.getValueType() ) ) {
					result = qe.getKeyType();
					break;
				}
			}
		}
		if ( result == null ) {
			if ( cacheConfig.getKeyType() != null ) {
				result = cacheConfig.getKeyType().getSimpleName();
			}
			if ( result == null ) {
				// if nothing found we use id field name
				result = StringHelper.stringBeforePoint( keyMetadata.getColumnNames()[0] );
				result = StringUtils.capitalize( result );
			}
		}
		compositeIdTypes.put( keyMetadata.getTable(), result );
	}
	return result;
}
 
Example 17
Project: momo-2   File: FFXIVCharacter.java   View Source Code Vote up 4 votes
public FFXIVCharacter(String server, String firstName, String lastName) throws IOException, BadCharacterException {
	this.server = StringUtils.capitalize(server.toLowerCase());
	this.firstName = StringUtils.capitalize(firstName.toLowerCase());
	this.lastName = StringUtils.capitalize(lastName.toLowerCase());

	try {
		lodestoneLink = getCharacterUrl(firstName, lastName, server);
		if(lodestoneLink == null) {
			throw new BadCharacterException();
		}
		Document doc = Jsoup.parse(new URL(lodestoneLink), 10000);
		this.imageLink = doc.select("div.character__detail__image").select("img").first().attr("src");
		String raceGender = doc.select("div.character-block__box").first()
				.select("p.character-block__name").first()
				.html();
		this.race = raceGender.substring(0, raceGender.indexOf('<'));
		this.faction = raceGender.substring(raceGender.indexOf('>') + 1, raceGender.indexOf('/') - 1);
		this.gender = raceGender.contains("♀") ? "Female" : "Male";
		
		Element charProfile = doc.select("div.character-block__box").get(1);
		this.nameday = charProfile.select("p.character-block__birth").first().text();
		this.guardian = charProfile.select("p.character-block__name").first().text();
		
		Element cityStateEle = doc.select("div.character-block__box").get(2);
		this.cityState = cityStateEle.select("p.character-block__name").first().text();
		
		int profileElements = doc.select("div.character__profile__data__detail").first()
				.select("div.character-block").size();
		if(profileElements == 5) { // Has both grand & free
			this.grandCompany = doc.select("div.character-block__box").get(3)
					.select("p.character-block__name").first().text();
			this.freeCompany = doc.select("div.character-block__box").get(4)
					.select("div.character__freecompany__name").first()
					.select("a").first().text();
		} else if(profileElements == 4) { // Has only grand OR free
			if (doc.select("div.character__freecompany__crest").isEmpty()) {
				this.grandCompany = doc.select("div.character-block__box").get(3)
						.select("p.character-block__name").first().text();
				this.freeCompany = "none";
			} else {
				this.freeCompany = doc.select("div.character-block__box").get(4)
						.select("div.character__freecompany__name").first()
						.select("a").first().text();
				this.grandCompany = "none";
			}
		} else {
			this.freeCompany = "none";
			this.grandCompany = "none";
		}

		this.jobImageLink = doc.select("div.character__class_icon").first().select("img").first().attr("src");
	} catch (IOException e) {
		throw new IOException();
	}
}
 
Example 18
Project: rest-modeling-framework   File: GeneratorHelper.java   View Source Code Vote up 4 votes
static String toRequestName(UriTemplate uri, Method method) {
    return toParamName(uri, "By") + StringUtils.capitalize(method.getMethod().toString());
}
 
Example 19
Project: Arc-v2   File: CommandSummary.java   View Source Code Vote up 4 votes
@Override
public void execute(Player player, String[] args) {

    if (args.length == 0) {
        player.sendMessage(usage());
        return;
    }

    Player user = Bukkit.getPlayer(args[1]);
    if (user == null) {
        player.sendMessage(ChatColor.RED + "Player not found.");
        return;
    }


    player.sendMessage(ChatColor.GOLD + "" + ChatColor.STRIKETHROUGH + "----------------------------------------------------");
    player.sendMessage(ChatColor.RED + ChatUtility.getCenteredMessage("Viewing report for " + ChatColor.GREEN + user.getName()));
    player.sendMessage(ChatColor.GOLD + "" + ChatColor.STRIKETHROUGH + "----------------------------------------------------");

    // get basic info about the player.
    String OP = user.isOp() ? ChatColor.RED + "true" : ChatColor.GREEN + "false";
    String gamemode = ChatColor.GOLD + "GameMode: " + ChatColor.BLUE + StringUtils.capitalize(user.getGameMode().toString()
            .toLowerCase());
    String world = ChatColor.GOLD + "World: " + ChatColor.BLUE + user.getWorld().getName();

    // send them their total violation level
    int totalLevel = Arc.getViolationHandler().getViolationData(user).getTotalLevel();
    player.sendMessage(ChatUtility.getCenteredMessage(ChatColor.GREEN + "" + user.getName() + "'s total violation level: " + ChatColor.RED + totalLevel));

    // append the cheatprobability.
    CheatProbability probability = totalLevel <= 30 ? CheatProbability.NOT_LIKELY : totalLevel <= 60 ? CheatProbability.LIKELY :
            CheatProbability.DEFINITELY;
    player.sendMessage(ChatUtility.getCenteredMessage(ChatColor.GREEN + "Probability this player is cheating: " + ChatColor.RED +
            probability.getName()));

    // Send some basic stats.
    player.sendMessage(ChatUtility.getCenteredMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GOLD
            + "Operator: " + OP + ChatColor.DARK_GRAY + "] [" + gamemode + ChatColor.DARK_GRAY + "] [" + world + ChatColor.DARK_GRAY +
            "]"));

    // start displaying check info.
    player.sendMessage(ChatColor.GOLD + "" + ChatColor.STRIKETHROUGH + "----------------------------------------------------");

    Map<CheckType, Integer> checks = Arc.getViolationHandler().getViolationData(user).getViolatedChecks();
    List<String> sorted = new ArrayList<>();

    // get all checks we have failed and put them in a list to be sorted.
    for (CheckType check : checks.keySet()) {
        int violationLevel = checks.get(check);
        String centered = ChatUtility.getCenteredMessage(ChatColor.RED + check.getCheckName() + ChatColor.GOLD + " violations: " +
                ChatColor.RED + violationLevel + ChatColor.GOLD + ".");
        sorted.add(centered);
    }

    // sort and send.
    sorted.sort(Comparator.comparingInt(String::length));
    sorted.forEach(player::sendMessage);

}
 
Example 20
Project: uroborosql   File: StringFunction.java   View Source Code Vote up 2 votes
/**
 * 文字列の先頭文字を大文字にする
 *
 * <pre>
 * StringUtils.capitalize(null)  = null
 * StringUtils.capitalize("")    = ""
 * StringUtils.capitalize("cat") = "Cat"
 * StringUtils.capitalize("cAt") = "CAt"
 * </pre>
 *
 * @param str 文字列
 * @return 先頭を大文字にした文字列
 * @see StringUtils#capitalize(String)
 * @see #uncapitalize(String)
 */
public String capitalize(final String str) {
	return StringUtils.capitalize(str);
}