/** * Whether the given array is not empty. * * @param array The array * @return True if it is */ public static boolean isNotEmpty(Object[] array) { return !isEmpty(array); }
/** * Produce a string representation of the given array. * * @param delimiter The delimiter * @param array The array * @return The string representation */ public static String toString(String delimiter, @Nullable Object[] array) { if (isEmpty(array)) { return ""; } List<Object> list = Arrays.asList(array); return CollectionUtils.toString(delimiter, list); } }
/** * Check whether any of the given stereotypes is present. * * @param annotations The annotations * @return True if any of the given stereotypes are present */ default boolean hasStereotype(@Nullable String[] annotations) { if (ArrayUtils.isEmpty(annotations)) { return false; } for (String annotation : annotations) { if (hasStereotype(annotation)) { return true; } } return false; }
/** * Convert an argument array to a class array. * * @param arguments The arguments * @return The class array */ static Class[] toClassArray(Argument... arguments) { if (ArrayUtils.isEmpty(arguments)) { return ReflectionUtils.EMPTY_CLASS_ARRAY; } Class[] types = new Class[arguments.length]; for (int i = 0; i < arguments.length; i++) { Argument argument = arguments[i]; types[i] = argument.getType(); } return types; }
/** * Checks whether this object has any of the given stereotype directly declared on the object. * * @param annotations The annotations * @return True if any of the given stereotypes are present */ @SuppressWarnings("unchecked") default boolean hasDeclaredStereotype(@Nullable Class<? extends Annotation>... annotations) { if (ArrayUtils.isEmpty(annotations)) { return false; } for (Class<? extends Annotation> annotation : annotations) { if (hasDeclaredStereotype(annotation)) { return true; } } return false; }
/** * Check whether any of the given stereotypes is present. * * @param annotations The annotations * @return True if any of the given stereotypes are present */ @SuppressWarnings("unchecked") default boolean hasStereotype(@Nullable Class<? extends Annotation>... annotations) { if (ArrayUtils.isEmpty(annotations)) { return false; } for (Class<? extends Annotation> annotation : annotations) { if (hasStereotype(annotation)) { return true; } } return false; }
private static Method[] introspectMethods(Class<?> beanClass) { // Get the list of methods belonging to this class Method[] basicMethods = beanClass.getMethods(); if (ArrayUtils.isEmpty(basicMethods)) { return null; } ArrayList<Method> methodList = new ArrayList<>(basicMethods.length); // Loop over the methods found, looking for public non-static methods for (Method basicMethod : basicMethods) { if (basicMethod.getDeclaringClass() == Object.class) { break; } int modifiers = basicMethod.getModifiers(); if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers) && !basicMethod.isBridge() && !basicMethod.isSynthetic() && basicMethod.getName().indexOf('$') == -1) { methodList.add(basicMethod); } } // Get the list of public methods into the returned array int methodCount = methodList.size(); Method[] theMethods = null; if (methodCount > 0) { theMethods = new Method[methodCount]; theMethods = methodList.toArray(theMethods); } return theMethods; }
@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); } }
this.implementInterface = implementInterface; if (!implementInterface && ArrayUtils.isEmpty(interfaceTypes)) { throw new IllegalArgumentException("if argument implementInterface is false at least one interface should be provided to the 'interfaceTypes' argument");
/** * @param params Parameters of the method */ public ParametersKey(Object... params) { if (ArrayUtils.isEmpty(params)) { this.params = ArrayUtils.EMPTY_OBJECT_ARRAY; this.hashCode = ClassUtils.EMPTY_OBJECT_ARRAY_HASH_CODE; } else { this.params = new Object[params.length]; System.arraycopy(params, 0, this.params, 0, params.length); this.hashCode = Arrays.deepHashCode(this.params); } }
/** * @param beanType The bean type * @param qualifier The qualifier * @param typeArguments The type arguments */ BeanKey(Class<T> beanType, Qualifier<T> qualifier, @Nullable Class... typeArguments) { this.beanType = beanType; this.qualifier = qualifier; this.typeArguments = ArrayUtils.isEmpty(typeArguments) ? null : typeArguments; int result = Objects.hash(beanType, qualifier); result = 31 * result + Arrays.hashCode(this.typeArguments); this.hashCode = result; }
private String[] getCacheNames(String[] cacheNames) { if (ArrayUtils.isEmpty(cacheNames)) { return defaultConfig.get(MEMBER_CACHE_NAMES, String[].class).orElse(StringUtils.EMPTY_STRING_ARRAY); } else { return cacheNames; } }
/** * Create default cache manager for the given caches. * * @param caches List of synchronous cache implementations */ public DefaultCacheManager(SyncCache<C>... caches) { if (ArrayUtils.isEmpty(caches)) { this.cacheMap = Collections.emptyMap(); } else { this.cacheMap = new LinkedHashMap<>(caches.length); for (SyncCache<C> cache : caches) { this.cacheMap.put(cache.getName(), cache); } } }
private String[] resolveCacheNames(AnnotationValue<CacheConfig> defaultConfig, AnnotationValue<Cacheable> cacheConfig) { String[] cacheNames = cacheConfig.get(MEMBER_CACHE_NAMES, String[].class).orElse(null); if (ArrayUtils.isEmpty(cacheNames)) { cacheNames = defaultConfig.get(MEMBER_CACHE_NAMES, String[].class).orElse(StringUtils.EMPTY_STRING_ARRAY); } return cacheNames; }
@Override public Publisher<PropertySource> getPropertySources(Environment environment) { if (ArrayUtils.isEmpty(configurationClients)) { return Flowable.empty(); } List<Publisher<PropertySource>> publishers = Arrays.stream(configurationClients) .map(configurationClient -> configurationClient.getPropertySources(environment)) .collect(Collectors.toList()); return Flowable.merge(publishers); }
private Object[] resolveParams(MethodInvocationContext<?, ?> context, String[] parameterNames) { Object[] parameterValues; if (ArrayUtils.isEmpty(parameterNames)) { parameterValues = context.getParameterValues(); } else { List list = new ArrayList(); Map<String, MutableArgumentValue<?>> parameters = context.getParameters(); for (String name : parameterNames) { list.add(parameters.get(name).getValue()); } parameterValues = list.toArray(); } return parameterValues; }
@Override public Object generateKey(AnnotationMetadata annotationMetadata, Object... params) { if (ArrayUtils.isEmpty(params)) { return ParametersKey.ZERO_ARG_KEY; } if (params.length == 1) { Object param = params[0]; if (param != null && !param.getClass().isArray()) { return param; } else { return new ParametersKey(params); } } else { return new ParametersKey(params); } } }
@Override public Flowable<List<String>> getServiceIds() { if (ArrayUtils.isEmpty(discoveryClients)) { return Flowable.just(Collections.emptyList()); } Stream<Flowable<List<String>>> flowableStream = Arrays.stream(discoveryClients).map(client -> Flowable.fromPublisher(client.getServiceIds())); Maybe<List<String>> reduced = Flowable.merge(flowableStream.collect(Collectors.toList())).reduce((strings, strings2) -> { strings.addAll(strings2); return strings; }); return reduced.toFlowable(); }
@Override public Flowable<List<ServiceInstance>> getInstances(String serviceId) { serviceId = NameUtils.hyphenate(serviceId); if (ArrayUtils.isEmpty(discoveryClients)) { return Flowable.just(Collections.emptyList()); } String finalServiceId = serviceId; Stream<Flowable<List<ServiceInstance>>> flowableStream = Arrays.stream(discoveryClients).map(client -> Flowable.fromPublisher(client.getInstances(finalServiceId))); Maybe<List<ServiceInstance>> reduced = Flowable.merge(flowableStream.collect(Collectors.toList())).reduce((instances, otherInstances) -> { instances.addAll(otherInstances); return instances; }); return reduced.toFlowable(); }
private void disposeOfBeanSubset(Collection<String> keys) { for (String beanKey : refreshableBeans.keySet()) { BeanRegistration beanRegistration = refreshableBeans.get(beanKey); BeanDefinition definition = beanRegistration.getBeanDefinition(); Optional<String[]> opt = definition.getValue(Refreshable.class, String[].class); if (opt.isPresent()) { String[] strings = opt.get(); if (!ArrayUtils.isEmpty(strings)) { List<String> prefixes = Arrays.asList(strings); for (String prefix : prefixes) { for (String k : keys) { if (k.startsWith(prefix)) { disposeOfBean(beanKey); } } } } else { disposeOfBean(beanKey); } } else { disposeOfBean(beanKey); } } }