mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-20 02:09:29 +01:00
Sort keys by age when printing them. Also fix a generics warning.
This commit is contained in:
parent
8936338059
commit
98cc6adfc2
@ -90,9 +90,21 @@ import static com.google.common.base.Preconditions.*;
|
||||
public class ECKey implements EncryptableItem, Serializable {
|
||||
private static final Logger log = LoggerFactory.getLogger(ECKey.class);
|
||||
|
||||
/** Compares pub key bytes using {@link com.google.common.primitives.UnsignedBytes#lexicographicalComparator()} **/
|
||||
/** Sorts oldest keys first, newest last. */
|
||||
public static final Comparator<ECKey> AGE_COMPARATOR = new Comparator<ECKey>() {
|
||||
|
||||
@Override
|
||||
public int compare(ECKey k1, ECKey k2) {
|
||||
if (k1.creationTimeSeconds == k2.creationTimeSeconds)
|
||||
return 0;
|
||||
else
|
||||
return k1.creationTimeSeconds > k2.creationTimeSeconds ? 1 : -1;
|
||||
}
|
||||
};
|
||||
|
||||
/** Compares pub key bytes using {@link com.google.common.primitives.UnsignedBytes#lexicographicalComparator()} */
|
||||
public static final Comparator<ECKey> PUBKEY_COMPARATOR = new Comparator<ECKey>() {
|
||||
private Comparator comparator = UnsignedBytes.lexicographicalComparator();
|
||||
private Comparator<byte[]> comparator = UnsignedBytes.lexicographicalComparator();
|
||||
|
||||
@Override
|
||||
public int compare(ECKey k1, ECKey k2) {
|
||||
|
@ -726,7 +726,9 @@ public class KeyChainGroup implements KeyBag {
|
||||
public String toString(boolean includePrivateKeys) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
if (basic != null) {
|
||||
for (ECKey key : basic.getKeys())
|
||||
List<ECKey> keys = basic.getKeys();
|
||||
Collections.sort(keys, ECKey.AGE_COMPARATOR);
|
||||
for (ECKey key : keys)
|
||||
key.formatKeyWithAddress(includePrivateKeys, builder, params);
|
||||
}
|
||||
List<String> chainStrs = Lists.newLinkedList();
|
||||
|
Loading…
Reference in New Issue
Block a user