emap                       (__NR_SYSCALL_BASE + 163)
#define __NR_poll                         (__NR_SYSCALL_BASE + 168)
#define __NR_prctl                        (__NR_SYSCALL_BASE + 172)
#define __NR_rt_sigaction                 (__NR_SYSCALL_BASE + 174)
#define __NR_rt_sigprocmask               (__NR_SYSCALL_BASE + 175)
#define __NR_rt_sigtimedwait              (__NR_SYSCALL_BASE + 177)
#define __NR_pread64                      (__NR_SYSCALL_BASE + 180)
#define __NR_pwrite64                     (__NR_SYSCALL_BASE + 181)
#define __NR_getcwd                       (__NR_SYSCALL_BASE + 183)
#define __NR_capget                       (__NR_SYSCALL_BASE + 184)
#define __NR_capset                       (__NR_SYSCALL_BASE + 185)
#define __NR_sigaltstack                  (__NR_SYSCALL_BASE + 186)
#define __NR_sendfile                     (__NR_SYSCALL_BASE + 187)
#define __NR_vfork                        (__NR_SYSCALL_BASE + 190)
#define __NR_ugetrlimit                   (__NR_SYSCALL_BASE + 191)
#define __NR_mmap2                        (__NR_SYSCALL_BASE + 192)
#define __NR_ftruncate64                  (__NR_SYSCALL_BASE + 194)
#define __NR_stat64                       (__NR_SYSCALL_BASE + 195)
#define __NR_lstat64                      (__NR_SYSCALL_BASE + 196)
#define __NR_fstat64                      (__NR_SYSCALL_BASE + 197)
#define __NR_lchown32                     (__NR_SYSCALL_BASE + 198)
#define __NR_getuid32                     (__NR_SYSCALL_BASE + 199)
#define __NR_getgid32                     (__NR_SYSCALL_BASE + 200)
#define __NR_geteuid32                    (__NR_SYSCALL_BASE + 201)
#define __NR_getegid32                    (__NR_SYSCALL_BASE + 202)
#define __NR_setreuid32                   (__NR_SYSCALL_BASE + 203)
#define __NR_setregid32                   (__NR_SYSCALL_BASE + 204)
#define __NR_getgroups32                  (__NR_SYSCALL_BASE + 205)
#define __NR_setgroups32                  (__NR_SYSCALL_BASE + 206)
#define __NR_fchown32                     (__NR_SYSCALL_BASE + 207)
#define __NR_setresuid3/*
 * Copyright 2015 the original author or authors.
 *
 * 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.gradle.model.internal.core;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import org.gradle.model.internal.type.ModelType;

public class ModelNodes {
    public static Predicate<MutableModelNode> all() {
        return Predicates.alwaysTrue();
    }

    public static Predicate<MutableModelNode> withType(Class<?> type) {
        return withType(ModelType.of(type));
    }

    public static Predicate<MutableModelNode> withType(final ModelType<?> type) {
        return withType(type, Predicates.<MutableModelNode>alwaysTrue());
    }

    public static Predicate<MutableModelNode> withType(Class<?> type, Predicate<? super MutableModelNode> predicate) {
        return withType(ModelType.of(type), predicate);
    }

    public static Predicate<MutableModelNode> withType(final ModelType<?> type, final Predicate<? super MutableModelNode> predicate) {
        return new Predicate<MutableModelNode>() {
            @Override
            public boolean apply(MutableModelNode node) {
                node.ensureAtLeast(ModelNode.State.Discovered);
                return node.canBeViewedAs(type) && predicate.apply(node);
            }
        };
    }
}
