
br.com.objectos.code.pojo.Pojo Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2015 Objectos, Fábrica de Software LTDA.
*
* 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 br.com.objectos.code.pojo;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import br.com.objectos.code.MethodInfo;
import br.com.objectos.code.ModifierInfo;
import br.com.objectos.code.SimpleTypePrimitives;
import br.com.objectos.code.TypeInfo;
/**
* @author [email protected] (Marcio Endo)
*/
public abstract class Pojo extends Configuration {
protected Pojo(PojoInfo pojoInfo) {
super(pojoInfo);
}
public static Builder builder(TypeInfo typeInfo, PojoConstructor constructor) {
Objects.requireNonNull(typeInfo);
Objects.requireNonNull(constructor);
return new Builder<>(typeInfo, constructor);
}
public static T of(TypeInfo typeInfo, PojoConstructor constructor) {
return of(typeInfo, constructor, m -> true, m -> true);
}
public static T of(
TypeInfo typeInfo,
PojoConstructor constructor,
Predicate pojoMethod,
Predicate builderMethod) {
PojoInfo pojoInfo = PojoInfo.of(typeInfo, pojoMethod, builderMethod);
return constructor.apply(pojoInfo);
}
public static List methodInfoList(TypeInfo typeInfo) {
return methodInfoList(typeInfo, m -> true);
}
public static List methodInfoList(TypeInfo typeInfo, Predicate pojoMethod) {
return typeInfo.methodInfoStream()
.filter(m -> m.hasModifierInfo(ModifierInfo.ABSTRACT))
.filter(m -> !m.hasReturnTypeInfo(SimpleTypePrimitives.VOID))
.filter(m -> m.hasParameterInfoListSize(0))
.filter(pojoMethod)
.collect(Collectors.toList());
}
public static class Builder implements br.com.objectos.core.lang.Builder {
private final TypeInfo typeInfo;
private final PojoConstructor constructor;
private Predicate builderMethod = m -> true;
private Predicate lazyMethod = m -> true;
private Predicate pojoMethod = m -> true;
private Builder(TypeInfo typeInfo,PojoConstructor constructor) {
this.typeInfo = typeInfo;
this.constructor = constructor;
}
@Override
public T build() {
PojoInfo pojoInfo = PojoInfo.builder(typeInfo)
.builderMethod(builderMethod)
.lazyMethod(lazyMethod)
.pojoMethod(pojoMethod)
.build();
return constructor.apply(pojoInfo);
}
public Builder builderMethod(Predicate builderMethod) {
this.builderMethod = Objects.requireNonNull(builderMethod);
return this;
}
public Builder lazyMethod(Predicate lazyMethod) {
this.lazyMethod = Objects.requireNonNull(lazyMethod);
return this;
}
public Builder pojoMethod(Predicate pojoMethod) {
this.pojoMethod = Objects.requireNonNull(pojoMethod);
return this;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy