agirstatool/src/org/april/agirstatool/core/ProjectComparator.java

158 lines
2.2 KiB
Java

package org.april.agirstatool.core;
import java.util.Comparator;
/**
* The Class ProjectComparator.
*/
public class ProjectComparator implements Comparator<Project>
{
public enum Sorting
{
ID,
IDENTIFIER,
NAME
}
private Sorting sorting;
/**
* Instantiates a new project comparator.
*
* @param sorting
* the sorting
*/
public ProjectComparator(final Sorting sorting)
{
//
this.sorting = sorting;
}
/**
*
*/
@Override
public int compare(final Project alpha, final Project 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 Project alpha, final Project bravo, final Sorting sorting)
{
int result;
if (sorting == null)
{
result = 0;
}
else
{
switch (sorting)
{
case ID:
result = CompareUtils.compare(getId(alpha), getId(bravo));
break;
case IDENTIFIER:
result = CompareUtils.compare(getIdentifier(alpha), getIdentifier(bravo));
break;
case NAME:
default:
result = CompareUtils.compare(getName(alpha), getName(bravo));
}
}
//
return result;
}
/**
* Gets the id.
*
* @param source
* the source
* @return the id
*/
public static Long getId(final Project 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 String getIdentifier(final Project source)
{
String result;
if (source == null)
{
result = null;
}
else
{
result = source.getIdentifier();
}
//
return result;
}
/**
* Gets the name.
*
* @param source
* the source
* @return the name
*/
public static String getName(final Project source)
{
String result;
if (source == null)
{
result = null;
}
else
{
result = source.getName();
}
//
return result;
}
}