00001 package edu.rice.cs.hpc.data.experiment.extdata; 00002 00003 import java.util.ArrayList; 00004 00005 public class FilterSet { 00006 private ArrayList<Filter> patterns; 00007 private boolean excludeMatched; //i.e. do we hide traces that match the pattern 00008 00009 public FilterSet() { 00010 // default is to hide the matching processes 00011 excludeMatched = true; 00012 patterns = new ArrayList<Filter>(); 00013 } 00014 boolean hasAnyFilters() { 00015 return patterns != null && !patterns.isEmpty(); 00016 } 00017 public void setPatterns(ArrayList<Filter> patterns) { 00018 this.patterns = patterns; 00019 } 00020 00021 public void setShowMode(boolean toShow) { 00022 excludeMatched = !toShow; 00023 } 00024 00025 public boolean isShownMode() { 00026 return !excludeMatched; 00027 } 00028 //TODO: We should probably use TraceName instead 00029 public boolean includes(String name){ 00030 String[] split = name.split("\\."); 00031 int process = Integer.parseInt(split[0]); 00032 int thread = 0; 00033 if (split.length > 1) { 00034 thread = Integer.parseInt(split[1]); 00035 } 00036 return include(new TraceName(process, thread)); 00037 } 00038 00039 public ArrayList<Filter> getPatterns() 00040 { 00041 return patterns; 00042 } 00043 public boolean include(TraceName traceName) { 00044 boolean matchedSoFar = true; 00045 /* 00046 * We think about it as applying each filter to the results of the 00047 * filter before. This is logically the same as requiring a rank to 00048 * match every filter (AND, though sometimes it is more intuitive as the 00049 * OR equation provided by De Morgan's law). Also, if excludeMatched is 00050 * true, we need to NOT the matches. This is the same as XORing with 00051 * excludeMatched 00052 */ 00053 for (Filter filter : patterns) { 00054 matchedSoFar &= (filter.matches(traceName.process, traceName.thread)^excludeMatched); 00055 } 00056 return matchedSoFar; 00057 } 00058 } 00059