io.deephaven.appmode.Fields Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-application-mode Show documentation
Show all versions of deephaven-application-mode Show documentation
The 'application-mode' project
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.appmode;
import io.deephaven.annotations.BuildableStyle;
import org.immutables.value.Value.Check;
import org.immutables.value.Value.Immutable;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Spliterator;
import java.util.function.Consumer;
@Immutable
@BuildableStyle
public abstract class Fields implements Iterable> {
public static Builder builder() {
return ImmutableFields.builder();
}
public static Fields of(Field>... fields) {
return builder().addFields(fields).build();
}
public static Fields of(Collection> fields) {
return builder().addAllFields(fields).build();
}
abstract Map> fields();
public final int size() {
return fields().size();
}
@Override
public final Iterator> iterator() {
return fields().values().iterator();
}
@Override
public final void forEach(Consumer super Field>> action) {
fields().values().forEach(action);
}
@Override
public final Spliterator> spliterator() {
return fields().values().spliterator();
}
public interface Builder {
Builder putFields(String key, Field> value);
default Builder addFields(Field> field) {
return putFields(field.name(), field);
}
default Builder addFields(Field>... fields) {
for (Field> field : fields) {
addFields(field);
}
return this;
}
default Builder addAllFields(Collection> fields) {
for (Field> field : fields) {
addFields(field);
}
return this;
}
Fields build();
}
@Check
final void checkKeys() {
for (Entry> e : fields().entrySet()) {
if (!e.getKey().equals(e.getValue().name())) {
throw new IllegalArgumentException("field name must be used as the key");
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy