|
1 /* |
|
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.carbide.internal.cpp.epoc.engine.model; |
|
19 |
|
20 import com.nokia.carbide.internal.api.cpp.epoc.engine.dom.IASTStatement; |
|
21 |
|
22 import java.util.*; |
|
23 |
|
24 /** |
|
25 * This is a set of objects that uses a converter class to measure equality. |
|
26 * @see StructuredItemListConverter#elementMatches(Object, Object) |
|
27 */ |
|
28 public class ConvertedModelSet<ModelType, NodeType extends IASTStatement> { |
|
29 |
|
30 private StructuredItemListConverter<NodeType, ModelType> converter; |
|
31 private ArrayList<ModelType> contents; |
|
32 |
|
33 /** |
|
34 * @param converter |
|
35 */ |
|
36 public ConvertedModelSet( |
|
37 StructuredItemListConverter<NodeType, ModelType> converter) { |
|
38 this.converter = converter; |
|
39 this.contents = new ArrayList<ModelType>(); |
|
40 } |
|
41 |
|
42 |
|
43 public void add(ModelType model) { |
|
44 if (!contains(model)) |
|
45 contents.add(model); |
|
46 } |
|
47 |
|
48 public boolean equals(Object other) { |
|
49 if (!(other instanceof ConvertedModelSet)) |
|
50 return false; |
|
51 ConvertedModelSet<ModelType, NodeType> otherSet = (ConvertedModelSet<ModelType, NodeType>) other; |
|
52 if (otherSet.contents.size() != contents.size()) |
|
53 return false; |
|
54 for (ModelType content : contents) { |
|
55 if (!otherSet.contains(content)) |
|
56 return false; |
|
57 } |
|
58 return true; |
|
59 } |
|
60 |
|
61 |
|
62 public boolean contains(ModelType model) { |
|
63 for (ModelType content : contents) { |
|
64 if (content == model || converter.elementMatches(model, content)) |
|
65 return true; |
|
66 } |
|
67 return false; |
|
68 } |
|
69 |
|
70 |
|
71 /** |
|
72 * @return |
|
73 */ |
|
74 public int size() { |
|
75 return contents.size(); |
|
76 } |
|
77 |
|
78 public void clear() { |
|
79 contents.clear(); |
|
80 } |
|
81 } |