/** * Removes a path segment. When this method returns the last segment is always "", which means * the encoded path will have a trailing '/'. * * <p>Popping "/a/b/c/" yields "/a/b/". In this case the list of path segments goes from ["a", * "b", "c", ""] to ["a", "b", ""]. * * <p>Popping "/a/b/c" also yields "/a/b/". The list of path segments goes from ["a", "b", "c"] * to ["a", "b", ""]. */ private void pop() { String removed = encodedPathSegments.remove(encodedPathSegments.size() - 1); // Make sure the path ends with a '/' by either adding an empty string or clearing a segment. if (removed.isEmpty() && !encodedPathSegments.isEmpty()) { encodedPathSegments.set(encodedPathSegments.size() - 1, ""); } else { encodedPathSegments.add(""); } }
private static void removeCompletedStateUpdatesFromMap( Map<String, List<StateUpdate>> currentStateUpdates, Map<String, List<StateUpdate>> completedStateUpdates, String key) { List<StateUpdate> completed = completedStateUpdates.get(key); List<StateUpdate> current = currentStateUpdates.remove(key); if (completed != null && current != null) { current.removeAll(completed); } if (current != null && !current.isEmpty()) { currentStateUpdates.put(key, current); } }
public RenderOnDemandClosure(JellyContext context, String attributesToCapture) { List<Script> bodyStack = new ArrayList<Script>(); for (JellyContext c = context; c!=null; c=c.getParent()) { Script script = (Script) c.getVariables().get("org.apache.commons.jelly.body"); if(script!=null) bodyStack.add(script); } this.bodyStack = bodyStack.toArray(new Script[bodyStack.size()]); assert !bodyStack.isEmpty(); // there must be at least one, which is the direct child of <l:renderOnDemand> Map<String,Object> variables = new HashMap<String, Object>(); for (String v : Util.fixNull(attributesToCapture).split(",")) variables.put(v.intern(),context.getVariable(v)); // capture the current base of context for descriptors currentDescriptorByNameUrl = Descriptor.getCurrentDescriptorByNameUrl(); this.variables = PackedMap.of(variables); Set<String> _adjuncts = AdjunctsInPage.get().getIncluded(); this.adjuncts = new String[_adjuncts.size()]; int i = 0; for (String adjunct : _adjuncts) { this.adjuncts[i++] = adjunct.intern(); } }
public void testAsMapGet() { for (K key : sampleKeys()) { List<V> expectedValues = new ArrayList<>(); for (Entry<K, V> entry : getSampleElements()) { if (entry.getKey().equals(key)) { expectedValues.add(entry.getValue()); } } Collection<V> collection = multimap().asMap().get(key); if (expectedValues.isEmpty()) { assertNull(collection); } else { assertEqualIgnoringOrder(expectedValues, collection); } } }
private static Profiles merge(String expression, List<Profiles> elements, @Nullable Operator operator) { assertWellFormed(expression, !elements.isEmpty()); if (elements.size() == 1) { return elements.get(0); } Profiles[] profiles = elements.toArray(new Profiles[0]); return (operator == Operator.AND ? and(profiles) : or(profiles)); }
@Override public List<URL> lookup(URL url) { List<URL> urls = new ArrayList<>(); Map<String, List<URL>> notifiedUrls = getNotified().get(url); if (notifiedUrls != null && notifiedUrls.size() > 0) { for (List<URL> values : notifiedUrls.values()) { urls.addAll(values); if (urls.isEmpty()) { List<URL> cacheUrls = getCacheUrls(url); if (CollectionUtils.isNotEmpty(cacheUrls)) { urls.addAll(cacheUrls); if (urls.isEmpty()) { for (URL u : getRegistered()) { if (UrlUtils.isMatch(url, u)) { urls.add(u); for (URL u : getSubscribed().keySet()) { if (UrlUtils.isMatch(url, u)) { urls.add(u);
/** * Return all configured {@link MappedInterceptor MappedInterceptors} as an array. * @return the array of {@link MappedInterceptor MappedInterceptors}, or {@code null} if none */ @Nullable protected final MappedInterceptor[] getMappedInterceptors() { List<MappedInterceptor> mappedInterceptors = new ArrayList<>(this.adaptedInterceptors.size()); for (HandlerInterceptor interceptor : this.adaptedInterceptors) { if (interceptor instanceof MappedInterceptor) { mappedInterceptors.add((MappedInterceptor) interceptor); } } return (!mappedInterceptors.isEmpty() ? mappedInterceptors.toArray(new MappedInterceptor[0]) : null); }
@Deprecated @Override public Map<String,List<String>> getExensionsFor( Class<?> type ) { Map<String,List<String>> result = new HashMap<>(); for ( Map.Entry<String,ServerExtender> extension : extensions.entrySet() ) { List<String> methods = new ArrayList<>(); for ( PluginPoint method : extension.getValue() .getExtensionsFor( type ) ) { methods.add( method.name() ); } if ( !methods.isEmpty() ) { result.put( extension.getKey(), methods ); } } return result; }
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)); } }
static <E> List<List<E>> create(List<? extends List<? extends E>> lists) { ImmutableList.Builder<List<E>> axesBuilder = new ImmutableList.Builder<>(lists.size()); for (List<? extends E> list : lists) { List<E> copy = ImmutableList.copyOf(list); if (copy.isEmpty()) { return ImmutableList.of(); } axesBuilder.add(copy); } return new CartesianList<E>(axesBuilder.build()); }
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; }