Skip to content

Package: EMFIndexedValuePropertyDelegator

EMFIndexedValuePropertyDelegator

nameinstructionbranchcomplexitylinemethod
EMFIndexedValuePropertyDelegator(IValueProperty, int)
M: 5 C: 11
69%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 5
83%
M: 0 C: 1
100%
adaptListener(ISimplePropertyListener)
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
doGetValue(Object)
M: 2 C: 20
91%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 4
80%
M: 0 C: 1
100%
doSetValue(Object, Object)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getValueType()
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-2015 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: * Lucas - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.dynamictree.model.impl;
15:
16: import java.util.List;
17:
18: import org.eclipse.core.databinding.property.INativePropertyListener;
19: import org.eclipse.core.databinding.property.ISimplePropertyListener;
20: import org.eclipse.core.databinding.property.value.IValueProperty;
21: import org.eclipse.core.databinding.property.value.SimpleValueProperty;
22:
23: /**
24: * This class adds support for addressing specific elements of a list by an index to an encapsulated
25: * {@link IValueProperty}.
26: *
27: * @author Lucas Koehler
28: *
29: */
30: public class EMFIndexedValuePropertyDelegator extends SimpleValueProperty {
31:
32:         private final IValueProperty delegate;
33:         private final int index;
34:
35:         /**
36:          * Creates a new instance of {@link EMFIndexedValuePropertyDelegator}.
37:          *
38:          * @param delegate The encapsulated {@link IValueProperty}
39:          * @param index The list index
40:          */
41:         public EMFIndexedValuePropertyDelegator(IValueProperty delegate, int index) {
42:                 this.delegate = delegate;
43:•                if (index < 0) {
44:                         throw new IllegalArgumentException("The list index must not be negative!"); //$NON-NLS-1$
45:                 }
46:                 this.index = index;
47:         }
48:
49:         /**
50:          * {@inheritDoc}
51:          *
52:          * @see org.eclipse.core.databinding.property.value.IValueProperty#getValueType()
53:          */
54:         @Override
55:         public Object getValueType() {
56:                 return delegate.getValueType();
57:         }
58:
59:         /**
60:          * {@inheritDoc}
61:          *
62:          * @see org.eclipse.core.databinding.property.value.SimpleValueProperty#doGetValue(java.lang.Object)
63:          */
64:         @SuppressWarnings("unchecked")
65:         @Override
66:         protected Object doGetValue(Object source) {
67:                 final Object result = delegate.getValue(source);
68:                 final List<Object> list = (List<Object>) result;
69:•                if (list != null && index >= list.size()) {
70:                         return null;
71:                 }
72:                 return list.get(index);
73:         }
74:
75:         /**
76:          * {@inheritDoc}
77:          *
78:          * @see org.eclipse.core.databinding.property.value.SimpleValueProperty#doSetValue(java.lang.Object,
79:          * java.lang.Object)
80:          */
81:         @SuppressWarnings("unchecked")
82:         @Override
83:         protected void doSetValue(Object source, Object value) {
84:                 final Object result = delegate.getValue(source);
85:                 final List<Object> list = (List<Object>) result;
86:                 list.set(index, value);
87:         }
88:
89:         /**
90:          * {@inheritDoc}
91:          *
92:          * @see org.eclipse.core.databinding.property.value.SimpleValueProperty#adaptListener(org.eclipse.core.databinding.property.ISimplePropertyListener)
93:          */
94:         @Override
95:         public INativePropertyListener adaptListener(ISimplePropertyListener listener) {
96:                 // TODO return suitable listener; maybe not needed as some other implementation of SimpleValueProperty return
97:                 // null, too.
98:                 return null;
99:         }
100: }