001package org.biopax.paxtools.pattern.constraint; 002 003import org.biopax.paxtools.model.BioPAXElement; 004import org.biopax.paxtools.pattern.Match; 005import org.biopax.paxtools.pattern.miner.IDFetcher; 006 007import java.util.Map; 008import java.util.Set; 009 010/** 011 * Checks if the element has a valid ID. 012 * 013 * @author Ozgun Babur 014 */ 015public class HasAnID extends ConstraintAdapter 016{ 017 /** 018 * ID generator object. 019 */ 020 private IDFetcher idFetcher; 021 022 private Map<BioPAXElement, Set<String>> idMap; 023 024 /** 025 * Constructor with the ID fetcher. 026 * @param fetcher ID generator 027 * @param idMap map of IDs 028 */ 029 public HasAnID(IDFetcher fetcher, Map<BioPAXElement, Set<String>> idMap) 030 { 031 this.idFetcher = fetcher; 032 this.idMap = idMap; 033 } 034 035 /** 036 * Returns 1. 037 * @return 1 038 */ 039 @Override 040 public int getVariableSize() 041 { 042 return 1; 043 } 044 045 /** 046 * Checks if the element has one of the desired IDs. 047 * @param match current pattern match 048 * @param ind mapped indices 049 * @return true if the ID is in the list 050 */ 051 @Override 052 public boolean satisfies(Match match, int... ind) 053 { 054 BioPAXElement ele = match.get(ind[0]); 055 if (!idMap.containsKey(ele)) idMap.put(ele, idFetcher.fetchID(ele)); 056 return idMap.get(ele) != null && !idMap.get(ele).isEmpty(); 057 } 058}