org.simpleflatmapper.jdbc.impl.JdbcColumnKeyMapperKeyComparator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-jdbc Show documentation
Show all versions of sfm-jdbc Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
The newest version!
package org.simpleflatmapper.jdbc.impl;
import org.simpleflatmapper.jdbc.JdbcColumnKey;
import org.simpleflatmapper.map.mapper.MapperKey;
import org.simpleflatmapper.map.mapper.MapperKeyComparator;
public final class JdbcColumnKeyMapperKeyComparator extends MapperKeyComparator {
public final static JdbcColumnKeyMapperKeyComparator INSTANCE = new JdbcColumnKeyMapperKeyComparator();
private JdbcColumnKeyMapperKeyComparator() {
}
@Override
public int compare(MapperKey m1, MapperKey m2) {
JdbcColumnKey[] keys1 = m1.getColumns();
JdbcColumnKey[] keys2 = m2.getColumns();
int d = keys1.length - keys2.length;
if (d != 0) {
return d;
}
return compareKeys(keys1, keys2);
}
private int compareKeys(JdbcColumnKey[] keys1, JdbcColumnKey[] keys2) {
for (int i = 0; i < keys1.length; i++) {
int d = compare(keys1[i], keys2[i]);
if (d != 0) {
return d;
}
}
return 0;
}
protected int compare(JdbcColumnKey k1, JdbcColumnKey k2) {
int d = k1.getIndex() - k2.getIndex();
if (d != 0) return d;
d = k1.getName().compareTo(k2.getName());
if (d != 0) return d;
return k1.getSqlType(null) - k2.getSqlType(null);
}
}