@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()); } }
/** * Moves the object to the index of the list. * This implementation uses {@link #indexOf} of find the object * and delegates to {@link #move(int, int) move(int, int)}. * @param index the new position for the object in the list. * @param object the object to be moved. * @exception IndexOutOfBoundsException if the index isn't within the size range or the object isn't contained by the list. */ public void move(int index, E object) { move(index, indexOf(object)); }
/** * Removes the object from the list and returns whether the object was actually contained by the list. * This implementation uses {@link #indexOf indexOf} to find the object * and delegates to {@link #remove(int) remove(int)} * in the case that it finds the object. * @param object the object to be removed. * @return whether the object was actually contained by the list. */ @Override public boolean remove(Object object) { int index = indexOf(object); if (index >= 0) { remove(index); return true; } else { return false; } }
/** * Throws an exception. * @exception UnsupportedOperationException always because it's not supported. */ @Override public void set(E1 object) { throw new UnsupportedOperationException(); }