From 19688656134b288fd981730544dde303c9c3afd9 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 14 Aug 2015 15:31:12 +0200 Subject: Thrift api changes --- .../java/org/openslx/thrifthelper/Comparators.java | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/main/java/org/openslx/thrifthelper/Comparators.java (limited to 'src/main/java/org/openslx/thrifthelper/Comparators.java') diff --git a/src/main/java/org/openslx/thrifthelper/Comparators.java b/src/main/java/org/openslx/thrifthelper/Comparators.java new file mode 100644 index 0000000..5580cf6 --- /dev/null +++ b/src/main/java/org/openslx/thrifthelper/Comparators.java @@ -0,0 +1,78 @@ +package org.openslx.thrifthelper; + +import java.util.Comparator; + +import org.openslx.bwlp.thrift.iface.ImageSummaryRead; +import org.openslx.bwlp.thrift.iface.ImageVersionDetails; +import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.bwlp.thrift.iface.Organization; +import org.openslx.bwlp.thrift.iface.Virtualizer; + +/** + * A bunch of comparators for thrift classes. They will compare on what would be considered the + * identifier ("primary key") of a struct, unless stated otherwise. + */ +public class Comparators +{ + + public static final Comparator imageVersionDetails = new Comparator() { + @Override + public int compare( ImageVersionDetails o1, ImageVersionDetails o2 ) + { + if ( o1 == null || o1.versionId == null ) + return o2 == null || o2.versionId == null ? 0 : 1; + if ( o2 == null || o2.versionId == null ) + return -1; + return o1.versionId.compareTo( o2.versionId ); + } + }; + + public static final Comparator imageSummaryRead = new Comparator() { + @Override + public int compare( ImageSummaryRead o1, ImageSummaryRead o2 ) + { + if ( o1 == null || o1.imageBaseId == null ) + return o2 == null || o2.imageBaseId == null ? 0 : 1; + if ( o2 == null || o2.imageBaseId == null ) + return -1; + return o1.imageBaseId.compareTo( o2.imageBaseId ); + } + }; + + public static final Comparator operatingSystem = new Comparator() { + @Override + public int compare( OperatingSystem o1, OperatingSystem o2 ) + { + if ( o1 == null ) + return o2 == null ? 0 : 1; + if ( o2 == null ) + return -1; + return o1.osId - o2.osId; + } + }; + + public static final Comparator virtualizer = new Comparator() { + @Override + public int compare( Virtualizer o1, Virtualizer o2 ) + { + if ( o1 == null || o1.virtId == null ) + return o2 == null || o2.virtId == null ? 0 : 1; + if ( o2 == null || o2.virtId == null ) + return -1; + return o1.virtId.compareTo( o2.virtId ); + } + }; + + public static final Comparator organization = new Comparator() { + @Override + public int compare( Organization o1, Organization o2 ) + { + if ( o1 == null || o1.organizationId == null ) + return o2 == null || o2.organizationId == null ? 0 : 1; + if ( o2 == null || o2.organizationId == null ) + return -1; + return o1.organizationId.compareTo( o2.organizationId ); + } + }; + +} -- cgit v1.2.3-55-g7522