package com.capgemini.framework.teamcenter.resolution.filtering;

import java.util.Arrays;

/** Include objects according to their type. */
public class TcTypeInclusionFilter implements ITcTypeFilter {

    private final String[] allowedObjects;

    /**
     * Builds a {@link ITcTypeFilter} that will ALLOW any object of the provided type.
     * 
     * @param allowedObjects the object types to be included
     */
    public TcTypeInclusionFilter(final String... allowedObjects) {
        this.allowedObjects = allowedObjects;
        Arrays.sort(allowedObjects);
    }

    @Override
    public boolean isExcluded(final String type) {
        return !isIncluded(type);
    }

    @Override
    public boolean isIncluded(final String type) {
        return Arrays.binarySearch(allowedObjects, type) >= 0;
    }

}
