Skip to content
Snippets Groups Projects
Commit 51724cee authored by ribeaudc's avatar ribeaudc
Browse files

fix: - Bug in sorting by Group (it did not implement the Comparable interface).

SVN: 9042
parent cee3849e
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package ch.systemsx.cisd.openbis.generic.client.web.client.dto; package ch.systemsx.cisd.openbis.generic.client.web.client.dto;
import java.util.Comparator;
import com.google.gwt.user.client.rpc.IsSerializable; import com.google.gwt.user.client.rpc.IsSerializable;
/** /**
...@@ -25,6 +27,9 @@ import com.google.gwt.user.client.rpc.IsSerializable; ...@@ -25,6 +27,9 @@ import com.google.gwt.user.client.rpc.IsSerializable;
*/ */
public class Code<T extends Code<T>> implements IsSerializable, ICodeProvider, Comparable<T> public class Code<T extends Code<T>> implements IsSerializable, ICodeProvider, Comparable<T>
{ {
public final static Comparator<ICodeProvider> CODE_PROVIDER_COMPARATOR =
new CodeProviderComparator();
private String code; private String code;
public final void setCode(final String code) public final void setCode(final String code)
...@@ -45,17 +50,37 @@ public class Code<T extends Code<T>> implements IsSerializable, ICodeProvider, C ...@@ -45,17 +50,37 @@ public class Code<T extends Code<T>> implements IsSerializable, ICodeProvider, C
// Comparable // Comparable
// //
public int compareTo(final T o) public final int compareTo(final T o)
{ {
final String thatCode = o.code; return CODE_PROVIDER_COMPARATOR.compare(this, o);
if (code == null) }
{
return thatCode == null ? 0 : -1; //
} // Helper classes
if (thatCode == null) //
public final static class CodeProviderComparator implements Comparator<ICodeProvider>
{
//
// Comparable
//
public int compare(final ICodeProvider o1, final ICodeProvider o2)
{ {
return 1; assert o1 != null : "Unspecified code provider.";
assert o2 != null : "Unspecified code provider.";
final String thisCode = o1.getCode();
final String thatCode = o2.getCode();
if (thisCode == null)
{
return thatCode == null ? 0 : -1;
}
if (thatCode == null)
{
return 1;
}
return thisCode.compareTo(thatCode);
} }
return code.compareTo(thatCode);
} }
} }
...@@ -21,7 +21,8 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.dto; ...@@ -21,7 +21,8 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.dto;
* *
* @author Christian Ribeaud * @author Christian Ribeaud
*/ */
public class CodeWithRegistration extends AbstractRegistrationHolder implements ICodeProvider public class CodeWithRegistration<T extends CodeWithRegistration<T>> extends
AbstractRegistrationHolder implements ICodeProvider, Comparable<T>
{ {
private String code; private String code;
...@@ -38,4 +39,13 @@ public class CodeWithRegistration extends AbstractRegistrationHolder implements ...@@ -38,4 +39,13 @@ public class CodeWithRegistration extends AbstractRegistrationHolder implements
{ {
return code; return code;
} }
//
// Comparable
//
public int compareTo(final T o)
{
return Code.CODE_PROVIDER_COMPARATOR.compare(this, o);
}
} }
...@@ -23,7 +23,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; ...@@ -23,7 +23,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE;
* *
* @author Tomasz Pylak * @author Tomasz Pylak
*/ */
public class Experiment extends CodeWithRegistration implements Comparable<Experiment> public class Experiment extends CodeWithRegistration<Experiment>
{ {
private Project project; private Project project;
...@@ -65,6 +65,7 @@ public class Experiment extends CodeWithRegistration implements Comparable<Exper ...@@ -65,6 +65,7 @@ public class Experiment extends CodeWithRegistration implements Comparable<Exper
// Comparable // Comparable
// //
@Override
public final int compareTo(final Experiment o) public final int compareTo(final Experiment o)
{ {
return getExperimentIdentifier().compareTo(o.getExperimentIdentifier()); return getExperimentIdentifier().compareTo(o.getExperimentIdentifier());
......
...@@ -23,7 +23,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE; ...@@ -23,7 +23,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE;
* *
* @author Christian Ribeaud * @author Christian Ribeaud
*/ */
public class ExternalData extends CodeWithRegistration public class ExternalData extends CodeWithRegistration<ExternalData>
{ {
private String location; private String location;
......
...@@ -23,7 +23,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.GroupPE; ...@@ -23,7 +23,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.GroupPE;
* *
* @author Franz-Josef Elmer * @author Franz-Josef Elmer
*/ */
public final class Group extends CodeWithRegistration public final class Group extends CodeWithRegistration<Group>
{ {
private String description; private String description;
......
...@@ -26,7 +26,7 @@ import ch.systemsx.cisd.common.annotation.CollectionMapping; ...@@ -26,7 +26,7 @@ import ch.systemsx.cisd.common.annotation.CollectionMapping;
* *
* @author Izabela Adamczyk * @author Izabela Adamczyk
*/ */
public final class Sample extends CodeWithRegistration implements IInvalidationProvider, public final class Sample extends CodeWithRegistration<Sample> implements IInvalidationProvider,
Comparable<Sample> Comparable<Sample>
{ {
public static final Sample[] EMPTY_ARRAY = new Sample[0]; public static final Sample[] EMPTY_ARRAY = new Sample[0];
...@@ -145,6 +145,7 @@ public final class Sample extends CodeWithRegistration implements IInvalidationP ...@@ -145,6 +145,7 @@ public final class Sample extends CodeWithRegistration implements IInvalidationP
// Comparable // Comparable
// //
@Override
public final int compareTo(final Sample o) public final int compareTo(final Sample o)
{ {
return getSampleIdentifier().compareTo(o.getSampleIdentifier()); return getSampleIdentifier().compareTo(o.getSampleIdentifier());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment