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

net.amygdalum.util.text.linkeddawg.CharMapFallbackNode Maven / Gradle / Ivy

The newest version!
package net.amygdalum.util.text.linkeddawg;

import net.amygdalum.util.map.CharObjectMap;
import net.amygdalum.util.text.CharFallbackAdaptor;
import net.amygdalum.util.text.CharNode;
import net.amygdalum.util.text.NodeResolver;

public class CharMapFallbackNode  implements CharNode, CharFallbackAdaptor {

	private CharObjectMap> nexts;
	private char[] alts;
	private CharNode fallbackNode;
	private T attached;
	
	private CharMapFallbackNode(CharObjectMap> nexts, char[] alts, T attached) {
		this.nexts = nexts;
		this.alts = alts;
		this.attached = attached;
	}

	public static  CharMapFallbackNode buildNodeFrom(CharNode node, NodeResolver> resolver) {
		char[] alts = node.getAlternatives();
		CharObjectMap> nexts = new CharObjectMap>(null);
		for (char c : alts) {
			nexts.add(c, resolver.resolve(node.nextNode(c)));
		}
		T attached = node.getAttached();
		CharMapFallbackNode buildNode = new CharMapFallbackNode<>(nexts, alts, attached);
		CharNode fallbackNode = CharFallbackAdaptor.getFallback(node);
		if (fallbackNode != null) {
			buildNode.setFallback(fallbackNode);
		}
		return buildNode;
	}

	@Override
	public CharNode nextNode(char c) {
		return nexts.get(c);
	}

	@Override
	public char[] getAlternatives() {
		return alts;
	}
	
	@Override
	public int getAlternativesSize() {
		return alts.length;
	}
	
	@Override
	public T getAttached() {
		return attached;
	}

	@Override
	public void setFallback(CharNode fallbackNode) {
		this.fallbackNode = fallbackNode;
	}
	
	@Override
	public CharNode getFallback() {
		return fallbackNode;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy