/******************************************************************************* * 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.interestset; import java.util.Map; import org.simantics.databoard.annotations.Optional; import org.simantics.databoard.type.ArrayType; /** * Interest set of an Array Type. * * @see ArrayType * @author Toni Kalajainen */ public class ArrayInterestSet extends InterestSet { public static final ArrayInterestSet MONITOR_EVERYTHING = new ArrayInterestSet(true, null, true, null, null, null); // Notifications /** Interested in notification of element assignments, add and removal (excludes the value) */ public boolean notification; /** Interested in notifications to elements by index, (excludes the value). Sorted array of indices. */ public @Optional int[] notifications; // Value Assignments /** Interested in all notification and value assignments */ public boolean value; /** Interested in values by element (includes change). Sorted array of indices */ public @Optional int[] values; // Content /** Component Interest of the contents of values. Incl. interest in change and value. null if no interest. */ public @Optional InterestSet componentInterest; /** Component Interests of the contents of values of specific elements (incl. interest in change and value), null if no interest. */ public @Optional Map componentInterests; // TODO Make TreeMap /** * Create an array interest set * * @param notification interested in add, remove and change to assignment of all elements * @param specificNotifications interested in add, remove and change to assignment of all specific elements * @param values interested in add, remove and change to assignment of all elements, incl. new values * @param specificValues interested in add, remove and change to assignment of all specific elements, incl. new values * @param componentInterest Interest of the changes of values and their sub-value changes of all elements * @param componentInterests Interest of the changes of values and their sub-value changes of specific elements */ public ArrayInterestSet(boolean notification, int[] specificNotifications, boolean values, int[] specificValues, InterestSet componentInterest, Map componentInterests) { this.notification = notification; this.notifications = specificNotifications; this.value = values; this.values = specificValues; this.componentInterest = componentInterest; this.componentInterests = componentInterests; } /** * Returns true, if interested in element assignment, add, removal. * This excludes interest in the new values. * * @return true if interested in notifications */ public boolean inNotifications() { return notification | value | (componentInterest!=null); } /** * Returns true, if interested in assignment of the element at specific index * * @param elementIndex * @return true if interested in notifications of a specific element */ public boolean inNotificationsOf(int elementIndex) { if (notification || value) return true; if (notifications!=null) { for (int i=0; iindex. * * @param elementIndex * @return true if interested in the values of a specific element */ public boolean inValuesOf(int elementIndex) { if (value | componentInterest!=null) return true; if (values!=null) { for (int i=0; inull */ public InterestSet getComponentInterest() { return componentInterest; } /** * Get composite interest of component value of element at index * * @param index element index * @return composite interest set or null */ public InterestSet getComponentInterest(int index) { if (componentInterests==null) return null; return componentInterests.get(index); } }