001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 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 Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core;
011:
012: import java.util.ArrayList;
013:
014: import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
015:
016: public class FeatureModelDelta implements IFeatureModelDelta {
017: private ArrayList fAdded;
018:
019: private ArrayList fRemoved;
020:
021: private ArrayList fChanged;
022:
023: private int kind = 0;
024:
025: public FeatureModelDelta() {
026: }
027:
028: /*
029: * (non-Javadoc)
030: *
031: * @see org.eclipse.pde.internal.core.IFeatureModelDelta#getKind()
032: */
033: public int getKind() {
034: return kind;
035: }
036:
037: /*
038: * (non-Javadoc)
039: *
040: * @see org.eclipse.pde.internal.core.IFeatureModelDelta#getAdded()
041: */
042: public IFeatureModel[] getAdded() {
043: return get(fAdded);
044: }
045:
046: /*
047: * (non-Javadoc)
048: *
049: * @see org.eclipse.pde.internal.core.IFeatureModelDelta#getRemoved()
050: */
051: public IFeatureModel[] getRemoved() {
052: return get(fRemoved);
053: }
054:
055: /*
056: * (non-Javadoc)
057: *
058: * @see org.eclipse.pde.internal.core.IFeatureModelDelta#getChanged()
059: */
060: public IFeatureModel[] getChanged() {
061: return get(fChanged);
062: }
063:
064: private IFeatureModel[] get(ArrayList list) {
065: if (list == null)
066: return new IFeatureModel[0];
067: return (IFeatureModel[]) list.toArray(new IFeatureModel[list
068: .size()]);
069: }
070:
071: void add(IFeatureModel model, int type) {
072: switch (type) {
073: case ADDED:
074: fAdded = add(fAdded, model);
075: break;
076: case REMOVED:
077: fRemoved = add(fRemoved, model);
078: break;
079: case CHANGED:
080: fChanged = add(fChanged, model);
081: break;
082: }
083: kind |= type;
084: }
085:
086: private ArrayList add(ArrayList list, IFeatureModel model) {
087: if (list == null)
088: list = new ArrayList();
089: list.add(model);
090: return list;
091: }
092:
093: boolean contains(IFeatureModel model, int type) {
094: if ((type & ADDED) != 0 && fAdded != null
095: && fAdded.contains(model)) {
096: return true;
097: }
098: if ((type & REMOVED) != 0 && fRemoved != null
099: && fRemoved.contains(model)) {
100: return true;
101: }
102: if ((type & CHANGED) != 0 && fChanged != null
103: && fChanged.contains(model)) {
104: return true;
105: }
106: return false;
107: }
108: }
|