72 lines
1.4 KiB
Java
72 lines
1.4 KiB
Java
package org.lucares.pdbui;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.List;
|
|
|
|
import org.lucares.collections.LongList;
|
|
|
|
final class LongPair implements Comparable<LongPair> {
|
|
private final long a, b;
|
|
|
|
public LongPair(final long a, final long b) {
|
|
super();
|
|
this.a = a;
|
|
this.b = b;
|
|
}
|
|
|
|
public static List<LongPair> fromLongList(final LongList longList) {
|
|
final List<LongPair> result = new ArrayList<>();
|
|
for (int i = 0; i < longList.size(); i += 2) {
|
|
|
|
result.add(new LongPair(longList.get(i), longList.get(i + 1)));
|
|
|
|
}
|
|
Collections.sort(result);
|
|
return result;
|
|
}
|
|
|
|
public long getA() {
|
|
return a;
|
|
}
|
|
|
|
public long getB() {
|
|
return b;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return a + "," + b;
|
|
}
|
|
|
|
@Override
|
|
public int compareTo(final LongPair o) {
|
|
return Comparator.comparing(LongPair::getA).thenComparing(LongPair::getB).compare(this, o);
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
final int prime = 31;
|
|
int result = 1;
|
|
result = prime * result + (int) (a ^ (a >>> 32));
|
|
result = prime * result + (int) (b ^ (b >>> 32));
|
|
return result;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(final Object obj) {
|
|
if (this == obj)
|
|
return true;
|
|
if (obj == null)
|
|
return false;
|
|
if (getClass() != obj.getClass())
|
|
return false;
|
|
final LongPair other = (LongPair) obj;
|
|
if (a != other.a)
|
|
return false;
|
|
if (b != other.b)
|
|
return false;
|
|
return true;
|
|
}
|
|
} |