private void addNamespace(Namespace ns) { if (ns == defaultNamespace) return; for (Namespace n : namespaces) if (n == ns) return; if (defaultNamespace != null && (ns.uri.equals(defaultNamespace.uri) || ns.name.equals(defaultNamespace.name))) defaultNamespace = ns; else namespaces = append(namespaces, ns); }
/** * Removes the specified element from the specified array. * * @param element The element to remove from the array. * @param array The array to remove the element from. * @return A new array with the element removed, or the original array if the array did not contain the element. */ public static Object[] remove(Object element, Object[] array) { if (! contains(element, array)) return array; List<Object> l = new ArrayList<>(array.length); for (Object o2 : array) { if (! element.equals(o2)) l.add(o2); } return l.toArray(new Object[l.size()]); } }
@Override /* Map */ public Set<String> keySet() { return asSet(keys); }
/** * Sets an array field on this bean. * * <p> * Works on both <code>Object</code> and primitive arrays. * * @param bean The bean of the field. * @param l The collection to use to set the array field. * @throws IllegalArgumentException Thrown by method invocation. * @throws IllegalAccessException Thrown by method invocation. * @throws InvocationTargetException Thrown by method invocation. */ protected void setArray(Object bean, List l) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Object array = toArray(l, this.rawTypeMeta.getElementType().getInnerClass()); invokeSetter(bean, name, array); }
/** * Creates the class-level guards associated with this servlet. * <p> * Subclasses can override this method to provide their own class-level guards for this servlet. * <p> * By default, returns the guards specified through the {@link RestResource#guards() @RestResource.guards()} annotation in child-to-parent order. * (i.e. guards on children will be called before guards on parents). * * @param properties Servlet-level properties returned by {@link #createProperties()}. * @return The new set of guards associated with this servet. * @throws RestServletException */ protected RestGuard[] createGuards(ObjectMap properties) throws RestServletException { List<RestGuard> l = new LinkedList<RestGuard>(); // Guards are loaded in child-to-parent order. for (RestResource r : restResourceAnnotationsChildFirst.values()) for (Class<? extends RestGuard> c : reverse(r.guards())) try { l.add(c.newInstance()); } catch (Exception e) { throw new RestServletException("Exception occurred while trying to instantiate RestGuard ''{0}''", c.getSimpleName()).initCause(e); } return l.toArray(new RestGuard[l.size()]); }
/** * Creates a new {@link EncoderGroup} object using a snapshot of the settings defined in this builder. * * <p> * This method can be called multiple times to produce multiple encoder groups. * * @return A new {@link EncoderGroup} object. */ public EncoderGroup build() { List<Encoder> l = new ArrayList<>(); for (Object e : encoders) l.add(beanContext.newInstance(Encoder.class, e)); return new EncoderGroup(ArrayUtils.toReverseArray(Encoder.class, l)); } }
/** * Returns <jk>true</jk> if the specified array contains the specified element using the {@link String#equals(Object)} * method. * * @param element The element to check for. * @param array The array to check. * @return * <jk>true</jk> if the specified array contains the specified element, * <jk>false</jk> if the array or element is <jk>null</jk>. */ public static boolean contains(String element, String[] array) { return indexOf(element, array) != -1; }
copyToList(oldArray, l);
/** * Sets an array field on this bean. * * <p> * Works on both <code>Object</code> and primitive arrays. * * @param bean The bean of the field. * @param l The collection to use to set the array field. * @throws IllegalArgumentException Thrown by method invocation. * @throws IllegalAccessException Thrown by method invocation. * @throws InvocationTargetException Thrown by method invocation. */ protected void setArray(Object bean, List l) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Object array = toArray(l, this.rawTypeMeta.getElementType().getInnerClass()); invokeSetter(bean, name, array); }
@Test public void testReverse() throws Exception { String[] s = null; assertNull(reverse(s)); s = new String[]{}; assertObjectEquals("[]", reverse(s)); s = new String[]{"a"}; assertObjectEquals("['a']", reverse(s)); s = new String[]{"a","b"}; assertObjectEquals("['b','a']", reverse(s)); s = new String[]{"a","b","c"}; assertObjectEquals("['c','b','a']", reverse(s)); }
/** * Creates a new {@link EncoderGroup} object using a snapshot of the settings defined in this builder. * * <p> * This method can be called multiple times to produce multiple encoder groups. * * @return A new {@link EncoderGroup} object. */ public EncoderGroup build() { List<Encoder> l = new ArrayList<>(); for (Object e : encoders) l.add(beanContext.newInstance(Encoder.class, e)); return new EncoderGroup(ArrayUtils.toReverseArray(Encoder.class, l)); } }
private SerializerWriter serializeMap(UonWriter out, Map m, ClassMeta<?> type) throws Exception { m = sort(m); ClassMeta<?> keyType = type.getKeyType(), valueType = type.getValueType(); boolean addAmp = false; for (Map.Entry e : (Set<Map.Entry>)m.entrySet()) { Object key = generalize(e.getKey(), keyType); Object value = e.getValue(); if (shouldUseExpandedParams(value)) { Iterator i = value instanceof Collection ? ((Collection)value).iterator() : iterator(value); while (i.hasNext()) { if (addAmp) out.cr(indent).append('&'); out.appendObject(key, true).append('='); super.serializeAnything(out, i.next(), null, (key == null ? null : key.toString()), null); addAmp = true; } } else { if (addAmp) out.cr(indent).append('&'); out.appendObject(key, true).append('='); super.serializeAnything(out, value, valueType, (key == null ? null : key.toString()), null); addAmp = true; } } return out; }
/** * Returns <jk>true</jk> if the specified array contains the specified element using the {@link Object#equals(Object)} * method. * * @param element The element to check for. * @param array The array to check. * @return * <jk>true</jk> if the specified array contains the specified element, * <jk>false</jk> if the array or element is <jk>null</jk>. */ public static <T> boolean contains(T element, T[] array) { return indexOf(element, array) != -1; }
copyToList(oldArray, l);
private void addNamespace(Namespace ns) { if (ns == defaultNamespace) return; for (Namespace n : namespaces) if (n == ns) return; if (defaultNamespace != null && (ns.uri.equals(defaultNamespace.uri) || ns.name.equals(defaultNamespace.name))) defaultNamespace = ns; else namespaces = append(namespaces, ns); }
/** * Removes the specified element from the specified array. * * @param element The element to remove from the array. * @param array The array to remove the element from. * @return A new array with the element removed, or the original array if the array did not contain the element. */ public static Object[] remove(Object element, Object[] array) { if (! contains(element, array)) return array; List<Object> l = new ArrayList<>(array.length); for (Object o2 : array) { if (! element.equals(o2)) l.add(o2); } return l.toArray(new Object[l.size()]); } }
/** * Sets an array field on this bean. * * <p> * Works on both <code>Object</code> and primitive arrays. * * @param bean The bean of the field. * @param l The collection to use to set the array field. * @throws IllegalArgumentException Thrown by method invocation. * @throws IllegalAccessException Thrown by method invocation. * @throws InvocationTargetException Thrown by method invocation. */ protected void setArray(Object bean, List l) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Object array = toArray(l, this.rawTypeMeta.getElementType().getInnerClass()); invokeSetter(bean, name, array); }