blob: ab1b6e8d968093867c60326952855b5138f12071 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/*******************************************************************************
* Copyright (c) 2007, 2010 Intel Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.tcmodification;
import org.eclipse.cdt.managedbuilder.internal.core.IRealBuildObjectAssociation;
/**
* The class implements the storage organized by types extending
* {@link IRealBuildObjectAssociation}.
*
* @param <T> - the type of object being stored.
*/
public final class ObjectTypeBasedStorage<T> implements Cloneable {
private static final int TOOL_INDEX = 0;
private static final int TOOLCHAIN_INDEX = 1;
private static final int BUILDER_INDEX = 2;
private static final int CFG_INDEX = 3;
private static final int SIZE = 4;
private static final int[] OBJECT_TYPES = new int[]{
IRealBuildObjectAssociation.OBJECT_TOOL,
IRealBuildObjectAssociation.OBJECT_TOOLCHAIN,
IRealBuildObjectAssociation.OBJECT_BUILDER,
IRealBuildObjectAssociation.OBJECT_CONFIGURATION,
};
@SuppressWarnings("unchecked")
private T fStorage[] = (T[]) new Object[SIZE];
public static int[] getSupportedObjectTypes(){
return OBJECT_TYPES.clone();
}
private int getIndex(int type){
switch (type) {
case IRealBuildObjectAssociation.OBJECT_TOOL:
return TOOL_INDEX;
case IRealBuildObjectAssociation.OBJECT_TOOLCHAIN:
return TOOLCHAIN_INDEX;
case IRealBuildObjectAssociation.OBJECT_BUILDER:
return BUILDER_INDEX;
case IRealBuildObjectAssociation.OBJECT_CONFIGURATION:
return CFG_INDEX;
default:
throw new IllegalArgumentException();
}
}
// private int getType(int index){
// switch (index) {
// case TOOL_INDEX:
// return IRealBuildObjectAssociation.OBJECT_TOOL;
// case TOOLCHAIN_INDEX:
// return IRealBuildObjectAssociation.OBJECT_TOOLCHAIN;
// case BUILDER_INDEX:
// return IRealBuildObjectAssociation.OBJECT_BUILDER;
// case CFG_INDEX:
// return IRealBuildObjectAssociation.OBJECT_CONFIGURATION;
// default:
// throw new IllegalArgumentException();
// }
// }
public T get(int type){
return fStorage[getIndex(type)];
}
public T set(int type, T value){
int index = getIndex(type);
T oldValue = fStorage[index];
fStorage[index] = value;
return oldValue;
}
@Override
public Object clone(){
try {
@SuppressWarnings("unchecked")
ObjectTypeBasedStorage<T> clone = (ObjectTypeBasedStorage<T>)super.clone();
clone.fStorage = fStorage.clone();
return clone;
} catch (CloneNotSupportedException e) {
e.printStackTrace();
return null;
}
}
public boolean isEmpty(){
for(int i = 0; i < fStorage.length; i++){
if(fStorage[i] != null)
return false;
}
return true;
}
}
|