io.github.albertus82.jface.preference.LocalizedLabelsAndValues Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jface-utils Show documentation
Show all versions of jface-utils Show documentation
Java SWT/JFace Utility Library including a Preferences Framework, Lightweight HTTP Server and macOS support.
package io.github.albertus82.jface.preference;
import java.util.ArrayList;
import java.util.List;
import io.github.albertus82.util.ISupplier;
public class LocalizedLabelsAndValues implements LabelsAndValues {
private final List entries;
public LocalizedLabelsAndValues() {
entries = new ArrayList<>();
}
public LocalizedLabelsAndValues(final int initialCapacity) {
entries = new ArrayList<>(initialCapacity);
}
public LocalizedLabelsAndValues(final ISupplier name, final Object value) {
this(1);
add(name, value);
}
public void add(final ISupplier name, final Object value) {
entries.add(new LabelValue(name, String.valueOf(value)));
}
@Override
public String[][] toArray() {
final String[][] options = new String[entries.size()][2];
int index = 0;
for (final LabelValue entry : entries) {
options[index][0] = entry.key.get();
options[index][1] = entry.value;
index++;
}
return options;
}
@Override
public String toString() {
return entries.toString();
}
private class LabelValue {
private final ISupplier key;
private final String value;
private LabelValue(final ISupplier key, final String value) {
if (key == null) {
throw new NullPointerException("key cannot be null");
}
this.key = key;
this.value = value;
}
@Override
public String toString() {
return key.get() + "=" + value;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy