001package org.biopax.paxtools.pattern.constraint; 002 003import org.biopax.paxtools.pattern.Match; 004 005import java.util.Set; 006 007/** 008 * Checks if the element has the desired ID. This is a separate class (not reusing FieldConstraint) 009 * because PathAccessor cannot access to RDFIDs. 010 * 011 * @author Ozgun Babur 012 */ 013public class IDConstraint extends ConstraintAdapter 014{ 015 /** 016 * Desired IDs. 017 */ 018 Set<String> ids; 019 020 /** 021 * Constructor with desired IDs. 022 * @param ids desired IDs for valid elements to have 023 */ 024 public IDConstraint(Set<String> ids) 025 { 026 this.ids = ids; 027 } 028 029 /** 030 * Returns 1. 031 * @return 1 032 */ 033 @Override 034 public int getVariableSize() 035 { 036 return 1; 037 } 038 039 /** 040 * Checks if the element has one of the desired IDs. 041 * @param match current pattern match 042 * @param ind mapped indices 043 * @return true if the ID is in the list 044 */ 045 @Override 046 public boolean satisfies(Match match, int... ind) 047 { 048 return ids.contains(match.get(ind[0]).getRDFId()); 049 } 050}