io.kubernetes.client.fluent.BaseFluent Maven / Gradle / Ivy
/*
Copyright 2022 The Kubernetes Authors.
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 io.kubernetes.client.fluent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
public class BaseFluent>
implements io.kubernetes.client.fluent.Fluent, Visitable {
public static final String VISIT = "visit";
public final VisitableMap _visitables = new VisitableMap();
public static VisitableBuilder builderOf(T item) {
if (item instanceof Editable) {
Object editor = ((Editable) item).edit();
if (editor instanceof VisitableBuilder) {
return (VisitableBuilder) editor;
}
}
try {
return (VisitableBuilder)
Class.forName(item.getClass().getName() + "Builder")
.getConstructor(item.getClass())
.newInstance(item);
} catch (Exception e) {
throw new IllegalStateException("Failed to create builder for: " + item.getClass(), e);
}
}
public static List build(
java.util.List extends io.kubernetes.client.fluent.Builder extends T>> list) {
return list == null
? null
: new ArrayList(list.stream().map(Builder::build).collect(Collectors.toList()));
}
public static Set build(
java.util.Set extends io.kubernetes.client.fluent.Builder extends T>> set) {
return set == null
? null
: new LinkedHashSet(set.stream().map(Builder::build).collect(Collectors.toSet()));
}
public static java.util.List aggregate(java.util.List extends T>... lists) {
return new ArrayList(
Arrays.stream(lists).filter(Objects::nonNull).collect(Collectors.toList()));
}
public static java.util.Set aggregate(java.util.Set extends T>... sets) {
return new LinkedHashSet(
Arrays.stream(sets).filter(Objects::nonNull).collect(Collectors.toSet()));
}
public F accept(Visitor... visitors) {
return accept(Collections.emptyList(), visitors);
}
public F accept(Class type, io.kubernetes.client.fluent.Visitor visitor) {
return accept(
Collections.emptyList(),
new Visitor() {
@Override
public Class getType() {
return type;
}
@Override
public void visit(List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy