Autopsy  4.4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CompoundFilter.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-16 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.timeline.filters;
20 
21 import java.util.List;
22 import java.util.Objects;
23 import javafx.collections.FXCollections;
24 import javafx.collections.ListChangeListener;
25 import javafx.collections.ObservableList;
26 
36 public abstract class CompoundFilter<SubFilterType extends Filter> extends AbstractFilter {
37 
41  private final ObservableList<SubFilterType> subFilters = FXCollections.observableArrayList();
42 
43  public final ObservableList<SubFilterType> getSubFilters() {
44  return subFilters;
45  }
46 
52  public CompoundFilter(List<SubFilterType> subFilters) {
53  super();
54 
55  //listen to changes in list of subfilters
56  this.subFilters.addListener((ListChangeListener.Change<? extends SubFilterType> change) -> {
57  while (change.next()) {
58  //add a listener to the selected property of each added subfilter
59  change.getAddedSubList().forEach(addedSubFilter -> {
60  //if a subfilter's selected property changes...
61  addedSubFilter.selectedProperty().addListener(selectedProperty -> {
62  //set this compound filter selected af any of the subfilters are selected.
63  setSelected(getSubFilters().parallelStream().anyMatch(Filter::isSelected));
64  });
65  });
66  }
67  });
68 
69  this.subFilters.setAll(subFilters);
70  }
71 
72  static <SubFilterType extends Filter> boolean areSubFiltersEqual(final CompoundFilter<SubFilterType> oneFilter, final CompoundFilter<SubFilterType> otherFilter) {
73  if (oneFilter.getSubFilters().size() != otherFilter.getSubFilters().size()) {
74  return false;
75  }
76  for (int i = 0; i < oneFilter.getSubFilters().size(); i++) {
77  final SubFilterType subFilter = oneFilter.getSubFilters().get(i);
78  final SubFilterType otherSubFilter = otherFilter.getSubFilters().get(i);
79  if (subFilter.equals(otherSubFilter) == false) {
80  return false;
81  }
82  }
83  return true;
84  }
85 
86  @Override
87  public int hashCode() {
88  int hash = 3;
89  hash = 61 * hash + Objects.hashCode(this.subFilters);
90  return hash;
91  }
92 }
final ObservableList< SubFilterType > getSubFilters()
CompoundFilter(List< SubFilterType > subFilters)
final ObservableList< SubFilterType > subFilters

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.