001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*- 002 * 003 * Copyright © 2024 microBean™. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 006 * the License. You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 011 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 012 * specific language governing permissions and limitations under the License. 013 */ 014package org.microbean.bean; 015 016import java.util.Collection; 017import java.util.Objects; 018 019import javax.lang.model.type.TypeMirror; 020 021import org.microbean.qualifier.NamedAttributeMap; 022 023public final class IdMatcher implements Matcher<AttributedType, Id> { 024 025 private final QualifiersMatcher qm; 026 027 private final InterceptorBindingsMatcher ibm; 028 029 private final TypeMatcher tm; 030 031 public IdMatcher(final QualifiersMatcher qm, 032 final InterceptorBindingsMatcher ibm, 033 final TypeMatcher tm) { 034 super(); 035 this.qm = Objects.requireNonNull(qm, "qm"); 036 this.ibm = Objects.requireNonNull(ibm, "ibm"); 037 this.tm = Objects.requireNonNull(tm, "tm"); 038 } 039 040 @Override // Matcher<AttributedType, Id> (BiPredicate<AttributedType, Id>) 041 public final boolean test(final AttributedType t, final Id id) { 042 final Collection<? extends NamedAttributeMap<?>> attributes = t.attributes(); 043 final Collection<? extends NamedAttributeMap<?>> idAttributes = id.attributes(); 044 return 045 this.qm.test(attributes, idAttributes) && 046 this.ibm.test(attributes, idAttributes) && 047 this.test(t.type(), id.types()); 048 } 049 050 public final boolean test(final TypeMirror type, final Iterable<? extends TypeMirror> ts) { 051 for (final TypeMirror t : ts) { 052 if (this.tm.test(type, t)) { 053 return true; 054 } 055 } 056 return false; 057 } 058 059}