com.almworks.jira.structure.api.util.ComparableTuple Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of structure-api Show documentation
Show all versions of structure-api Show documentation
Public API for the Structure Plugin for JIRA
The newest version!
package com.almworks.jira.structure.api.util;
import org.jetbrains.annotations.NotNull;
import java.util.*;
/**
* Comparable tuple is a tuple consisting of numbers and strings, which is compared on per-component order, starting
* with the first element (most significant), down to the last one. It works similar to the string comparison by
* character.
*
* Each pair of elements are compared based on their types. Elements of the same types are compared using their
* standard comparison method. If elements have different types, the numbers come before the strings.
*/
public final class ComparableTuple implements Comparable {
public static final ComparableTuple NIL = new ComparableTuple(new Object[] {});
@NotNull
private final Object[] myValue;
private ComparableTuple(@NotNull Object[] value) {
myValue = value;
}
public static ComparableTuple of(long number) {
return new ComparableTuple(new Object[] { number });
}
public static ComparableTuple of(double number) {
return new ComparableTuple(new Object[] { number });
}
public static ComparableTuple of(String string) {
if (string == null) {
throw new IllegalArgumentException();
}
return new ComparableTuple(new Object[] { string });
}
public static ComparableTuple of(String a, String b) {
if (a == null || b == null) {
throw new IllegalArgumentException();
}
return new ComparableTuple(new Object[] { a, b });
}
public static ComparableTuple of(long a, long b) {
return new ComparableTuple(new Object[] { a, b });
}
public static ComparableTuple of(String[] strings) {
if (strings == null) {
throw new IllegalArgumentException();
}
return new ComparableTuple(Arrays.copyOf(strings, strings.length));
}
public static ComparableTuple of(Long[] longs) {
if (longs == null) {
throw new IllegalArgumentException();
}
return new ComparableTuple(Arrays.copyOf(longs, longs.length));
}
public static ComparableTuple of(String a, long b) {
if (a == null) {
throw new IllegalArgumentException();
}
return new ComparableTuple(new Object[] {a, b});
}
public static ComparableTuple of(String a, long b, String c) {
if (a == null || c == null) {
throw new IllegalArgumentException();
}
return new ComparableTuple(new Object[] {a, b, c});
}
public static ComparableTuple of(List> values) {
if (values == null) {
throw new IllegalArgumentException();
}
List