001package org.biopax.paxtools.pattern.constraint; 002 003import org.biopax.paxtools.pattern.Match; 004import org.biopax.paxtools.model.BioPAXElement; 005 006/** 007 * Checks if a variable is a specific type or its subclass. 008 * 009 * @author Ozgun Babur 010 */ 011public class Type extends ConstraintAdapter 012{ 013 /** 014 * Desired class. 015 */ 016 private Class<? extends BioPAXElement> clazz; 017 018 /** 019 * Constructor with the desired class. 020 * @param clazz desired class 021 */ 022 public Type(Class<? extends BioPAXElement> clazz) 023 { 024 super(1); 025 this.clazz = clazz; 026 } 027 028 /** 029 * Checks if the element is assignable to a variable of the desired type. 030 * @param match current pattern match 031 * @param ind mapped indices 032 * @return true if the element is assignable to a variable of the desired type 033 */ 034 @Override 035 public boolean satisfies(Match match, int... ind) 036 { 037 assert ind.length == 1; 038 039 return clazz.isAssignableFrom(match.get(ind[0]).getModelInterface()); 040 } 041}