com.link_intersystems.dbunit.table.DefaultTableOrder Maven / Gradle / Ivy
package com.link_intersystems.dbunit.table;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static java.util.Objects.requireNonNull;
/**
* @author René Link {@literal }
*/
public class DefaultTableOrder implements TableOrder {
private List tableOrder;
private class TableOrderComparator implements Comparator {
@Override
public int compare(String o1, String o2) {
int o1Index = tableOrder.indexOf(o1);
int o2Index = tableOrder.indexOf(o2);
return o1Index - o2Index;
}
}
private TableOrderComparator tableOrderComparator = new TableOrderComparator();
public DefaultTableOrder(String... tableOrder) {
this(Arrays.asList(tableOrder));
}
public DefaultTableOrder(List tableOrder) {
this.tableOrder = requireNonNull(tableOrder);
}
@Override
public String[] orderTables(String... tableNames) {
List tableNameList = Arrays.asList(tableNames);
tableNameList.sort(tableOrderComparator);
return tableNameList.toArray(new String[0]);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy