![JAR search and dependency download from the Maven repository](/logo.png)
org.apache.bval.jsr.metadata.EmptyBuilder Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.bval.jsr.metadata;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.bval.jsr.groups.GroupConversion;
import org.apache.bval.util.Lazy;
import org.apache.bval.util.ObjectUtils;
import org.apache.bval.util.Validate;
public class EmptyBuilder {
private static final Map INSTANCES = new EnumMap<>(AnnotationBehavior.class);
public static EmptyBuilder instance() {
return instance(AnnotationBehavior.ABSTAIN);
}
public static EmptyBuilder instance(AnnotationBehavior annotationBehavior) {
return INSTANCES.computeIfAbsent(annotationBehavior, EmptyBuilder::new);
}
private class Level implements HasAnnotationBehavior {
@Override
public final AnnotationBehavior getAnnotationBehavior() {
return annotationBehavior;
}
}
private class ForBean extends Level implements MetadataBuilder.ForBean {
@SuppressWarnings("rawtypes")
private final Lazy forClass = new Lazy<>(EmptyBuilder.ForClass::new);
@SuppressWarnings("unchecked")
@Override
public MetadataBuilder.ForClass getClass(Meta> meta) {
return forClass.get();
}
@Override
public Map> getFields(Meta> meta) {
return Collections.emptyMap();
}
@Override
public Map> getGetters(Meta> meta) {
return Collections.emptyMap();
}
@Override
public Map>> getConstructors(Meta> meta) {
return Collections.emptyMap();
}
@Override
public Map> getMethods(Meta> meta) {
return Collections.emptyMap();
}
@Override
public boolean isEmpty() {
return true;
}
}
private class ForElement extends Level implements MetadataBuilder.ForElement {
@Override
public final Annotation[] getDeclaredConstraints(Meta meta) {
return ObjectUtils.EMPTY_ANNOTATION_ARRAY;
}
}
private class ForClass extends ForElement> implements MetadataBuilder.ForClass {
@Override
public List> getGroupSequence(Meta> meta) {
return null;
}
}
private class ForContainer extends ForElement
implements MetadataBuilder.ForContainer {
@Override
public boolean isCascade(Meta meta) {
return false;
}
@Override
public Set getGroupConversions(Meta meta) {
return Collections.emptySet();
}
@Override
public Map> getContainerElementTypes(
Meta meta) {
return Collections.emptyMap();
}
}
private class ForExecutable extends Level implements MetadataBuilder.ForExecutable {
@SuppressWarnings("unchecked")
@Override
public MetadataBuilder.ForElement getCrossParameter(Meta meta) {
return forElement.get();
}
@Override
public List> getParameters(Meta meta) {
return Collections.emptyList();
}
@SuppressWarnings("unchecked")
@Override
public MetadataBuilder.ForContainer getReturnValue(Meta meta) {
return forContainer.get();
}
}
private final AnnotationBehavior annotationBehavior;
@SuppressWarnings("rawtypes")
private final Lazy forBean;
@SuppressWarnings("rawtypes")
private final Lazy forContainer;
@SuppressWarnings("rawtypes")
private final Lazy forExecutable;
@SuppressWarnings("rawtypes")
private final Lazy forElement;
private EmptyBuilder(AnnotationBehavior annotationBehavior) {
super();
this.annotationBehavior = Validate.notNull(annotationBehavior, "annotationBehavior");
forBean = new Lazy<>(EmptyBuilder.ForBean::new);
forContainer = new Lazy<>(EmptyBuilder.ForContainer::new);
forExecutable = new Lazy<>(EmptyBuilder.ForExecutable::new);
forElement = new Lazy<>(EmptyBuilder.ForElement::new);
}
@SuppressWarnings("unchecked")
public MetadataBuilder.ForBean forBean() {
return forBean.get();
}
@SuppressWarnings("unchecked")
public MetadataBuilder.ForContainer forContainer() {
return forContainer.get();
}
@SuppressWarnings("unchecked")
public MetadataBuilder.ForExecutable forExecutable() {
return forExecutable.get();
}
@SuppressWarnings("unchecked")
public MetadataBuilder.ForElement forElement() {
return forElement.get();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy