All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.daisy.dotify.cli.BrailleUtilsInfo Maven / Gradle / Ivy

There is a newer version: 3.2.5
Show newest version
package org.daisy.dotify.cli;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.daisy.dotify.api.factory.Factory;
import org.daisy.dotify.api.factory.FactoryCatalog;
import org.daisy.dotify.api.factory.FactoryProperties;
import org.daisy.dotify.api.table.TableCatalog;
import org.daisy.streamline.cli.Definition;
import org.daisy.streamline.cli.ShortFormResolver;

/**
 * Provides lazy loading of braille utils related details
 * @author Joel Håkansson
 *
 */
class BrailleUtilsInfo {
	private ShortFormResolver tableSF;
	private TableCatalog tableCatalog;

	/**
	 * Creates a list of braille tables.
	 * @return returns a list of definitions
	 */
	List getDefinitionList() {
		ShortFormResolver resolver = getShortFormResolver();
		FactoryCatalog catalog = getTableCatalog();
		List ret = new ArrayList<>();
		for (String key : resolver.getShortForms()) {
			ret.add(new Definition(key, catalog.get(resolver.resolve(key)).getDescription()));
		}
		return ret;
	}

	ShortFormResolver getShortFormResolver() {
		if (tableSF==null) {
			Collection idents = new ArrayList();
			for (FactoryProperties p : getTableCatalog().list()) { idents.add(p.getIdentifier()); }
			tableSF = new ShortFormResolver(idents);
		}
		return tableSF;
	}

	private TableCatalog getTableCatalog() {
		if (tableCatalog==null) {
			tableCatalog = TableCatalog.newInstance();
		}
		return tableCatalog;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy