001/**
002 *  Licensed to the Apache Software Foundation (ASF) under one or more
003 *  contributor license agreements.  See the NOTICE file distributed with
004 *  this work for additional information regarding copyright ownership.
005 *  The ASF licenses this file to You under the Apache License, Version 2.0
006 *  (the "License"); you may not use this file except in compliance with
007 *  the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 *  Unless required by applicable law or agreed to in writing, software
012 *  distributed under the License is distributed on an "AS IS" BASIS,
013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 *  See the License for the specific language governing permissions and
015 *  limitations under the License.
016 */
017package org.apache.isis.core.metamodel.specloader.specimpl;
018
019import com.google.common.base.Predicate;
020
021import org.apache.isis.core.metamodel.spec.feature.Contributed;
022import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
023
024
025/**
026 * Marker interface indicating an a contributed association or action.
027 */
028public interface ContributeeMember {
029    
030    public static class Predicates {
031        
032        private Predicates(){}
033        
034        /**
035         * Evaluates the supplied {@link ObjectMember} and includes either if it is not a {@link ContributeeMember}
036         * (ie is a regular member) or is a {@link ContributeeMember} and contributed are to be
037         * {@link Contributed#isIncluded() included}.  
038         */
039        public static <T extends ObjectMember> Predicate<T> regularElse(final Contributed contributed) {
040            return com.google.common.base.Predicates.or(regular(), is(contributed));
041        }
042        
043        public static <T extends ObjectMember> Predicate<T> regular() {
044            return new Predicate<T>() {
045                @Override
046                public boolean apply(ObjectMember input) {
047                    return !(input instanceof ContributeeMember);
048                }
049            };
050        }
051
052        public static <T extends ObjectMember> Predicate<T> is(final Contributed contributed) {
053            return new Predicate<T>() {
054                @Override
055                public boolean apply(ObjectMember input) {
056                    return input instanceof ContributeeMember && contributed.isIncluded();
057                }
058            };
059        }
060
061    }
062
063}