@Test public void testCompare() { MetaData metaData1 = mock( MetaData.class ); MetaData metaData2 = mock( MetaData.class ); doReturn( 0 ).when( metaData1 ).getGroupingOrdinal( locale ); doReturn( 1 ).when( metaData2 ).getGroupingOrdinal( locale ); assertThat( comparator.compare( metaData1, metaData2 ), is( equalTo( -1 ) ) ); doReturn( 1 ).when( metaData1 ).getGroupingOrdinal( locale ); doReturn( 0 ).when( metaData2 ).getGroupingOrdinal( locale ); assertThat( comparator.compare( metaData1, metaData2 ), is( equalTo( 1 ) ) ); doReturn( 1 ).when( metaData2 ).getGroupingOrdinal( locale ); doReturn( "1" ).when( metaData1 ).getGrouping( locale ); doReturn( "0" ).when( metaData2 ).getGrouping( locale ); assertThat( comparator.compare( metaData1, metaData2 ), is( equalTo( 1 ) ) ); doReturn( "1" ).when( metaData2 ).getGrouping( locale ); doReturn( 0 ).when( metaData1 ).getItemOrdinal( locale ); doReturn( 1 ).when( metaData2 ).getItemOrdinal( locale ); assertThat( comparator.compare( metaData1, metaData2 ), is( equalTo( -1 ) ) ); doReturn( 1 ).when( metaData1 ).getItemOrdinal( locale ); doReturn( 0 ).when( metaData2 ).getItemOrdinal( locale ); assertThat( comparator.compare( metaData1, metaData2 ), is( equalTo( 1 ) ) ); doReturn( 1 ).when( metaData2 ).getItemOrdinal( locale ); doReturn( null ).when( metaData1 ).getMetaAttribute( "display-name", locale ); doReturn( null ).when( metaData2 ).getMetaAttribute( "display-name", locale ); assertThat( comparator.compare( metaData1, metaData2 ), is( equalTo( 0 ) ) ); doReturn( null ).when( metaData1 ).getMetaAttribute( "display-name", locale ); doReturn( "none" ).when( metaData2 ).getMetaAttribute( "display-name", locale ); assertThat( comparator.compare( metaData1, metaData2 ), is( equalTo( -1 ) ) ); doReturn( "none" ).when( metaData1 ).getMetaAttribute( "display-name", locale ); doReturn( null ).when( metaData2 ).getMetaAttribute( "display-name", locale ); assertThat( comparator.compare( metaData1, metaData2 ), is( equalTo( 1 ) ) ); doReturn( "none" ).when( metaData2 ).getMetaAttribute( "display-name", locale ); assertThat( comparator.compare( metaData1, metaData2 ), is( equalTo( 0 ) ) ); }
public int compare( final MetaData metaData1, final MetaData metaData2 ) { final int groupOrd1 = metaData1.getGroupingOrdinal( locale ); final int groupOrd2 = metaData2.getGroupingOrdinal( locale ); if ( groupOrd1 != groupOrd2 ) { return groupOrd1 < groupOrd2 ? -1 : 1; } final String gr1 = metaData1.getGrouping( locale ); final String gr2 = metaData2.getGrouping( locale ); final int result = gr1.compareTo( gr2 ); if ( result != 0 ) { return result; } final int itemOrd1 = metaData1.getItemOrdinal( locale ); final int itemOrd2 = metaData2.getItemOrdinal( locale ); if ( itemOrd1 != itemOrd2 ) { return itemOrd1 < itemOrd2 ? -1 : 1; } final String dn1 = metaData1.getMetaAttribute( "display-name", locale ); final String dn2 = metaData2.getMetaAttribute( "display-name", locale ); if ( dn1 == null && dn2 == null ) { return 0; } if ( dn1 == null ) { return -1; } if ( dn2 == null ) { return +1; } return dn1.compareTo( dn2 ); }
GroupedMetaDataComparator implements Comparator<MetaData> { public int compare( final MetaData metaData1, final MetaData metaData2 ) { final int groupOrd1 = metaData1.getGroupingOrdinal( locale ); final int groupOrd2 = metaData2.getGroupingOrdinal( locale ); if ( groupOrd1 != groupOrd2 ) { return groupOrd1 < groupOrd2 ? -1 : 1; } final String gr1 = metaData1.getGrouping( locale ); final String gr2 = metaData2.getGrouping( locale ); final int result = gr1.compareTo( gr2 ); if ( result != 0 ) { return result; } final int itemOrd1 = metaData1.getItemOrdinal( locale ); final int itemOrd2 = metaData2.getItemOrdinal( locale ); if ( itemOrd1 != itemOrd2 ) { return itemOrd1 < itemOrd2 ? -1 : 1; } final String dn1 = metaData1.getMetaAttribute( "display-name", locale ); final String dn2 = metaData2.getMetaAttribute( "display-name", locale ); if ( dn1 == null && dn2 == null ) { return 0; } if ( dn1 == null ) { return -1; } if ( dn2 == null ) { return +1; } return dn1.compareTo( dn2 ); } }
GroupedMetaDataComparator implements Comparator<MetaData> { public int compare( final MetaData metaData1, final MetaData metaData2 ) { final int groupOrd1 = metaData1.getGroupingOrdinal( locale ); final int groupOrd2 = metaData2.getGroupingOrdinal( locale ); if ( groupOrd1 != groupOrd2 ) { return groupOrd1 < groupOrd2 ? -1 : 1; } final String gr1 = metaData1.getGrouping( locale ); final String gr2 = metaData2.getGrouping( locale ); final int result = gr1.compareTo( gr2 ); if ( result != 0 ) { return result; } final int itemOrd1 = metaData1.getItemOrdinal( locale ); final int itemOrd2 = metaData2.getItemOrdinal( locale ); if ( itemOrd1 != itemOrd2 ) { return itemOrd1 < itemOrd2 ? -1 : 1; } final String dn1 = metaData1.getMetaAttribute( "display-name", locale ); final String dn2 = metaData2.getMetaAttribute( "display-name", locale ); if ( dn1 == null && dn2 == null ) { return 0; } if ( dn1 == null ) { return -1; } if ( dn2 == null ) { return +1; } return dn1.compareTo( dn2 ); } GroupedMetaDataComparator();  GroupedMetaDataComparator( final Locale locale ); }
GroupedMetaDataComparator implements Comparator<MetaData> { public int compare( final MetaData metaData1, final MetaData metaData2 ) { final int groupOrd1 = metaData1.getGroupingOrdinal( locale ); final int groupOrd2 = metaData2.getGroupingOrdinal( locale ); if ( groupOrd1 != groupOrd2 ) { return groupOrd1 < groupOrd2 ? -1 : 1; } final String gr1 = metaData1.getGrouping( locale ); final String gr2 = metaData2.getGrouping( locale ); final int result = gr1.compareTo( gr2 ); if ( result != 0 ) { return result; } final int itemOrd1 = metaData1.getItemOrdinal( locale ); final int itemOrd2 = metaData2.getItemOrdinal( locale ); if ( itemOrd1 != itemOrd2 ) { return itemOrd1 < itemOrd2 ? -1 : 1; } final String dn1 = metaData1.getMetaAttribute( "display-name", locale ); final String dn2 = metaData2.getMetaAttribute( "display-name", locale ); if ( dn1 == null && dn2 == null ) { return 0; } if ( dn1 == null ) { return -1; } if ( dn2 == null ) { return +1; } return dn1.compareTo( dn2 ); } GroupedMetaDataComparator();  GroupedMetaDataComparator( final Locale locale ); int compare( final MetaData metaData1, final MetaData metaData2 ); }
GroupedMetaDataComparator implements Comparator<MetaData> { public int compare( final MetaData metaData1, final MetaData metaData2 ) { final int groupOrd1 = metaData1.getGroupingOrdinal( locale ); final int groupOrd2 = metaData2.getGroupingOrdinal( locale ); if ( groupOrd1 != groupOrd2 ) { return groupOrd1 < groupOrd2 ? -1 : 1; } final String gr1 = metaData1.getGrouping( locale ); final String gr2 = metaData2.getGrouping( locale ); final int result = gr1.compareTo( gr2 ); if ( result != 0 ) { return result; } final int itemOrd1 = metaData1.getItemOrdinal( locale ); final int itemOrd2 = metaData2.getItemOrdinal( locale ); if ( itemOrd1 != itemOrd2 ) { return itemOrd1 < itemOrd2 ? -1 : 1; } final String dn1 = metaData1.getMetaAttribute( "display-name", locale ); final String dn2 = metaData2.getMetaAttribute( "display-name", locale ); if ( dn1 == null && dn2 == null ) { return 0; } if ( dn1 == null ) { return -1; } if ( dn2 == null ) { return +1; } return dn1.compareTo( dn2 ); } GroupedMetaDataComparator();  GroupedMetaDataComparator( final Locale locale ); int compare( final MetaData metaData1, final MetaData metaData2 ); static final GroupedMetaDataComparator DEFAULT; static final GroupedMetaDataComparator ENGLISH; }