/** * Appends all of the elements in the specified Collection to the end of this list, in the order * that they are returned by the specified Collection's Iterator. The behavior of this * operation is undefined if the specified Collection is modified while the operation is in * progress. (This implies that the behavior of this call is undefined if the specified * Collection is this list, and this list is nonempty.) * <p/> * This method performs any necessary type conversion. * * @param c the elements to be inserted into this list. * @return <tt>true</tt> if this list changed as a result of the call. * @throws NullPointerException if the specified collection is null. */ @Override public boolean addAll(Collection c) { if (c == null) { throw new NullPointerException("Collection to add is null"); } for (Object aC : c) { add(aC); } return true; }
/** * Inserts the specified element at the specified position in this list. Shifts the element * currently at that position (if any) and any subsequent elements to the right (adds one to * their indices). * <p/> * This method is guaranteed to work since it will create empty beans to fill the gap between * the current list size and the requested index to enable the element to be set. This method * also performs any necessary type conversion. * * @param index index at which the specified element is to be inserted. * @param element element to be inserted. */ @Override public void add(int index, Object element) { if (index >= this.size()) { get(index); } element = convert(element); super.add(index, element); }
/** * Returns the element at the specified position in this list. * <p/> * An object is guaranteed to be returned since it will create empty beans to fill the gap * between the current list size and the requested index. * * @param index index of element to return. * @return the element at the specified position in this list. */ @Override public synchronized Object get(int index) { while (index >= this.size()) { try { this.add(getObjectFactory().buildBean(clazz, ActionContext.getContext().getContextMap())); } catch (Exception e) { throw new XWorkException(e); } } return super.get(index); }
@Override public boolean contains(Object element) { element = convert(element); return super.contains(element); } }
private Collection createCollection(Class toType, Class memberType, int size) { Collection result; if (toType == Set.class) { if (size > 0) { result = new HashSet(size); } else { result = new HashSet(); } } else if (toType == SortedSet.class) { result = new TreeSet(); } else { if (size > 0) { result = new XWorkList(memberType, size); } else { result = new XWorkList(memberType); } } return result; }
private Object convert(Object element) { if ((element != null) && !clazz.isAssignableFrom(element.getClass())) { // convert to correct type if (LOG.isDebugEnabled()) { LOG.debug("Converting from " + element.getClass().getName() + " to " + clazz.getName()); } TypeConverter conv = getTypeConverter(); Map<String, Object> context = ActionContext.getContext().getContextMap(); element = conv.convertValue(context, null, null, null, element, clazz); } return element; }
/** * Appends the specified element to the end of this list. * <p/> * This method performs any necessary type conversion. * * @param element element to be appended to this list. * @return <tt>true</tt> (as per the general contract of Collection.add). */ @Override public boolean add(Object element) { element = convert(element); return super.add(element); }
/** * Replaces the element at the specified position in this list with the specified element. * <p/> * This method is guaranteed to work since it will create empty beans to fill the gap between * the current list size and the requested index to enable the element to be set. This method * also performs any necessary type conversion. * * @param index index of element to replace. * @param element element to be stored at the specified position. * @return the element previously at the specified position. */ @Override public Object set(int index, Object element) { if (index >= this.size()) { get(index); } element = convert(element); return super.set(index, element); }