
br.com.objectos.code.pojo.PojoInfo 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.AccessInfo;
import br.com.objectos.code.ConstructorInfo;
import br.com.objectos.code.MethodInfo;
import br.com.objectos.code.TypeInfo;
import br.com.objectos.core.auto.AutoPojo;
import br.com.objectos.core.testing.Testable;
/**
* @author [email protected] (Marcio Endo)
*/
@AutoPojo
public abstract class PojoInfo implements Testable {
abstract AccessInfo accessInfo();
abstract Naming naming();
abstract List constructorInfoList();
abstract List attributeMethodList();
abstract List builderMethodList();
abstract List lazyMethodList();
abstract InvalidateMethod invalidate();
abstract IsTestable testable();
PojoInfo() {
}
public static Builder builder(TypeInfo typeInfo) {
Objects.requireNonNull(typeInfo);
return new Builder(typeInfo);
}
public static PojoInfo of(TypeInfo typeInfo) {
return of(typeInfo, m -> true, m -> true);
}
public static PojoInfo of(TypeInfo typeInfo, Predicate pojoMethod, Predicate builderMethod) {
return new Builder(typeInfo)
.pojoMethod(pojoMethod)
.builderMethod(builderMethod)
.build();
}
private static PojoInfoBuilder thisBuilder() {
return new PojoInfoBuilderPojo();
}
BuilderClass toBuilderClass() {
return new BuilderClass(this);
}
BuilderInterface toBuilderInterface() {
return new BuilderInterface(this);
}
PojoClass toPojoClass() {
return new PojoClass(this);
}
public static class Builder implements br.com.objectos.core.lang.Builder {
private final TypeInfo typeInfo;
private Predicate builderMethod = m -> true;
private Predicate lazyMethod = m -> true;
private Predicate pojoMethod = m -> true;
private Builder(TypeInfo typeInfo) {
this.typeInfo = typeInfo;
}
@Override
public PojoInfo build() {
Naming naming = Naming.of(typeInfo);
List methodInfoList = Pojo.methodInfoList(typeInfo, pojoMethod);
return PojoInfo.thisBuilder()
.accessInfo(typeInfo.accessInfo())
.naming(naming)
.constructorInfoList(typeInfo.constructorInfoStream()
.filter(c -> !c.hasAccessInfo(AccessInfo.PRIVATE))
.collect(Collectors.toList()))
.attributeMethodList(methodInfoList.stream()
.map(m -> AttributeMethod.of(naming, m))
.collect(Collectors.toList()))
.builderMethodList(methodInfoList.stream()
.filter(builderMethod)
.map(m -> AttributeMethod.of(naming, m))
.collect(Collectors.toList()))
.lazyMethodList(LazyMethod.of(naming, typeInfo.methodInfoStream().filter(lazyMethod)))
.invalidate(InvalidateMethod.of(typeInfo))
.testable(IsTestable.of(naming, typeInfo))
.build();
}
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