001 /*--------------------------------------------------------------------------+
002 $Id: StateflowDeclContainerBase.java 26285 2010-02-18 11:22:54Z juergens $
003 | |
004 | Copyright 2005-2010 Technische Universitaet Muenchen |
005 | |
006 | Licensed under the Apache License, Version 2.0 (the "License"); |
007 | you may not use this file except in compliance with the License. |
008 | You may obtain a copy of the License at |
009 | |
010 | http://www.apache.org/licenses/LICENSE-2.0 |
011 | |
012 | Unless required by applicable law or agreed to in writing, software |
013 | distributed under the License is distributed on an "AS IS" BASIS, |
014 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
015 | See the License for the specific language governing permissions and |
016 | limitations under the License. |
017 +--------------------------------------------------------------------------*/
018 package edu.tum.cs.simulink.model.stateflow;
019
020 import edu.tum.cs.commons.assertion.CCSMPre;
021 import edu.tum.cs.commons.collections.CollectionUtils;
022 import edu.tum.cs.commons.collections.IdentityHashSet;
023 import edu.tum.cs.commons.collections.UnmodifiableSet;
024
025 /**
026 * Base class for classes that contain Stateflow declarations.
027 *
028 * @param
029 * <P>
030 * Type of the parent of this node.
031 *
032 * @author deissenb
033 * @author $Author: juergens $
034 * @version $Rev: 26285 $
035 * @levd.rating GREEN Hash: 3EE8464273E894EAEFF063776FC39642
036 */
037 public abstract class StateflowDeclContainerBase<P extends IStateflowElement<?>>
038 extends StateflowElementBase<P> {
039
040 /** Set of Stateflow dates. */
041 private final IdentityHashSet<StateflowData> dates = new IdentityHashSet<StateflowData>();
042
043 /** Set of Stateflow events. */
044 private final IdentityHashSet<StateflowEvent> events = new IdentityHashSet<StateflowEvent>();
045
046 /** Create new declaration container. */
047 /* package */StateflowDeclContainerBase() {
048 super();
049 }
050
051 /** Copy constructor for deep cloning. */
052 /* package */StateflowDeclContainerBase(
053 StateflowDeclContainerBase<? extends P> orig) {
054 super(orig);
055
056 for (StateflowData data : orig.dates) {
057 addData(data.deepClone());
058 }
059
060 for (StateflowEvent event : orig.events) {
061 addEvent(event.deepClone());
062 }
063 }
064
065 /** Add Stateflow data. */
066 public void addData(StateflowData data) {
067 dates.add(data);
068 data.setParent(this);
069 }
070
071 /** Add Stateflow event. */
072 public void addEvent(StateflowEvent event) {
073 events.add(event);
074 event.setParent(this);
075 }
076
077 /** Get Stateflow data objects. */
078 public UnmodifiableSet<StateflowData> getData() {
079 return CollectionUtils.asUnmodifiable(dates);
080 }
081
082 /** Get Stateflow events objects. */
083 public UnmodifiableSet<StateflowEvent> getEvents() {
084 return CollectionUtils.asUnmodifiable(events);
085 }
086
087 /** Remove Stateflow data object. */
088 /* package */void removeData(StateflowData data) {
089 CCSMPre.isTrue(data.getParent() == this,
090 "Data object must belong to container to be removed.");
091 dates.remove(data);
092 data.setParent(null);
093 }
094
095 /** Remove Stateflow event object. */
096 /* package */void removeEvent(StateflowEvent event) {
097 CCSMPre.isTrue(event.getParent() == this,
098 "Event must belong to container to be removed.");
099 events.remove(event);
100 event.setParent(null);
101 }
102 }