/** * Configure one or more factories to decorate the handler used to process * WebSocket messages. This may be useful in some advanced use cases, for * example to allow Spring Security to forcibly close the WebSocket session * when the corresponding HTTP session expires. * @since 4.1.2 */ public WebSocketTransportRegistration setDecoratorFactories(WebSocketHandlerDecoratorFactory... factories) { this.decoratorFactories.addAll(Arrays.asList(factories)); return this; }
public static void assertContainsAllOf(Iterable<?> actual, Object... expected) { List<Object> expectedList = new ArrayList<>(); expectedList.addAll(Arrays.asList(expected)); for (Object o : actual) { expectedList.remove(o); } if (!expectedList.isEmpty()) { Assert.fail("Not true that " + actual + " contains all of " + Arrays.asList(expected)); } }
/** Returns a snapshot of the calls currently being executed. */ public synchronized List<Call> runningCalls() { List<Call> result = new ArrayList<>(); result.addAll(runningSyncCalls); for (AsyncCall asyncCall : runningAsyncCalls) { result.add(asyncCall.get()); } return Collections.unmodifiableList(result); }
/** * Returns an immutable map containing each field to its list of values. * * @param valueForNullKey the request line for requests, or the status line for responses. If * non-null, this value is mapped to the null key. */ public static Map<String, List<String>> toMultimap(Headers headers, String valueForNullKey) { Map<String, List<String>> result = new TreeMap<>(FIELD_NAME_COMPARATOR); for (int i = 0, size = headers.size(); i < size; i++) { String fieldName = headers.name(i); String value = headers.value(i); List<String> allValues = new ArrayList<>(); List<String> otherValues = result.get(fieldName); if (otherValues != null) { allValues.addAll(otherValues); } allValues.add(value); result.put(fieldName, Collections.unmodifiableList(allValues)); } if (valueForNullKey != null) { result.put(null, Collections.unmodifiableList(Collections.singletonList(valueForNullKey))); } return Collections.unmodifiableMap(result); } }
private List<String> updateLocations(String path, List<String> possibleLocations) { List<String> knownLocations = new ArrayList<>(); for (String location : possibleLocations) { String expectedLocation = path + "/" + location; File file = new File(expectedLocation + "/output.json"); if (file.exists()) { Matcher matcher = OUTPUT_JSON_PATTERN.matcher(readJsonFromFile(file)); if (matcher.matches()) { String relativeManifestPath = matcher.group(1); File manifestFile = new File(expectedLocation + "/" + relativeManifestPath); String manifestDirectory = manifestFile.getParentFile().getAbsolutePath(); knownLocations.add(manifestDirectory.substring(path.length())); } } } if (knownLocations.isEmpty()) { knownLocations.addAll(possibleLocations); } return knownLocations; }
/** * Parse the given list of (potentially) comma-separated strings into a * list of {@code MediaType} objects. * <p>This method can be used to parse an Accept or Content-Type header. * @param mediaTypes the string to parse * @return the list of media types * @throws InvalidMediaTypeException if the media type value cannot be parsed * @since 4.3.2 */ public static List<MediaType> parseMediaTypes(@Nullable List<String> mediaTypes) { if (CollectionUtils.isEmpty(mediaTypes)) { return Collections.emptyList(); } else if (mediaTypes.size() == 1) { return parseMediaTypes(mediaTypes.get(0)); } else { List<MediaType> result = new ArrayList<>(8); for (String mediaType : mediaTypes) { result.addAll(parseMediaTypes(mediaType)); } return result; } }
private static Map<Class<? extends Throwable>, Method> initExceptionMappings(Class<?> handlerType) { Map<Method, MessageExceptionHandler> methods = MethodIntrospector.selectMethods(handlerType, (MethodIntrospector.MetadataLookup<MessageExceptionHandler>) method -> AnnotatedElementUtils.findMergedAnnotation(method, MessageExceptionHandler.class)); Map<Class<? extends Throwable>, Method> result = new HashMap<>(); for (Map.Entry<Method, MessageExceptionHandler> entry : methods.entrySet()) { Method method = entry.getKey(); List<Class<? extends Throwable>> exceptionTypes = new ArrayList<>(); exceptionTypes.addAll(Arrays.asList(entry.getValue().value())); if (exceptionTypes.isEmpty()) { exceptionTypes.addAll(getExceptionsFromMethodSignature(method)); } for (Class<? extends Throwable> exceptionType : exceptionTypes) { Method oldMethod = result.put(exceptionType, method); if (oldMethod != null && !oldMethod.equals(method)) { throw new IllegalStateException("Ambiguous @ExceptionHandler method mapped for [" + exceptionType + "]: {" + oldMethod + ", " + method + "}"); } } } return result; }
private void updateFilters() { if (this.filters.isEmpty()) { return; } List<WebFilter> filtersToUse = this.filters.stream() .peek(filter -> { if (filter instanceof ForwardedHeaderTransformer && this.forwardedHeaderTransformer == null) { this.forwardedHeaderTransformer = (ForwardedHeaderTransformer) filter; } }) .filter(filter -> !(filter instanceof ForwardedHeaderTransformer)) .collect(Collectors.toList()); this.filters.clear(); this.filters.addAll(filtersToUse); }
public static InputGate createInputGate(Collection<InputGate> inputGates1, Collection<InputGate> inputGates2) { List<InputGate> gates = new ArrayList<InputGate>(inputGates1.size() + inputGates2.size()); gates.addAll(inputGates1); gates.addAll(inputGates2); return createInputGate(gates.toArray(new InputGate[gates.size()])); }
@Test public void multipleKeyRows() { Map<String, Object> m = new HashMap<String, Object>() {{ put("key", 1); put("seq", 2); }}; kh.getKeyList().addAll(asList(m, m)); assertEquals("two rows should be in the list", 2, kh.getKeyList().size()); exception.expect(InvalidDataAccessApiUsageException.class); exception.expectMessage(startsWith("The getKeys method should only be used when keys for a single row are returned.")); kh.getKeys(); }
private static void insertAtStart(BlockNode block, List<InsnNode> insns) { List<InsnNode> blockInsns = block.getInstructions(); List<InsnNode> newInsnList = new ArrayList<>(insns.size() + blockInsns.size()); newInsnList.addAll(insns); newInsnList.addAll(blockInsns); blockInsns.clear(); blockInsns.addAll(newInsnList); }
@Override public Object[] getConstructorArgs() { if (outerClassInstance == null) { return constructorArgs; } List<Object> resultArgs = new ArrayList<Object>(constructorArgs.length + 1); resultArgs.add(outerClassInstance); resultArgs.addAll(Arrays.asList(constructorArgs)); return resultArgs.toArray(new Object[constructorArgs.length + 1]); }
private static List<MediaType> initMediaTypes(@Nullable HttpMessageWriter<?> formWriter) { List<MediaType> result = new ArrayList<>(); result.add(MediaType.MULTIPART_FORM_DATA); if (formWriter != null) { result.addAll(formWriter.getWritableMediaTypes()); } return Collections.unmodifiableList(result); }
public void declareStream(String streamId, boolean direct, Fields fields) { if (_fields.containsKey(streamId)) { throw new IllegalArgumentException("Fields for " + streamId + " already set"); } List<String> fieldList = new ArrayList<>(); fieldList.add(TransactionCommon.BATCH_GROUP_ID_FIELD); fieldList.addAll(fields.toList()); _fields.put(streamId, new StreamInfo(fieldList, direct)); }
@SafeVarargs public static <T> TupleDomain<T> columnWiseUnion(TupleDomain<T> first, TupleDomain<T> second, TupleDomain<T>... rest) { List<TupleDomain<T>> domains = new ArrayList<>(rest.length + 2); domains.add(first); domains.add(second); domains.addAll(Arrays.asList(rest)); return columnWiseUnion(domains); }