189 lines
2.7 KiB
Java
189 lines
2.7 KiB
Java
package org.april.agirstatool.core;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.Comparator;
|
|
|
|
/**
|
|
* The Class ProjectComparator.
|
|
*/
|
|
public class IssueComparator implements Comparator<Issue>
|
|
{
|
|
public enum Sorting
|
|
{
|
|
ID,
|
|
PROJECTID,
|
|
CREATEDON,
|
|
CLOSEDON
|
|
}
|
|
|
|
private Sorting sorting;
|
|
|
|
/**
|
|
* Instantiates a new project comparator.
|
|
*
|
|
* @param sorting
|
|
* the sorting
|
|
*/
|
|
public IssueComparator(final Sorting sorting)
|
|
{
|
|
//
|
|
this.sorting = sorting;
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
@Override
|
|
public int compare(final Issue alpha, final Issue bravo)
|
|
{
|
|
int result;
|
|
|
|
result = compare(alpha, bravo, this.sorting);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Compare.
|
|
*
|
|
* @param alpha
|
|
* the alpha
|
|
* @param bravo
|
|
* the bravo
|
|
* @param sorting
|
|
* the sorting
|
|
* @return the int
|
|
*/
|
|
public static int compare(final Issue alpha, final Issue bravo, final Sorting sorting)
|
|
{
|
|
int result;
|
|
|
|
if (sorting == null)
|
|
{
|
|
result = 0;
|
|
}
|
|
else
|
|
{
|
|
switch (sorting)
|
|
{
|
|
default:
|
|
case ID:
|
|
result = CompareUtils.compare(getId(alpha), getId(bravo));
|
|
break;
|
|
|
|
case PROJECTID:
|
|
result = CompareUtils.compare(getProjectId(alpha), getProjectId(bravo));
|
|
break;
|
|
|
|
case CREATEDON:
|
|
result = CompareUtils.compare(getCreatedOn(alpha), getCreatedOn(bravo));
|
|
break;
|
|
|
|
case CLOSEDON:
|
|
result = CompareUtils.compare(getClosedOn(alpha), getClosedOn(bravo));
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the closed on.
|
|
*
|
|
* @param source
|
|
* the source
|
|
* @return the closed on
|
|
*/
|
|
public static LocalDateTime getClosedOn(final Issue source)
|
|
{
|
|
LocalDateTime result;
|
|
|
|
if (source == null)
|
|
{
|
|
result = null;
|
|
}
|
|
else
|
|
{
|
|
result = source.getClosedOn();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the created on.
|
|
*
|
|
* @param source
|
|
* the source
|
|
* @return the created on
|
|
*/
|
|
public static LocalDateTime getCreatedOn(final Issue source)
|
|
{
|
|
LocalDateTime result;
|
|
|
|
if (source == null)
|
|
{
|
|
result = null;
|
|
}
|
|
else
|
|
{
|
|
result = source.getCreatedOn();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the id.
|
|
*
|
|
* @param source
|
|
* the source
|
|
* @return the id
|
|
*/
|
|
public static Long getId(final Issue source)
|
|
{
|
|
Long result;
|
|
|
|
if (source == null)
|
|
{
|
|
result = null;
|
|
}
|
|
else
|
|
{
|
|
result = source.getId();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the identifier.
|
|
*
|
|
* @param source
|
|
* the source
|
|
* @return the identifier
|
|
*/
|
|
public static Long getProjectId(final Issue source)
|
|
{
|
|
Long result;
|
|
|
|
if (source == null)
|
|
{
|
|
result = null;
|
|
}
|
|
else
|
|
{
|
|
result = source.getProjectId();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|