001    /*
002     * Copyright (c) 2006 IBM Corporation and others.
003     * All rights reserved.   This program and the accompanying materials
004     * are made available under the terms of the Eclipse Public License v1.0
005     * which accompanies this distribution, and is available at
006     * http://www.eclipse.org/legal/epl-v10.html
007     *
008     * Contributors:
009     *   IBM - initial API and implementation
010     *
011     * $Id: SubsetSupersetEObjectContainmentEList.java,v 1.3 2006/12/14 15:47:32 khussey Exp $
012     */
013    package org.eclipse.uml2.common.util;
014    
015    import java.util.ArrayList;
016    import java.util.Collection;
017    
018    import org.eclipse.emf.common.notify.Notification;
019    import org.eclipse.emf.ecore.EObject;
020    import org.eclipse.emf.ecore.InternalEObject;
021    
022    /**
023     * @since 1.2
024     */
025    public class SubsetSupersetEObjectContainmentEList<E>
026                    extends SubsetSupersetEObjectEList<E> {
027    
028            private static final long serialVersionUID = 1L;
029    
030            public static class Unsettable<E>
031                            extends SubsetSupersetEObjectContainmentEList<E> {
032    
033                    private static final long serialVersionUID = 1L;
034    
035                    public static class Resolving<E>
036                                    extends Unsettable<E> {
037    
038                            private static final long serialVersionUID = 1L;
039    
040                            public Resolving(Class<?> dataClass, InternalEObject owner,
041                                            int featureID, int[] supersetFeatureIDs,
042                                            int[] subsetFeatureIDs) {
043                                    super(dataClass, owner, featureID, supersetFeatureIDs,
044                                            subsetFeatureIDs);
045                            }
046    
047                            @Override
048                            protected boolean hasProxies() {
049                                    return true;
050                            }
051    
052                            @SuppressWarnings("unchecked")
053                            @Override
054                            protected E resolve(int index, E object) {
055                                    return (E) resolve(index, (EObject) object);
056                            }
057                    }
058    
059                    protected boolean isSet;
060    
061                    public Unsettable(Class<?> dataClass, InternalEObject owner,
062                                    int featureID, int[] supersetFeatureIDs, int[] subsetFeatureIDs) {
063                            super(dataClass, owner, featureID, supersetFeatureIDs,
064                                    subsetFeatureIDs);
065                    }
066    
067                    @Override
068                    protected void didChange() {
069                            isSet = true;
070                    }
071    
072                    @Override
073                    public boolean isSet() {
074                            return isSet;
075                    }
076    
077                    @Override
078                    public void unset() {
079                            super.unset();
080    
081                            if (isNotificationRequired()) {
082                                    boolean oldIsSet = isSet;
083                                    isSet = false;
084    
085                                    owner.eNotify(createNotification(Notification.UNSET, oldIsSet,
086                                            false));
087                            } else {
088                                    isSet = false;
089                            }
090                    }
091            }
092    
093            public static class Resolving<E>
094                            extends SubsetSupersetEObjectContainmentEList<E> {
095    
096                    private static final long serialVersionUID = 1L;
097    
098                    public Resolving(Class<?> dataClass, InternalEObject owner,
099                                    int featureID, int[] supersetFeatureIDs, int[] subsetFeatureIDs) {
100                            super(dataClass, owner, featureID, supersetFeatureIDs,
101                                    subsetFeatureIDs);
102                    }
103    
104                    @Override
105                    protected boolean hasProxies() {
106                            return true;
107                    }
108    
109                    @SuppressWarnings("unchecked")
110                    @Override
111                    protected E resolve(int index, E object) {
112                            return (E) resolve(index, (EObject) object);
113                    }
114            }
115    
116            public SubsetSupersetEObjectContainmentEList(Class<?> dataClass,
117                            InternalEObject owner, int featureID, int[] supersetFeatureIDs,
118                            int[] subsetFeatureIDs) {
119                    super(dataClass, owner, featureID, supersetFeatureIDs, subsetFeatureIDs);
120            }
121    
122            @Override
123            protected boolean hasInverse() {
124                    return true;
125            }
126    
127            @Override
128            protected boolean hasNavigableInverse() {
129                    return false;
130            }
131    
132            @Override
133            protected boolean isContainment() {
134                    return true;
135            }
136    
137            @Override
138            public boolean addAll(Collection<? extends E> collection) {
139                    return super.addAll(new ArrayList<E>(collection));
140            }
141    
142            @Override
143            public boolean addAll(int index, Collection<? extends E> collection) {
144                    return super.addAll(index, new ArrayList<E>(collection));
145            }
146    
147    }