blob: 411a56b7edc20cbba24a2acf4f31eb5aa7469e82 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Andras Schmidt, Andras Balogh, Istvan Rath and Daniel Varro
* 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:
* Andras Schmidt, Andras Balogh, Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.core.simple.constraint;
import org.eclipse.viatra2.core.constraint.EConstraint;
import org.eclipse.viatra2.core.constraint.IConstraint;
/**
* Translates old fashioned integer constraint constats to new enumerations.
*
* @author Andras Schmidt
*
*/
public class ConstraintTranslator {
public static EConstraint getConst(int c) {
return EConstraint.values()[c];
}
/**
* Get the old fashion constrait constant
*
* @param c
* constraint type
* @return constraint type in old fashion
*/
public static int getConst(EConstraint c) {
switch (c) {
case BELOW:
return IConstraint.BELOW;
case DINSTANCE:
return IConstraint.DINSTANCE;
case CHILD:
return IConstraint.CHILD;
case DSUBTYPE:
return IConstraint.DSUBTYPE;
case DSUPERTYPE:
return IConstraint.DSUPERTYPE;
case DTYPE:
return IConstraint.DTYPE;
case ENTITY:
return IConstraint.ENTITY;
case ENTITY_REL_FROM:
return IConstraint.REL_FROM;
case ENTITY_REL_TO:
return IConstraint.ENTITY_REL_TO;
case INSTANCE:
return IConstraint.INSTANCE;
case OVER:
return IConstraint.OVER;
case PARENT:
return IConstraint.PARENT;
case REL_FROM:
return IConstraint.REL_FROM;
case REL_TO:
return IConstraint.REL_TO;
case RELATION:
return IConstraint.RELATION;
case SUBTYPE:
return IConstraint.SUBTYPE;
case SUPERTYPE:
return IConstraint.SUPERTYPE;
case TYPE:
return IConstraint.TYPE;
}
return 0;
}
/**
* Get the other side constrait constant
*
* @param c
* constraint type
* @return constraint type from the other side
*/
public static EConstraint getOtherSide(EConstraint c) {
switch (c) {
case BELOW:
return EConstraint.OVER;
case DINSTANCE:
return EConstraint.DTYPE;
case CHILD:
return EConstraint.PARENT;
case DSUBTYPE:
return EConstraint.DSUPERTYPE;
case DSUPERTYPE:
return EConstraint.DSUBTYPE;
case DTYPE:
return EConstraint.DINSTANCE;
case ENTITY:
return EConstraint.ENTITY;
case ENTITY_REL_FROM:
return EConstraint.REL_FROM;
case ENTITY_REL_TO:
return EConstraint.REL_TO;
case INSTANCE:
return EConstraint.TYPE;
case OVER:
return EConstraint.BELOW;
case PARENT:
return EConstraint.CHILD;
case REL_FROM:
return EConstraint.ENTITY_REL_FROM;
case REL_TO:
return EConstraint.ENTITY_REL_TO;
case RELATION:
return EConstraint.RELATION;
case SUBTYPE:
return EConstraint.SUPERTYPE;
case SUPERTYPE:
return EConstraint.SUBTYPE;
case TYPE:
return EConstraint.INSTANCE;
}
return null;
}
int i;
/**
* query if this constraint is "canonical". All types are only "canonical"
* in one direction.
*
* @param c
* constraint type
* @return is canonical
*/
public static boolean isOtherSide(EConstraint c) {
switch (c) {
case BELOW:
case DINSTANCE:
case DSUBTYPE:
case SUBTYPE:
case INSTANCE:
case CHILD:
case ENTITY:
case RELATION:
case REL_FROM:
case REL_TO:
return false;
case DSUPERTYPE:
case DTYPE:
case ENTITY_REL_FROM:
case ENTITY_REL_TO:
case OVER:
case PARENT:
case SUPERTYPE:
case TYPE:
default:
return true;
}
}
}