objectos.way.CssProperties Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of objectos.way Show documentation
Show all versions of objectos.way Show documentation
Objectos Way allows you to build full-stack web applications using only Java.
The newest version!
/*
* Copyright (C) 2023-2024 Objectos 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 objectos.way;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
final class CssProperties implements Iterable> {
static final class Builder {
private final List> values = Util.createList();
public final void add(String key, String value) {
Entry entry;
entry = Map.entry(key, value);
values.add(entry);
}
public final CssProperties build() {
if (values.isEmpty()) {
throw new IllegalArgumentException("Empty");
}
return new CssProperties(
Util.toUnmodifiableList(values)
);
}
}
public static final CssProperties NOOP = new CssProperties(List.of());
private final List> values;
private CssProperties(List> values) {
this.values = values;
}
public static CssProperties of(String key, String value) {
Map.Entry property;
property = Map.entry(key, value);
List> values;
values = List.of(property);
return new CssProperties(values);
}
public final Iterable> entries() {
return values;
}
public final Map.Entry get(int index) {
return values.get(index);
}
@Override
public final Iterator> iterator() {
return values.iterator();
}
@SuppressWarnings({"rawtypes", "unchecked"})
public final Map toMap() {
Map.Entry[] entries;
entries = values.toArray(Map.Entry[]::new);
return Map.ofEntries(entries);
}
public final Map toMap(Map more) {
Map map;
map = Util.createMap();
for (Map.Entry entry : values) {
map.put(
entry.getKey(),
entry.getValue()
);
}
map.putAll(more);
return Util.toUnmodifiableMap(map);
}
public final Map toMap(CssProperties extension) {
Map map;
map = Util.createMap();
for (Map.Entry entry : values) {
map.put(
entry.getKey(),
entry.getValue()
);
}
for (Map.Entry entry : extension.values) {
map.put(
entry.getKey(),
entry.getValue()
);
}
return Util.toUnmodifiableMap(map);
}
public final int size() {
return values.size();
}
}