@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Reference reAttach(IdEObject mainObject) { // System.out.println("Re-attaching M " + getReferredObject() + " to " + mainObject + " on " + getIdEObject() + "." + geteReference().getName()); AbstractEList list = (AbstractEList) getIdEObject().eGet(geteReference()); int index = list.indexOf(getReferredObject()); if (index != -1) { try { list.set(index, mainObject); } catch (IllegalArgumentException e) { // e.printStackTrace(); } } // TODO if the old object really does exist multiple times, the new object should also exist multiple times... but it's probably a bug that it's there multiple times in the first place... while (list.contains(getReferredObject())) { list.remove(getReferredObject()); } return new MultiReference(getIdEObject(), mainObject, geteReference()); } }
/** * Adds the object at the end of the list * and returns whether the object was added; * if {@link #isUnique uniqueness} is required, * duplicates will be ignored and <code>false</code> will be returned. * This implementation delegates to {@link #addUnique(Object) addUnique(E)} * after uniqueness checking. * @param object the object to be added. * @return whether the object was added. * @see #addUnique(Object) */ @Override public boolean add(E object) { if (isUnique() && contains(object)) { return false; } else { addUnique(object); return true; } }
/** * Adds the object at the given index in the list. * If {@link #isUnique uniqueness} is required, * duplicates will be ignored. * This implementation delegates to {@link #addUnique(int, Object) addUnique(int, E)} * after uniqueness checking. * @param object the object to be added. * @exception IllegalArgumentException if {@link #isUnique uniqueness} is required, * and the object is a duplicate. * @see #addUnique(int, Object) */ @Override public void add(int index, E object) { int size = size(); if (index > size) throw new BasicIndexOutOfBoundsException(index, size); if (isUnique() && contains(object)) { throw new IllegalArgumentException("The 'no duplicates' constraint is violated"); } addUnique(index, object); }