示例#1
0
  public DatasetScanFilter(List<Selector> selectorGroup) {
    if (selectorGroup == null || selectorGroup.isEmpty()) {
      this.selectorGroup = Collections.emptyList();
      this.containsAtomicIncluders = false;
      this.containsAtomicExcluders = false;
      this.containsCollectionIncluders = false;
      this.containsCollectionExcluders = false;

    } else {
      boolean anyAtomicIncluders = false;
      boolean anyAtomicExcluders = false;
      boolean anyCollectionIncluders = false;
      boolean anyCollectionExcluders = false;
      List<Selector> tmpSelectorGroup = new ArrayList<Selector>();
      for (Selector curSelector : selectorGroup) {
        if (curSelector.isIncluder()) {
          if (curSelector.isApplyToAtomicDataset()) anyAtomicIncluders = true;
          if (curSelector.isApplyToCollectionDataset()) anyCollectionIncluders = true;
        } else { // curSelector.isExcluder()
          if (curSelector.isApplyToAtomicDataset()) anyAtomicExcluders = true;
          if (curSelector.isApplyToCollectionDataset()) anyCollectionExcluders = true;
        }
        tmpSelectorGroup.add(curSelector);
      }

      this.selectorGroup = tmpSelectorGroup;
      this.containsAtomicIncluders = anyAtomicIncluders;
      this.containsAtomicExcluders = anyAtomicExcluders;
      this.containsCollectionIncluders = anyCollectionIncluders;
      this.containsCollectionExcluders = anyCollectionExcluders;
    }
  }
示例#2
0
  public DatasetScanFilter(Selector selector) {
    if (selector == null) {
      this.selectorGroup = Collections.emptyList();
      this.containsAtomicIncluders = false;
      this.containsAtomicExcluders = false;
      this.containsCollectionIncluders = false;
      this.containsCollectionExcluders = false;
    } else {
      boolean anyAtomicIncluders = false;
      boolean anyAtomicExcluders = false;
      boolean anyCollectionIncluders = false;
      boolean anyCollectionExcluders = false;

      if (selector.isIncluder()) {
        if (selector.isApplyToAtomicDataset()) anyAtomicIncluders = true;
        if (selector.isApplyToCollectionDataset()) anyCollectionIncluders = true;
      } else { // curSelector.isExcluder()
        if (selector.isApplyToAtomicDataset()) anyAtomicExcluders = true;
        if (selector.isApplyToCollectionDataset()) anyCollectionExcluders = true;
      }

      this.selectorGroup = Collections.singletonList(selector);
      this.containsAtomicIncluders = anyAtomicIncluders;
      this.containsAtomicExcluders = anyAtomicExcluders;
      this.containsCollectionIncluders = anyCollectionIncluders;
      this.containsCollectionExcluders = anyCollectionExcluders;
    }
  }
示例#3
0
  public boolean accept(MFile dataset) {
    if (dataset == null) return false;

    // If no Selectors, accept all datasets.
    if (this.selectorGroup.isEmpty()) return true;

    if (dataset.isDirectory()) {
      // If no collection selectors, accept all collection datasets.
      if (!this.containsCollectionIncluders && !this.containsCollectionExcluders) return true;
    } else {
      // If no atomic selectors, accept all atomic datasets.
      if (!this.containsAtomicIncluders && !this.containsAtomicExcluders) return true;
    }

    boolean include = false;
    boolean exclude = false;

    for (Selector curSelector : this.selectorGroup) {
      if (curSelector.isApplicable(dataset)) {
        if (curSelector.match(dataset)) {
          if (curSelector.isIncluder()) include = true;
          else exclude = true;
        }
      }
    }

    // Deal with atomic datasets
    if (!dataset.isDirectory()) {
      // If have only inclusion Selectors, accept any dataset that is explicitly included.
      if (this.containsAtomicIncluders && !this.containsAtomicExcluders) return include;

      // If have only exclusion Selectors, accept any dataset not explicitly excluded.
      if (this.containsAtomicExcluders && !this.containsAtomicIncluders) return !exclude;

      // If have both inclusion and exclusion Selectors, accept datasets that are
      // explicitly included but not explicitly excluded.
      if (this.containsAtomicIncluders && this.containsAtomicExcluders && include) return !exclude;
      // Deal with collection datasets
    } else {
      // If have only inclusion Selectors, accept any dataset that is explicitly included.
      if (this.containsCollectionIncluders && !this.containsCollectionExcluders) return include;

      // If have only exclusion Selectors, accept any dataset not explicitly excluded.
      if (this.containsCollectionExcluders && !this.containsCollectionIncluders) return !exclude;

      // If have both inclusion and exclusion Selectors, accept datasets that are
      // explicitly included but not explicitly excluded.
      if (this.containsCollectionIncluders && this.containsCollectionExcluders && include)
        return !exclude;
    }

    // Otherwise, don't accept.
    return false;
  }