/** * 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); }
@Override protected String getFallbackFormat(Argument argument) { return NameUtils.hyphenate(argument.getName()); } }
private String resolveFunctionPath(String methodName, Class<?> declaringType, String functionName) { String functionPath = functionName; if (StringUtils.isEmpty(functionPath)) { String typeName = declaringType.getSimpleName(); if (typeName.contains("$")) { // generated lambda functionPath = contextPath + NameUtils.hyphenate(methodName); } else { functionPath = contextPath + NameUtils.hyphenate(typeName); } } else { functionPath = contextPath + functionPath; } return functionPath; }
/** * <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); }
/** * @param argument The argument * @return The fallback format */ protected String getFallbackFormat(Argument argument) { return NameUtils.hyphenate(argument.getName()); }
@Override protected String getFallbackFormat(Argument argument) { return NameUtils.hyphenate(NameUtils.capitalize(argument.getName()), false); } }
@Override protected String getFallbackFormat(Argument argument) { return NameUtils.hyphenate(NameUtils.capitalize(argument.getName()), false); } }
@Override public void process(BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) { if (method.hasAnnotation(FunctionBean.class)) { String functionId = method.getValue(FunctionBean.class, String.class).orElse(null); Class<?> declaringType = method.getDeclaringType(); if (StringUtils.isEmpty(functionId)) { String typeName = declaringType.getSimpleName(); if (typeName.contains("$")) { // generated lambda functionId = NameUtils.hyphenate(method.getMethodName()); } else { functionId = NameUtils.hyphenate(typeName); } } if (java.util.function.Function.class.isAssignableFrom(declaringType) && method.getMethodName().equals("apply")) { registerFunction(method, functionId); } else if (Consumer.class.isAssignableFrom(declaringType) && method.getMethodName().equals("accept")) { registerConsumer(method, functionId); } else if (BiFunction.class.isAssignableFrom(declaringType) && method.getMethodName().equals("apply")) { registerBiFunction(method, functionId); } else if (Supplier.class.isAssignableFrom(declaringType) && method.getMethodName().equals("get")) { registerSupplier(method, functionId); } } }
@Override public Optional<? extends LoadBalancer> resolve(String... serviceReferences) { if (ArrayUtils.isEmpty(serviceReferences) || StringUtils.isEmpty(serviceReferences[0])) { return Optional.empty(); } String reference = serviceReferences[0]; if (reference.startsWith("/")) { // current server reference if (beanContext.containsBean(EmbeddedServer.class)) { EmbeddedServer embeddedServer = beanContext.getBean(EmbeddedServer.class); URL url = embeddedServer.getURL(); return Optional.of(LoadBalancer.fixed(url)); } else { return Optional.empty(); } } else if (reference.indexOf('/') > -1) { try { URL url = new URL(reference); return Optional.of(LoadBalancer.fixed(url)); } catch (MalformedURLException e) { return Optional.empty(); } } else { reference = NameUtils.hyphenate(reference); return resolveLoadBalancerForServiceID(reference); } }
/** * 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; } } }
@Override public Publisher<List<ServiceInstance>> getInstances(String serviceId) { serviceId = NameUtils.hyphenate(serviceId); if (SERVICE_ID.equals(serviceId)) { return Publishers.just( Collections.singletonList(ServiceInstance.of(SERVICE_ID, consulConfiguration.getHost(), consulConfiguration.getPort())) ); } else { ConsulConfiguration.ConsulDiscoveryConfiguration discovery = consulConfiguration.getDiscovery(); boolean passing = discovery.isPassing(); String datacenter = discovery.getDatacenters().get(serviceId); String tag = discovery.getTags().get(serviceId); Optional<String> scheme = Optional.ofNullable(discovery.getSchemes().get(serviceId)); Publisher<List<HealthEntry>> healthyServicesPublisher = getHealthyServices(serviceId, passing, tag, datacenter); return Publishers.map(healthyServicesPublisher, healthEntries -> { List<ServiceInstance> serviceInstances = new ArrayList<>(); for (HealthEntry healthEntry : healthEntries) { serviceInstances.add(new ConsulServiceInstance(healthEntry, scheme.orElse("http"))); } return serviceInstances; }); } } }
@Override public Publisher<List<ServiceInstance>> getInstances(String serviceId) { serviceId = NameUtils.hyphenate(serviceId); Flowable<List<ServiceInstance>> flowable = Flowable.fromPublisher(getApplicationInfo(serviceId)).map(applicationInfo -> { List<InstanceInfo> instances = applicationInfo.getInstances(); return instances.stream() .map(ii -> { if (!discoveryConfiguration.isUseSecurePort()) { ii.setSecurePort(-1); } return new EurekaServiceInstance(ii); }) .collect(Collectors.toList()); }); return flowable.onErrorReturn(throwable -> { // Translate 404 into empty list if (throwable instanceof HttpClientResponseException) { HttpClientResponseException hcre = (HttpClientResponseException) throwable; if (hcre.getStatus() == HttpStatus.NOT_FOUND) { return Collections.emptyList(); } } if (throwable instanceof Exception) { throw (Exception) throwable; } else { throw new HttpClientException("Internal Client Error: " + throwable.getMessage(), throwable); } }); }
Cookie cookie = cookies.get(name); if (cookie == null) { cookie = cookies.get(NameUtils.hyphenate(name));
String functionName = context.getValue(Named.class, String.class).orElse(NameUtils.hyphenate(context.getMethodName(), true));
private List<String> resolvePropertiesForConvention(String property, PropertySource.PropertyConvention convention) { switch (convention) { case ENVIRONMENT_VARIABLE: // environment variables are converted to lower case and dot separated return Collections.singletonList(property.toLowerCase(Locale.ENGLISH) .replace('_', '.')); default: return Collections.singletonList( NameUtils.hyphenate(property, true) ); } }
@Override protected String getFallbackFormat(Argument argument) { return NameUtils.hyphenate(argument.getName()); } }
@Override public String resolveUri(String property) { if (StringUtils.isEmpty(property)) { return "/"; } if (property.charAt(0) != '/') { return '/' + NameUtils.hyphenate(property, true); } return property; } }
@Override public String resolveUri(String property) { if (StringUtils.isEmpty(property)) { return "/"; } if (property.charAt(0) != '/') { return '/' + NameUtils.hyphenate(property, true); } return property; } };
@Override protected String getFallbackFormat(Argument argument) { return NameUtils.hyphenate(NameUtils.capitalize(argument.getName()), false); } }