/*
 * Autopsy Forensic Browser
 *
 * Copyright 2015 Basis Technology Corp.
 * Contact: carrier <at> sleuthkit <dot> org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sleuthkit.autopsy.timeline.filters;

import java.util.stream.Collectors;

/**
 * union of {@link DataSourceFilter}s
 */
public class DataSourcesFilter extends UnionFilter {

    @Override
    public DataSourcesFilter copyOf() {
        //make a nonrecursive copy of this filter
        final DataSourcesFilter filterCopy = new DataSourcesFilter();
        filterCopy.setActive(isActive());
        filterCopy.setDisabled(isDisabled());
        //add a copy of each subfilter
        this.getSubFilters().forEach((Filter t) -> {
            filterCopy.addDataSourceFilter((DataSourceFilter) t.copyOf());
        });

        return filterCopy;
    }

    @Override
    public String getDisplayName() {
        return "Data Source";
    }

    @Override
    public String getHTMLReportString() {
        String string = getDisplayName();
        if (getSubFilters().isEmpty() == false) {
            string = string + " : " + getSubFilters().stream().filter(Filter::isActive).map(Filter::getHTMLReportString).collect(Collectors.joining("</li><li>", "<ul><li>", "</li></ul>")); // NON-NLS
        }
        return string;
    }

    public void addDataSourceFilter(DataSourceFilter dataSourceFilter) {
        if (getSubFilters().stream().map(DataSourceFilter.class::cast)
                .map(DataSourceFilter::getDataSourceID)
                .filter(t -> t == dataSourceFilter.getDataSourceID())
                .findAny().isPresent() == false) {
            getSubFilters().add(dataSourceFilter);
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final DataSourcesFilter other = (DataSourcesFilter) obj;

        if (isActive() != other.isActive()) {
            return false;
        }

        return hashEqualSubFilters(this, other);

    }

    @Override
    public int hashCode() {
        return 9;
    }

}

@@ -1521,16 +1521,38 @@
 ayName()
+ + getStringCheckBox()
 ;%0A      

fix "report" checkbox