io.legaldocml.business.builder.HierarchyStrategy Maven / Gradle / Ivy
The newest version!
package io.legaldocml.business.builder;
import com.google.common.collect.ImmutableList;
import io.legaldocml.akn.element.Hierarchy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.function.Supplier;
/**
* @author Jacques Militello
*/
public final class HierarchyStrategy {
/**
* SLF4J Logger.
*/
private static final Logger LOGGER = LoggerFactory.getLogger(HierarchyStrategy.class);
private final ImmutableList> keys;
private final ImmutableList> values;
HierarchyStrategy(ImmutableList> keys, ImmutableList> values) {
this.keys = keys;
this.values = values;
}
@SuppressWarnings("unchecked")
public E next(Hierarchy hierarchy) {
int index = this.keys.indexOf(hierarchy.getClass());
if (index == -1) {
return null;
}
if (index + 1 > this.keys.size()) {
return null;
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("[{}] -> [{}]", hierarchy.getClass().getSimpleName(), this.keys.get(index + 1).getSimpleName());
}
return (E) this.values.get(index + 1).get();
}
}