<commit_before>package sorcer.river;
/**
 *
 * Copyright 2013 <NAME>.
 * Copyright 2013 Sorcersoft.com S.A.
 *
 * 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.
 */


import net.jini.core.lookup.ServiceID;
import net.jini.core.lookup.ServiceItem;
import net.jini.lookup.ServiceItemFilter;

import java.util.ArrayList;
import java.util.List;

/**
 * Basic set of simple {@link ServiceItemFilter}s
 *
 * @author <NAME>
 */
public class Filters {
    private static ServiceItemFilter trueFilter = new AnyFilter();

    private Filters() {
        //static only class
    }

    /**
     * Find first matching {@link ServiceItem}
     *
     * @param items  {@link ServiceItem}s to look in
     * @param filter {@link ServiceItemFilter} to match
     * @return first item matching the filter
     */
    public static ServiceItem firstMatching(ServiceItem[] items, ServiceItemFilter filter) {
        for (ServiceItem item : items) {
            if (filter.check(item)) return item;
        }
        return null;
    }

    /**
     * Find and return all matching service items
     * @param items  {@link ServiceItem}s to look in
     * @param filter {@link ServiceItemFilter} to match
     * @return array of items matching the filter
     */
    public static ServiceItem[] matching(ServiceItem[] items, ServiceItemFilter filter) {
        List<ServiceItem> result = new ArrayList<ServiceItem>(items.length);
        for (ServiceItem item : items) {
            if (filter.check(item)) result.add(item);
        }
        return result.toArray(new ServiceItem[result.size()]);
    }

    /**
     * @return filter that matches any ServiceItem
     */
    public static ServiceItemFilter any() {
        return trueFilter;
    }

    public static ServiceItemFilter and(ServiceItemFilter... filters) {
        assert filters != null;
        return new AndFilter(filters);
    }

    public static ServiceItemFilter or(ServiceItemFilter... filters) {
        assert filters != null;
        return new OrFilter(filters);
    }

    public static ServiceItemFilter not(ServiceItemFilter filter) {
        assert filter != null;
        return new NotFilter(filter);
    }

    public static ServiceItemFilter serviceId(ServiceID serviceID) {
        return new ServiceIDFilter(serviceID);
    }<commit_msg>Allow creating ServiceItemFilter from serviceID String<commit_after>package sorcer.river;
/**
 *
 * Copyright 2013 <NAME>.
 * Copyright 2013 Sorcersoft.com S.A.
 *
 * 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.
 */


import net.jini.core.lookup.ServiceID;
import net.jini.core.lookup.ServiceItem;
import net.jini.lookup.ServiceItemFilter;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * Basic set of simple {@link ServiceItemFilter}s
 *
 * @author <NAME>
 */
public class Filters {
    private static ServiceItemFilter trueFilter = new AnyFilter();

    private Filters() {
        //static only class
    }

    /**
     * Find first matching {@link ServiceItem}
     *
     * @param items  {@link ServiceItem}s to look in
     * @param filter {@link ServiceItemFilter} to match
     * @return first item matching the filter
     */
    public static ServiceItem firstMatching(ServiceItem[] items, ServiceItemFilter filter) {
        for (ServiceItem item : items) {
            if (filter.check(item)) return item;
        }
        return null;
    }

    /**
     * Find and return all matching service items
     * @param items  {@link ServiceItem}s to look in
     * @param filter {@link ServiceItemFilter} to match
     * @return array of items matching the filter
     */
    public static ServiceItem[] matching(ServiceItem[] items, ServiceItemFilter filter) {
        List<ServiceItem> result = new ArrayList<ServiceItem>(items.length);
        for (ServiceItem item : items) {
            if (filter.check(item)) result.add(item);
        }
        return result.toArray(new ServiceItem[result.size()]);
    }

    /**
     * @return filter that matches any ServiceItem
     */
    public static ServiceItemFilter any() {
        return trueFilter;
    }

    public static ServiceItemFilter and(ServiceItemFilter... filters) {
        assert filters != null;
        return new AndFilter(filters);
    }

    public static ServiceItemFilter or(ServiceItemFilter... filters) {
        assert filters != null;
        return new OrFilter(filters);
    }

    public static ServiceItemFilter not(ServiceItemFilter filter) {
        assert filter != null;
        return new NotFilter(filter);
    }

    public static ServiceItemFilter serviceId(ServiceID serviceID) {
        return new ServiceIDFilter(serviceID);
    }

    public static ServiceItemFilter serviceId(String serviceID) {
        UUID uuid = UUID.fromString(serviceID);
        return new ServiceIDFilter(new ServiceID(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()));
    }
{'fraction_non_alphanumeric': 0.0902179422199696, 'fraction_numerical': 0.0040547389761784085, 'mean_word_length': 2.9731543624161074, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5561656', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1534, 'n_words': 542}