/** * Converts camel case to hyphenated, lowercase form. * * @param name The name * @return The hyphenated string */ public static String hyphenate(String name) { return hyphenate(name, true); }
/** * Constructor to create an object. * * @param name Parameter name to bind in the multipart request * @param filename Name of the file * @param contentType The type of the content, example - "application/json", "text/plain" etc */ AbstractFilePart(String name, String filename, @Nullable MediaType contentType) { super(name); if (filename == null) { throw new IllegalArgumentException("Adding file parts with a null filename is not allowed"); } this.filename = filename; if (contentType == null) { this.contentType = MediaType.forExtension(NameUtils.extension(filename)).orElse(MediaType.APPLICATION_OCTET_STREAM_TYPE); } else { this.contentType = contentType; } }
/** * . * The camel case version of the string with the first letter in lower case * * @param str The string * @param lowerCaseFirstLetter Whether the first letter is in upper case or lower case * @return The new string in camel case */ public static String camelCase(String str, boolean lowerCaseFirstLetter) { String result = Arrays.stream(str.split("[\\s_-]")).map(NameUtils::capitalize).collect(Collectors.joining("")); if (lowerCaseFirstLetter) { return decapitalize(result); } return result; }
/** * Converts class name to property name using JavaBean decapitalization. * * @param name The class name * @param suffixes The suffix to remove * @return The decapitalized name */ public static String decapitalizeWithoutSuffix(String name, String... suffixes) { String decapitalized = decapitalize(name); return trimSuffix(decapitalized, suffixes); }
/** * <p>Returns the hyphenated equivalent for this convention for the given class. Eg. BookShopController -> book-shop</p> * * @param type The type * @return The property name equivalent */ public String asHyphenatedName(Class type) { String shortName = NameUtils.trimSuffix(type.getSimpleName(), suffix); return NameUtils.hyphenate(shortName); }
/** * Get the equivalent property name for the given setter. * * @param setterName The setter * @return The property name */ public static String getPropertyNameForSetter(String setterName) { if (isSetterName(setterName)) { return decapitalize(setterName.substring(PREFIX_LENTGH)); } return setterName; }
@Override protected String getFallbackFormat(Argument argument) { return NameUtils.hyphenate(NameUtils.capitalize(argument.getName()), false); } }
GeneratorAdapter injectMethodVisitor = this.injectMethodVisitor; String propertyName = NameUtils.hyphenate(NameUtils.decapitalize(methodName.substring(prefix.length())), true);
/** * Format a string according to a convention. * * @param convention The string convention to use * @param str The string to format * @return The formatted string based on the convention */ public static String format(StringConvention convention, String str) { switch (convention) { case CAMEL_CASE: return NameUtils.camelCase(str); case HYPHENATED: return NameUtils.hyphenate(str); case UNDER_SCORE_SEPARATED_LOWER_CASE: return NameUtils.underscoreSeparate(str.toLowerCase(Locale.ENGLISH)); case UNDER_SCORE_SEPARATED: return NameUtils.environmentName(str); case CAMEL_CASE_CAPITALIZED: return NameUtils.camelCase(str, false); case RAW: default: return str; } } }
this.interfaceTypes = interfaceTypes != null ? new HashSet<>(Arrays.asList(interfaceTypes)) : Collections.emptySet(); this.classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); String proxyShortName = NameUtils.getSimpleName(proxyFullName); this.proxyBeanDefinitionWriter = new BeanDefinitionWriter( NameUtils.getPackageName(proxyFullName), proxyShortName, isInterface,
list.forEach(filePath -> { if (!propertySourceLoaders.isEmpty()) { String extension = NameUtils.extension(filePath); String fileName = NameUtils.filename(filePath); Optional<PropertySourceLoader> propertySourceLoader = Optional.ofNullable(loaderByFormatMap.get(extension)); if (propertySourceLoader.isPresent()) {
@Override public boolean isWithin(String className) { String pkgName = NameUtils.getPackageName(className); return pkgName.equals(this.packageName) || pkgName.startsWith(this.packageName + '.'); } }
/** * Get the equivalent property name for the given getter. * * @param getterName The getter * @return The property name */ public static String getPropertyNameForGetter(String getterName) { if (isGetterName(getterName)) { int prefixLength = 0; if (getterName.startsWith("get")) { prefixLength = PREFIX_LENTGH; } if (getterName.startsWith("is")) { prefixLength = IS_LENTGH; } return decapitalize(getterName.substring(prefixLength)); } return getterName; }
/** * The simple name without the package name. * * @return The simple name */ @Override default String getSimpleName() { return NameUtils.getSimpleName(getName()); }
@Override public Optional<Object> convert(Map map, Class<Object> targetType, ConversionContext context) { return InstantiationUtils .tryInstantiate(targetType) .map(object -> { Map<?, ?> theMap = map; Map bindMap = new LinkedHashMap(map.size()); for (Map.Entry<?, ?> entry : theMap.entrySet()) { Object key = entry.getKey(); bindMap.put(NameUtils.decapitalize(NameUtils.dehyphenate(key.toString())), entry.getValue()); } return beanPropertyBinder.bind(object, bindMap); } ); } }
/** * Default constructor. */ TypeConvention() { this.suffix = NameUtils.capitalize(name().toLowerCase(Locale.ENGLISH)); }
@Override protected String getFallbackFormat(Argument argument) { return NameUtils.hyphenate(NameUtils.capitalize(argument.getName()), false); } }
GeneratorAdapter injectMethodVisitor = this.injectMethodVisitor; String propertyName = NameUtils.hyphenate(NameUtils.decapitalize(methodName.substring(prefix.length())), true);
String proxyShortName = NameUtils.getSimpleName(proxyFullName); this.proxyInternalName = getInternalName(this.proxyFullName); this.proxyType = getTypeReference(proxyFullName); this.interfaceTypes = Collections.emptySet(); this.proxyBeanDefinitionWriter = new BeanDefinitionWriter( NameUtils.getPackageName(proxyFullName), proxyShortName, isInterface,
/** * Register a route to handle the error. * * @param error The error * @param type The type * @return The route */ default ErrorRoute error(Class<? extends Throwable> error, Class type) { return error(error, type, NameUtils.decapitalize(NameUtils.trimSuffix(type.getSimpleName(), "Exception", "Error")), ReflectionUtils.EMPTY_CLASS_ARRAY); }