
fr.vergne.translation.impl.LoadedMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of translation-core Show documentation
Show all versions of translation-core Show documentation
Basic features to support a translation project.
The newest version!
package fr.vergne.translation.impl;
import java.util.Iterator;
import java.util.List;
import fr.vergne.translation.TranslationEntry;
import fr.vergne.translation.TranslationMap;
import fr.vergne.translation.util.Writer;
/**
* A {@link LoadedMap} provides the basic features to manage a
* {@link TranslationMap} for which we already have the entries.
*
* @author Matthieu VERGNE
*
* @param
*/
public class LoadedMap> implements
TranslationMap {
private static final Writer> DEFAULT_SAVER = new Writer>>() {
@Override
public void write(LoadedMap extends TranslationEntry>> map) {
for (TranslationEntry> entry : map.entries) {
entry.saveAll();
}
}
};
private final List entries;
private final Writer super LoadedMap> mapSaver;
/**
* Instantiate a {@link LoadedMap} which should manage a known list of
* {@link TranslationEntry}s. The overall saving strategy is dedicated to a
* specific {@link Writer}.
*
* @param entries
* the list of {@link TranslationEntry} of this
* {@link TranslationMap}
* @param mapSaver
* the {@link Writer} to use for {@link #saveAll()}
*/
public LoadedMap(List entries,
Writer super LoadedMap> mapSaver) {
this.entries = entries;
this.mapSaver = mapSaver;
}
/**
* Instantiate a {@link LoadedMap} which should manage a known list of
* {@link TranslationEntry}s. The overall saving strategy is a naive one:
* each {@link TranslationEntry} is saved separately, one after the other.
* If you want a smarter saving strategy, use
* {@link #FixedListMap(List, Writer)} instead.
*
* @param entries
* the list of {@link TranslationEntry} of this
* {@link TranslationMap}
*/
public LoadedMap(List entries) {
this(entries, DEFAULT_SAVER);
}
@Override
public Iterator iterator() {
return entries.iterator();
}
@Override
public Entry getEntry(int index) {
return entries.get(index);
}
@Override
public int size() {
return entries.size();
}
@Override
public void saveAll() {
mapSaver.write(this);
}
@Override
public void resetAll() {
for (Entry entry : entries) {
entry.resetAll();
}
}
@Override
public String toString() {
return "Map(" + size() + " entries)";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy