X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Faccessor%2FArrayAccessor.java;fp=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Faccessor%2FArrayAccessor.java;h=df300fbbfb4bdf7fa3d743486a688e828ea79b5a;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/ArrayAccessor.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/ArrayAccessor.java new file mode 100644 index 000000000..df300fbbf --- /dev/null +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/ArrayAccessor.java @@ -0,0 +1,184 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.databoard.accessor; + +import java.util.Collection; + +import org.simantics.databoard.accessor.error.AccessorConstructionException; +import org.simantics.databoard.accessor.error.AccessorException; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.error.BindingException; +import org.simantics.databoard.type.ArrayType; + +public interface ArrayAccessor extends Accessor { + + /** + * Add a new value. + * + * @param binding + * @param value value + * @throws AccessorException + */ + void add(Binding binding, Object value) throws AccessorException; + + /** + * Add an array of elements. + * + * @param binding + * @param values value + * @throws AccessorException + */ + void addAll(Binding binding, Object[] values) throws AccessorException; + + /** + * Add an array of elements. + * + * If elements are inserted in the middle of the array, existing interest sets + * are updated to reflect the new positions. + * + * @param index position to insert new value to + * @param binding + * @param values + * @throws AccessorException + */ + void addAll(int index, Binding binding, Object[] values) throws AccessorException; + + /** + * Insert a new value. + * + * If elements are inserted in the middle of the array, existing interest sets + * are updated to reflect the new positions. + * + * @param index position to insert new value to + * @param binding + * @param value value + * @throws AccessorException + */ + void add(int index, Binding binding, Object value) throws AccessorException; + + /** + * Set all elements from an Array Value. + * + * If array becomes shorter and there are accessors to the removed elements, + * the accessors are invalidated. + * + * @param binding + * @param newValue + * @throws BindingException binding error + * @throws UnsupportedOperationException cannot set a new value + */ + void setValue(Binding binding, Object newValue) throws AccessorException; + + /** + * Replace a value container with a new value. + * + * @param index + * @param binding + * @param value + * @throws AccessorException + */ + void set(int index, Binding binding, Object value) throws AccessorException; + + /** + * Remove an element at an index. + * + * If there are listeners to elements after the index, the + * interest sets and accessor paths are updated and decreased. + * + * If there was an accessor, it becomes invalid. + * + * @param index + * @param count + * @throws AccessorException + */ + void remove(int index, int count) throws AccessorException; + + /** + * Get an accessor to an element. + * The accessor is invalidated if the element is removed from the array. + *

+ * The accessor is not to the index, it is to the element. For instance, you get accessor X of [2] + * then a new value is inserted before 2. The accessor now points to the element at [3]. + * + * @param index + * @return the accessor + * @throws AccessorConstructionException + */ + T getAccessor(int index) throws AccessorConstructionException; + + /** + * Get a copy of the element + * + * @param index + * @param valueBinding + * @return the element + * @throws AccessorException + */ + Object get(int index, Binding valueBinding) throws AccessorException; + + /** + * Read the element to an object + * + * @param index + * @param valueBinding + * @param dest + * @throws AccessorException + */ + void get(int index, Binding valueBinding, Object dest) throws AccessorException; + + /** + * Get all elements and place them to an array. + * Exception is thrown if Array length is too short. + * + * @param valueBinding + * @param array + * @throws AccessorException + */ + void getAll(Binding valueBinding, Object[] array) throws AccessorException; + + /** + * Get all elements + * + * @param valueBinding + * @param values + * @throws AccessorException + */ + void getAll(Binding valueBinding, Collection values) throws AccessorException; + +// /** +// * Get a partial array +// * +// * @param binding +// * @param index +// * @param count +// * @return array +// * @throws AccessorException +// */ +// Object getPartial(ArrayBinding binding, int index, int count) throws AccessorException; + + void setSize(int newSize) throws AccessorException; + + /** + * Return the number of elements in the array. + * + * @return the number of elements + * @throws AccessorException + */ + int size() throws AccessorException; + + ArrayType type(); + + public interface CloseableArrayAccessor extends ArrayAccessor, CloseableAccessor {} + +} + +