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

com.regnosys.rosetta.translate.HandlerStackItem Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
package com.regnosys.rosetta.translate;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BinaryOperator;

import com.regnosys.rosetta.common.translation.Path;
import com.regnosys.rosetta.common.translation.Path.PathElement;

/**
 * @author TomForwood
 *         An xml element and a list of handlers that are interested at this point
 */

class HandlerStackItem {

	private final List handlers;
	private final List knownChildren = new ArrayList<>();
	private final Path fullPath;

	HandlerStackItem(List handlers, Path fullPath) {
		this.handlers = handlers;
		this.fullPath = fullPath;
	}

	PathElement addChild(String child, Map metas) {
		Optional last = knownChildren	.stream()
													.filter(pe -> pe.getPathName()
																	.equals(child))
													.reduce(last());
		PathElement newChild = last
									.map(pe -> new PathElement(child, pe.forceGetIndex() + 1, metas))
									.orElse(new PathElement(child, metas));
		knownChildren.add(newChild);
		return newChild;
	}

	List handlers() {
		return handlers;
	}

	Path fullPath() {
		return fullPath;
	}

	HandlerStackItem withNewFullPath() {
		return new HandlerStackItem(handlers, new Path());
	}

	@Override
	public String toString() {
		return "HandlerStackItem [handlers=" + handlers + ", fullPath=" + fullPath + "]";
	}

	private static  BinaryOperator last() {
		return (a, b) -> b;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy