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

com.xlrit.gears.engine.choice.TupleSelection Maven / Gradle / Ivy

package com.xlrit.gears.engine.choice;

import java.util.List;

import com.xlrit.gears.base.choice.Choice;
import com.xlrit.gears.base.choice.DefaultChoice;
import com.xlrit.gears.engine.meta.Property;
import jakarta.persistence.Tuple;

class TupleSelection implements Selection {
	private static final String DOT_ID = ".id";

	private final String element;
	private final String id;
	private final String label;

	TupleSelection(String elementSelectClause, String idSelectClause, String labelSelectClause) {
		this.element = elementSelectClause;
		this.id = idSelectClause;
		this.label = labelSelectClause;
	}

	TupleSelection(String elementSelectClause, String labelSelectClause) {
		this(elementSelectClause, elementSelectClause + ".id", labelSelectClause);
	}

	TupleSelection(String elementSelectClause, Property displayedProperty) {
		this(elementSelectClause, elementSelectClause + DOT_ID, elementSelectClause + "." + displayedProperty.getName());
	}

	@Override
	public Class resultClass() {
		return Tuple.class;
	}

	@Override
	public Choice toChoice(Tuple tuple) {
		return DefaultChoice.of(tuple.get(0, String.class), tuple.get(1, String.class));
	}

	@Override
	public String forElement() {
		return element;
	}

	@Override
	public String forId() {
		return id;
	}

	@Override
	public String forItem() {
		return id + ", " + label;
	}

	@Override
	public List searchFields() {
		return List.of(label);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy