Skip to content

Package: CachedTreeNode

CachedTreeNode

nameinstructionbranchcomplexitylinemethod
CachedTreeNode(Object)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getCache()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getChildValue()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getOwnValue()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getParent()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
putIntoCache(Object, Object)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
removeFromCache(Object)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setChildValue(Object)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setOwnValue(Object)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setParent(Object)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
values()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2012 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: *
13: *******************************************************************************/
14: package org.eclipse.emf.ecp.common.spi.cachetree;
15:
16: import java.util.Collection;
17: import java.util.LinkedHashMap;
18: import java.util.Map;
19:
20: /**
21: * A node within an {@link AbstractCachedTree}.
22: *
23: * @param <T> the type of the value stored by this node
24: *
25: * @author emueller
26: * @author Tobias Verhoeven
27: * @since 1.5
28: */
29: public abstract class CachedTreeNode<T> {
30:
31:         private T ownValue;
32:         private T cachedChildrenValue;
33:         private final Map<Object, T> cache;
34:         private Object parent;
35:
36:         /**
37:          * Constructor.
38:          *
39:          * @param initialValue the initial value
40:          */
41:         public CachedTreeNode(T initialValue) {
42:                 this.ownValue = initialValue;
43:                 cache = new LinkedHashMap<Object, T>();
44:         }
45:
46:         /**
47:          * Recomputes the cached value of this node.
48:          */
49:         protected abstract void update();
50:
51:         /**
52:          * Puts a value into the cache and updates its value.
53:          *
54:          * @param key
55:          * the (child) object that contains the given value
56:          * @param value
57:          * an additional value that will be considered for the computation of the
58:          * actual value that results to a {@link #update()} call
59:          */
60:         // TODO rename method
61:         public void putIntoCache(Object key, T value) {
62:                 cache.put(key, value);
63:                 update();
64:         }
65:
66:         /**
67:          * Removes a (child) object from the cache and updates its value.
68:          *
69:          * @param key
70:          * the object to be removed
71:          */
72:         // TODO rename method
73:         public void removeFromCache(Object key) {
74:                 cache.remove(key);
75:                 update();
76:         }
77:
78:         /**
79:          * Returns the value of this node.
80:          *
81:          * @return the value stored within this node
82:          */
83:         public T getOwnValue() {
84:                 return ownValue;
85:         }
86:
87:         /**
88:          * Sets the value of this node.
89:          *
90:          * @param newValue
91:          * the new value to be associated with this node
92:          */
93:         public void setOwnValue(T newValue) {
94:                 this.ownValue = newValue;
95:         }
96:
97:         /**
98:          * Returns the cached values that are stored in the children nodes.
99:          *
100:          * @return a set of values stored in the children nodes of this node
101:          */
102:         public Collection<T> values() {
103:                 return cache.values();
104:         }
105:
106:         /**
107:          * Returns the most severe cached value of all children.
108:          *
109:          * @return the childValue
110:          */
111:         public T getChildValue() {
112:                 return cachedChildrenValue;
113:         }
114:
115:         /**
116:          * Sets the the most severe cached value of all children.
117:          *
118:          * @param childValue the childValue to set
119:          */
120:         protected void setChildValue(T childValue) {
121:                 this.cachedChildrenValue = childValue;
122:         }
123:
124:         /**
125:          * Returns the value that this node should represent.
126:          * This value is also passed to parents in case of changes to the tree.
127:          *
128:          * @return the display value
129:          */
130:         public abstract T getDisplayValue();
131:
132:         /**
133:          * @return the parent object, this is not the parent tree node.
134:          */
135:         public Object getParent() {
136:                 return parent;
137:         }
138:
139:         /**
140:          * @param parent the parent to set, this is not the parent tree node.
141:          */
142:         public void setParent(Object parent) {
143:                 this.parent = parent;
144:         }
145:
146:         /**
147:          * Returns the internal representation of the child value cache.
148:          *
149:          * @return the cache
150:          * @since 1.9
151:          */
152:         protected final Map<Object, T> getCache() {
153:                 return cache;
154:         }
155: }