Dashboard extends BaseNameableObject implements MetadataObject { public boolean moveItem( String uid, int position ) { if ( items == null || position < 0 || position > items.size() ) { return false; } int index = items.indexOf( new DashboardItem( uid ) ); if ( index == -1 || index == position || (index + 1) == position ) { return false; } DashboardItem item = items.get( index ); index = position < index ? (index + 1) : index; items.add( position, item ); items.remove( index ); return true; } Dashboard();  Dashboard( String name ); boolean moveItem( String uid, int position ); DashboardItem getItemByUid( String uid ); DashboardItem getAvailableItemByType( DashboardItemType type ); boolean hasItems(); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) int getItemCount(); @JsonProperty( "dashboardItems" ) @JsonSerialize( contentAs = BaseIdentifiableObject.class ) @JacksonXmlElementWrapper( localName = "dashboardItems", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "dashboardItem", namespace = DxfNamespaces.DXF_2_0 ) List<DashboardItem> getItems(); void setItems( List<DashboardItem> items ); static final int MAX_ITEMS; }
@Test public void testMoveItem() { Dashboard dashboard = new Dashboard(); DashboardItem diA = new DashboardItem(); DashboardItem diB = new DashboardItem(); DashboardItem diC = new DashboardItem(); DashboardItem diD = new DashboardItem(); diA.setUid( "A" ); diB.setUid( "B" ); diC.setUid( "C" ); diD.setUid( "D" ); dashboard.getItems().add( diA ); dashboard.getItems().add( diB ); dashboard.getItems().add( diC ); dashboard.getItems().add( diD ); assertEquals( 4, dashboard.getItems().size() ); assertEquals( 2, dashboard.getItems().indexOf( diC ) ); assertTrue( dashboard.moveItem( "B", 3 ) ); assertEquals( 4, dashboard.getItems().size() ); assertEquals( 0, dashboard.getItems().indexOf( diA ) ); assertEquals( 1, dashboard.getItems().indexOf( diC ) ); assertEquals( 2, dashboard.getItems().indexOf( diB ) ); assertEquals( 3, dashboard.getItems().indexOf( diD ) ); assertTrue( dashboard.moveItem( "C", 4 ) ); assertEquals( 0, dashboard.getItems().indexOf( diA ) ); assertEquals( 1, dashboard.getItems().indexOf( diB ) ); assertEquals( 2, dashboard.getItems().indexOf( diD ) ); assertEquals( 3, dashboard.getItems().indexOf( diC ) ); assertTrue( dashboard.moveItem( "D", 1 ) ); assertEquals( 0, dashboard.getItems().indexOf( diA ) ); assertEquals( 1, dashboard.getItems().indexOf( diD ) ); assertEquals( 2, dashboard.getItems().indexOf( diB ) ); assertEquals( 3, dashboard.getItems().indexOf( diC ) ); assertTrue( dashboard.moveItem( "C", 0 ) ); assertEquals( 0, dashboard.getItems().indexOf( diC ) ); assertEquals( 1, dashboard.getItems().indexOf( diA ) ); assertEquals( 2, dashboard.getItems().indexOf( diD ) ); assertEquals( 3, dashboard.getItems().indexOf( diB ) ); assertFalse( dashboard.moveItem( "C", 5 ) ); assertFalse( dashboard.moveItem( "A", 1 ) ); assertFalse( dashboard.moveItem( "A", 2 ) ); }