[ https://java.net/jira/browse/GLAZEDLISTS-576?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=387572#comment-387572 ] reden edited comment on GLAZEDLISTS-576 at 6/12/15 9:31 PM: ------------------------------------------------------------ Unit tests which highlight the issue: {code:java} /** * Test event blocks in a manner similar to * {@link #testListEventRemoveAllContiguousBlocks()}, but where blocks are formed * not by duplicate items, but rather by matching different items sequentially. */ @Test public void testListEventRemoveAllContiguousDistinctBlocks() { final EventList<String> list = GlazedLists.eventListOf( "A", "B", "C", "D", "E", "F" ); list.addListEventListener( new ListEventListener<String>() { @Override public void listChanged( ListEvent<String> event ) { assertTrue( event.nextBlock() ); assertEquals( 0, event.getBlockStartIndex() ); assertEquals( 1, event.getBlockEndIndex() ); assertTrue( event.nextBlock() ); assertEquals( 2, event.getBlockStartIndex() ); assertEquals( 3, event.getBlockEndIndex() ); assertFalse( event.nextBlock() ); } } ); list.removeAll( GlazedLists.eventListOf( "A", "B", "E", "F" ) ); } /** * Test event blocks by clearing a list and checking for a single event. */ @Test public void testListEventClear() { final EventList<String> list = GlazedLists.eventListOf( "A", "B", "C", "D", "E", "F" ); list.addListEventListener( new ListEventListener<String>() { @Override public void listChanged( ListEvent<String> event ) { assertTrue( event.nextBlock() ); assertEquals( 0, event.getBlockStartIndex() ); assertEquals( 4, event.getBlockEndIndex() ); assertFalse( event.nextBlock() ); } } ); list.clear(); } /** * Test event blocks by adding a block of values which are sequential in position * but different in value. */ @Test public void testListEventAddContiguous() { final EventList<String> list = GlazedLists.eventListOf( "A", "B", "C", "D", "E", "F" ); list.addListEventListener( new ListEventListener<String>() { @Override public void listChanged( ListEvent<String> listChanges ) { System.out.println( listChanges ); } } ); list.addListEventListener( new ListEventListener<String>() { @Override public void listChanged( ListEvent<String> event ) { assertTrue( event.nextBlock() ); assertEquals( 0, event.getBlockStartIndex() ); assertEquals( 4, event.getBlockEndIndex() ); assertFalse( event.nextBlock() ); } } ); list.addAll( Arrays.asList( "G", "H", "I", "J" ) ); } {code} was (Author: reden): Unit tests which highlight the issue: {code:java} /** * Test event blocks in a manner similar to * {@link #testListEventRemoveAllContiguousBlocks()}, but where blocks are formed * not by duplicate items, but rather by matching different items sequentially. */ @Test public void testListEventRemoveAllContiguousDistinctBlocks() { final EventList<String> list = GlazedLists.eventListOf( "A", "B", "C", "D", "E", "F" ); list.addListEventListener( new ListEventListener<String>() { @Override public void listChanged( ListEvent<String> event ) { assertTrue( event.nextBlock() ); assertEquals( 0, event.getBlockStartIndex() ); assertEquals( 1, event.getBlockEndIndex() ); assertTrue( event.nextBlock() ); assertEquals( 2, event.getBlockStartIndex() ); assertEquals( 3, event.getBlockEndIndex() ); assertFalse( event.nextBlock() ); } } ); list.removeAll( GlazedLists.eventListOf( "A", "B", "E", "F" ) ); } /** * Test event blocks in a manner similar to * {@link #testListEventRemoveAllContiguousBlocks()}, but where blocks are formed * not by duplicate items, but rather by matching different items sequentially. */ @Test public void testListEventClear() { final EventList<String> list = GlazedLists.eventListOf( "A", "B", "C", "D", "E", "F" ); list.addListEventListener( new ListEventListener<String>() { @Override public void listChanged( ListEvent<String> event ) { assertTrue( event.nextBlock() ); assertEquals( 0, event.getBlockStartIndex() ); assertEquals( 4, event.getBlockEndIndex() ); assertFalse( event.nextBlock() ); } } ); list.clear(); } /** * Test event blocks in a manner similar to * {@link #testListEventRemoveAllContiguousBlocks()}, but where blocks are formed * not by duplicate items, but rather by matching different items sequentially. */ @Test public void testListEventAddContiguous() { final EventList<String> list = GlazedLists.eventListOf( "A", "B", "C", "D", "E", "F" ); list.addListEventListener( new ListEventListener<String>() { @Override public void listChanged( ListEvent<String> listChanges ) { System.out.println( listChanges ); } } ); list.addListEventListener( new ListEventListener<String>() { @Override public void listChanged( ListEvent<String> event ) { assertTrue( event.nextBlock() ); assertEquals( 0, event.getBlockStartIndex() ); assertEquals( 4, event.getBlockEndIndex() ); assertFalse( event.nextBlock() ); } } ); list.addAll( Arrays.asList( "G", "H", "I", "J" ) ); } {code} > ListEvent blocks mostly useless due to get*Value() methods > ---------------------------------------------------------- > > Key: GLAZEDLISTS-576 > URL: https://java.net/jira/browse/GLAZEDLISTS-576 > Project: glazedlists > Issue Type: Bug > Components: core > Affects Versions: 1.9.1 > Reporter: reden > Assignee: jessewilson > Priority: Critical > > ListEvent blocks are no longer useful unless a list contains contiguous duplicate values. This is due to logic in BlockSequence.addChange(int,int,int,E,E): > {code:java} > // concatenate this change on to the previous one > } else if(lastChangedIndex == startIndex && lastType == type && oldValue == lastOldValue && newValue == lastNewValue) { > {code} > Now the values must match in addition to the index (i.e., contiguous change) in order for an event to be concatenated. > The result of the this that...: > {code:java} > EventList<Integer> list = new BasicEventList(); > for( int i = 0; i < 10000; i++ ) { > list.add( Integer.valueOf( i ) ); > } > list.clear(); > {code} > ... the clear() will cause 10,000 events to be fired, which is obviously a huge performance hit in places where event handling is expensive. -- This message was sent by Atlassian JIRA (v6.2.3#6260) |
Free forum by Nabble | Edit this page |