blob: 281b9d1aab2ae75b6cb5f664afcd6fb3973e5565 [file] [log] [blame]
package org.eclipse.stem.core.predicate.impl;
/*******************************************************************************
* Copyright (c) 2008 IBM Corporation and others.
* 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.stem.core.graph.Graph;
import org.eclipse.stem.core.model.STEMTime;
import org.eclipse.stem.core.predicate.Predicate;
import org.eclipse.stem.core.predicate.PredicateExpression;
import org.eclipse.stem.core.predicate.PredicatePackage;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Expression</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link org.eclipse.stem.core.predicate.impl.PredicateExpressionImpl#getPredicate <em>Predicate</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public class PredicateExpressionImpl extends BooleanExpressionImpl implements PredicateExpression {
/**
* The cached value of the '{@link #getPredicate() <em>Predicate</em>}' containment reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getPredicate()
* @generated
* @ordered
*/
protected Predicate predicate;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected PredicateExpressionImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return PredicatePackage.Literals.PREDICATE_EXPRESSION;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Predicate getPredicate() {
return predicate;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetPredicate(Predicate newPredicate, NotificationChain msgs) {
Predicate oldPredicate = predicate;
predicate = newPredicate;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, PredicatePackage.PREDICATE_EXPRESSION__PREDICATE, oldPredicate, newPredicate);
if (msgs == null) msgs = notification; else msgs.add(notification);
}
return msgs;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setPredicate(Predicate newPredicate) {
if (newPredicate != predicate) {
NotificationChain msgs = null;
if (predicate != null)
msgs = ((InternalEObject)predicate).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - PredicatePackage.PREDICATE_EXPRESSION__PREDICATE, null, msgs);
if (newPredicate != null)
msgs = ((InternalEObject)newPredicate).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - PredicatePackage.PREDICATE_EXPRESSION__PREDICATE, null, msgs);
msgs = basicSetPredicate(newPredicate, msgs);
if (msgs != null) msgs.dispatch();
}
else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, PredicatePackage.PREDICATE_EXPRESSION__PREDICATE, newPredicate, newPredicate));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
switch (featureID) {
case PredicatePackage.PREDICATE_EXPRESSION__PREDICATE:
return basicSetPredicate(null, msgs);
}
return super.eInverseRemove(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case PredicatePackage.PREDICATE_EXPRESSION__PREDICATE:
return getPredicate();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case PredicatePackage.PREDICATE_EXPRESSION__PREDICATE:
setPredicate((Predicate)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case PredicatePackage.PREDICATE_EXPRESSION__PREDICATE:
setPredicate((Predicate)null);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case PredicatePackage.PREDICATE_EXPRESSION__PREDICATE:
return predicate != null;
}
return super.eIsSet(featureID);
}
/**
* @see org.eclipse.stem.core.predicate.impl.PredicateImpl#evaluate(org.eclipse.stem.core.model.STEMTime, long, org.eclipse.stem.core.model.Decorator)
*/
@Override
public boolean evaluate(STEMTime time, long timerPeriod, Graph graph) {
try {
return getPredicate().evaluate(time, timerPeriod, graph);
} catch (Exception e) {
return false;
}
}
} //PredicateExpressionImpl