1 /*******************************************************************************
2 * Copyright (c) 2010 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.databoard.accessor;
14 import java.util.Collection;
16 import org.simantics.databoard.accessor.error.AccessorConstructionException;
17 import org.simantics.databoard.accessor.error.AccessorException;
18 import org.simantics.databoard.binding.Binding;
19 import org.simantics.databoard.binding.error.BindingException;
20 import org.simantics.databoard.type.ArrayType;
22 public interface ArrayAccessor extends Accessor {
29 * @throws AccessorException
31 void add(Binding binding, Object value) throws AccessorException;
34 * Add an array of elements.
38 * @throws AccessorException
40 void addAll(Binding binding, Object[] values) throws AccessorException;
43 * Add an array of elements.
45 * If elements are inserted in the middle of the array, existing interest sets
46 * are updated to reflect the new positions.
48 * @param index position to insert new value to
51 * @throws AccessorException
53 void addAll(int index, Binding binding, Object[] values) throws AccessorException;
58 * If elements are inserted in the middle of the array, existing interest sets
59 * are updated to reflect the new positions.
61 * @param index position to insert new value to
64 * @throws AccessorException
66 void add(int index, Binding binding, Object value) throws AccessorException;
69 * Set all elements from an Array Value.
71 * If array becomes shorter and there are accessors to the removed elements,
72 * the accessors are invalidated.
76 * @throws BindingException binding error
77 * @throws UnsupportedOperationException cannot set a new value
79 void setValue(Binding binding, Object newValue) throws AccessorException;
82 * Replace a value container with a new value.
87 * @throws AccessorException
89 void set(int index, Binding binding, Object value) throws AccessorException;
92 * Remove an element at an index.
94 * If there are listeners to elements after the <code>index</code>, the
95 * interest sets and accessor paths are updated and decreased.
97 * If there was an accessor, it becomes invalid.
101 * @throws AccessorException
103 void remove(int index, int count) throws AccessorException;
106 * Get an accessor to an element.
107 * The accessor is invalidated if the element is removed from the array.
109 * The accessor is not to the index, it is to the element. For instance, you get accessor X of [2]
110 * then a new value is inserted before 2. The accessor now points to the element at [3].
113 * @return the accessor
114 * @throws AccessorConstructionException
116 <T extends Accessor> T getAccessor(int index) throws AccessorConstructionException;
119 * Get a copy of the element
122 * @param valueBinding
123 * @return the element
124 * @throws AccessorException
126 Object get(int index, Binding valueBinding) throws AccessorException;
129 * Read the element to an object
132 * @param valueBinding
134 * @throws AccessorException
136 void get(int index, Binding valueBinding, Object dest) throws AccessorException;
139 * Get all elements and place them to an <code>array</code>.
140 * Exception is thrown if Array length is too short.
142 * @param valueBinding
144 * @throws AccessorException
146 void getAll(Binding valueBinding, Object[] array) throws AccessorException;
151 * @param valueBinding
153 * @throws AccessorException
155 void getAll(Binding valueBinding, Collection<Object> values) throws AccessorException;
158 // * Get a partial array
164 // * @throws AccessorException
166 // Object getPartial(ArrayBinding binding, int index, int count) throws AccessorException;
168 void setSize(int newSize) throws AccessorException;
171 * Return the number of elements in the array.
173 * @return the number of elements
174 * @throws AccessorException
176 int size() throws AccessorException;
180 public interface CloseableArrayAccessor extends ArrayAccessor, CloseableAccessor {}