org.immutables.value.internal.$processor$.meta.$TelescopicBuild Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of value Show documentation
Show all versions of value Show documentation
Compile time annotations and compile time annotation processor to generate consistent value object using
either abstract class, interface or annotation as a base.
The newest version!
/*
Copyright 2016 Immutables Authors and Contributors
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 org.immutables.value.processor.meta;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import javax.annotation.Nullable;
public final class TelescopicBuild {
public final List stages;
public final List finals;
private TelescopicBuild(List initializers, List nonMandatory) {
this.stages = initializers;
this.finals = nonMandatory;
}
public TelescopicStage firstStage() {
return stages.get(0);
}
static TelescopicBuild from(List attributes) {
List mandatory = Lists.newArrayList();
List finals = Lists.newArrayList();
for (ValueAttribute a : attributes) {
if (a.isBuilderParameter) {
continue;
}
if (a.isMandatory()) {
mandatory.add(a);
} else {
finals.add(a);
}
}
LinkedList stages = Lists.newLinkedList();
if (!mandatory.isEmpty()) {
Collections.reverse(mandatory);
@Nullable TelescopicStage next = null;
for (ValueAttribute m : mandatory) {
next = new TelescopicStage(m, next);
stages.addFirst(next);
}
}
return new TelescopicBuild(stages, finals);
}
public final static class TelescopicStage {
public final ValueAttribute attribute;
public final @Nullable TelescopicStage next;
TelescopicStage(ValueAttribute attribute, @Nullable TelescopicStage next) {
this.attribute = attribute;
this.next = next;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy