/* * Copyright (C) 2009 The Android Open Source Project * * 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 com.android.mkstubs; import java.util.TreeSet; /** * A "filter" holds the various patterns that MkStubs should accept (include) * or reject (exclude). Patterns can be of two kind: * *

* The {@link #accept(String)} method examines a given string against the known * pattern to decide if it should be included. */ class Filter { private TreeSet mIncludePrefix = new TreeSet(); private TreeSet mIncludeFull = new TreeSet(); private TreeSet mExcludePrefix = new TreeSet(); private TreeSet mExcludeFull = new TreeSet(); /** * Returns the set of all full patterns to be included. */ public TreeSet getIncludeFull() { return mIncludeFull; } /** * Returns the set of all prefix patterns to be included. */ public TreeSet getIncludePrefix() { return mIncludePrefix; } /** * Returns the set of all full patterns to be excluded. */ public TreeSet getExcludeFull() { return mExcludeFull; } /** * Returns the set of all prefix patterns to be excluded. */ public TreeSet getExcludePrefix() { return mExcludePrefix; } /** * Checks if the given string passes the various include/exclude rules. * The matching is done as follows: *

* @param s The string to accept or reject. * @return True if the string can be accepted, false if it must be rejected. */ public boolean accept(String s) { // Check if it can be included. boolean accept = mIncludeFull.contains(s); if (!accept) { // Check for a prefix inclusion for (String prefix : mIncludePrefix) { if (s.startsWith(prefix)) { accept = true; break; } } } if (accept) { // check for a full exclusion accept = !mExcludeFull.contains(s); } if (accept) { // or check for prefix exclusion for (String prefix : mExcludePrefix) { if (s.startsWith(prefix)) { accept = false; break; } } } return accept; } }