KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > FeatureModelDelta


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
16
17 public class FeatureModelDelta implements IFeatureModelDelta {
18     private ArrayList JavaDoc fAdded;
19
20     private ArrayList JavaDoc fRemoved;
21
22     private ArrayList JavaDoc fChanged;
23
24     private int kind = 0;
25
26     public FeatureModelDelta() {
27     }
28
29     /*
30      * (non-Javadoc)
31      *
32      * @see org.eclipse.pde.internal.core.IFeatureModelDelta#getKind()
33      */

34     public int getKind() {
35         return kind;
36     }
37
38     /*
39      * (non-Javadoc)
40      *
41      * @see org.eclipse.pde.internal.core.IFeatureModelDelta#getAdded()
42      */

43     public IFeatureModel[] getAdded() {
44         return get(fAdded);
45     }
46
47     /*
48      * (non-Javadoc)
49      *
50      * @see org.eclipse.pde.internal.core.IFeatureModelDelta#getRemoved()
51      */

52     public IFeatureModel[] getRemoved() {
53         return get(fRemoved);
54     }
55
56     /*
57      * (non-Javadoc)
58      *
59      * @see org.eclipse.pde.internal.core.IFeatureModelDelta#getChanged()
60      */

61     public IFeatureModel[] getChanged() {
62         return get(fChanged);
63     }
64
65     private IFeatureModel[] get(ArrayList JavaDoc list) {
66         if (list == null)
67             return new IFeatureModel[0];
68         return (IFeatureModel[]) list.toArray(new IFeatureModel[list.size()]);
69     }
70
71     void add(IFeatureModel model, int type) {
72         switch (type) {
73         case ADDED:
74             fAdded = add(fAdded, model);
75             break;
76         case REMOVED:
77             fRemoved = add(fRemoved, model);
78             break;
79         case CHANGED:
80             fChanged = add(fChanged, model);
81             break;
82         }
83         kind |= type;
84     }
85
86     private ArrayList JavaDoc add(ArrayList JavaDoc list, IFeatureModel model) {
87         if (list == null)
88             list = new ArrayList JavaDoc();
89         list.add(model);
90         return list;
91     }
92
93     boolean contains(IFeatureModel model, int type) {
94         if ((type & ADDED) != 0 && fAdded != null && fAdded.contains(model)) {
95             return true;
96         }
97         if ((type & REMOVED) != 0 && fRemoved != null
98                 && fRemoved.contains(model)) {
99             return true;
100         }
101         if ((type & CHANGED) != 0 && fChanged != null
102                 && fChanged.contains(model)) {
103             return true;
104         }
105         return false;
106     }
107 }
108
Popular Tags