
br.com.objectos.way.pojo.plugin.PredicateConfiguration Maven / Gradle / Ivy
/*
* Copyright 2014-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.way.pojo.plugin;
import java.util.Objects;
import br.com.objectos.way.code.Artifact;
import br.com.objectos.way.code.TypeInfo;
/**
* @author [email protected] (Marcio Endo)
*/
class PredicateConfiguration implements Configuration {
private final PojoInfo pojoInfo;
private final PojoClass pojoClass;
private final BuilderConfiguration builder;
private PredicateConfiguration(PojoInfo pojoInfo, PojoClass pojoClass, BuilderConfiguration builder) {
this.pojoInfo = pojoInfo;
this.pojoClass = pojoClass;
this.builder = builder;
}
public static PredicateConfiguration standard(TypeInfo typeInfo) {
return ofMode(Mode.STANDARD, typeInfo);
}
public static PredicateConfiguration pojoOnly(TypeInfo typeInfo) {
return ofMode(Mode.POJO_ONLY, typeInfo);
}
private static PredicateConfiguration ofMode(Mode mode, TypeInfo typeInfo) {
PojoInfo pojoInfo = PojoInfo.of(mode, typeInfo);
return new PredicateConfiguration(
pojoInfo,
PojoClass.of(pojoInfo, typeInfo),
mode.builderConfiguration(typeInfo));
}
public RecordingConfiguration toRecordingConfiguration() {
return new RecordingConfiguration(pojoInfo, builder, pojoClass);
}
@Override
public void execute(ArtifactAction action) {
// noop
}
@Override
public void execute(BuilderPropertyAction action) {
// noop
}
@Override
public void execute(MethodAction action) {
// noop
}
@Override
public void execute(PojoAction action) {
// noop
}
@Override
public Configuration executeWhen(PojoPredicate condition) {
return condition.test(pojoInfo)
? this
: NoopConfiguration.INSTANCE;
}
@Override
public Artifact generate() {
// invalid op
throw new UnsupportedOperationException();
}
@Override
public void generatedBy(Class> generator) {
// noop
}
@Override
public WhenMethod when(MethodPredicate condition) {
return new WhenMethod() {
@Override
public void execute(MethodAction action) {
// noop
}
};
}
@Override
public WhenPojo when(PojoPredicate condition) {
return new WhenPojo() {
@Override
public void execute(WhenPojoAction action) {
// noop
}
};
}
@Override
public final WhenProperty when(PropertyPredicate condition) {
Objects.requireNonNull(condition);
return new InnerWhenProperty(condition);
}
private class InnerWhenProperty implements WhenProperty {
private final PropertyPredicate predicate;
public InnerWhenProperty(PropertyPredicate predicate) {
this.predicate = predicate;
}
@Override
public WhenProperty and(Condition condition) {
return new InnerWhenProperty(predicate.and(condition));
}
@Override
public void execute(BuilderPropertyAction action) {
// noop
}
@Override
public void execute(PojoPropertyAction action) {
// noop
}
@Override
public void ignore() {
builder.addPropertyCondition(predicate);
pojoClass.addPropertyCondition(predicate);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy