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

com.softicar.platform.common.container.data.table.in.memory.InMemoryDataTableSorterList Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.container.data.table.in.memory;

import com.softicar.platform.common.container.comparator.OrderDirection;
import com.softicar.platform.common.container.data.table.IDataTableColumn;
import com.softicar.platform.common.container.data.table.IDataTableSorterList;
import com.softicar.platform.common.core.interfaces.INullaryVoidFunction;
import java.util.ArrayList;
import java.util.List;

/**
 * Combined implementation of {@link IInMemoryDataTableSorter} and
 * {@link IDataTableSorterList}.
 *
 * @author Alexander Schmidt
 * @author Oliver Richers
 */
class InMemoryDataTableSorterList implements IInMemoryDataTableSorter, IDataTableSorterList {

	private final INullaryVoidFunction callback;
	private final List> sorters;

	public InMemoryDataTableSorterList(INullaryVoidFunction callback) {

		this.callback = callback;
		this.sorters = new ArrayList<>();
	}

	@Override
	public void clear() {

		sorters.clear();
		callback.apply();
	}

	@Override
	public boolean isEmpty() {

		return sorters.isEmpty();
	}

	@Override
	public void addSorter(IDataTableColumn column, OrderDirection orderDirection) {

		sorters.add(new InMemoryDataTableColumnSorter<>(column, orderDirection));
		callback.apply();
	}

	@Override
	public int compareRows(R leftRow, R rightRow) {

		for (IInMemoryDataTableSorter sorter: sorters) {
			int result = sorter.compareRows(leftRow, rightRow);
			if (result != 0) {
				return result;
			}
		}
		return 0;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy