Skip to content

Commit

Permalink
IQuickReuseStrategy isPaging() replaced with isAddItemsSupported() + …
Browse files Browse the repository at this point in the history
…other useless tests removed
  • Loading branch information
vineetsemwal committed Dec 17, 2012
1 parent 1947271 commit 4eb6df9
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public <T> Iterator<Item<T>> addItems(int startIndex, IItemFactory<T> factory, I
*
*/
@Override
public boolean isPaging() {
return false;
public boolean isAddItemsSupported() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ public abstract class AbstractPagingNavigationStrategy implements IQuickReuseStr

@Override
public <T> Iterator<Item<T>> addItems(int startIndex, IItemFactory<T> factory, Iterator<IModel<T>> newModels) {
throw new UnsupportedOperationException("adding items dynamically for partial updates is not supported by this strategy");
throw new IRepeaterUtil.ReuseStrategyNotSupportedException("adding items dynamically for partial updates is not supported by this strategy");
}

public boolean isPaging(){
return true;
@Override
public boolean isAddItemsSupported(){
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public interface IQuickReuseStrategy extends Serializable {
/**
* tells whether reuse strategy support addition of items to view without re-rendering QuickView
*
* @return true if the reuse strategy doesn't support {@link this#addItems(int, org.apache.wicket.markup.repeater.IItemFactory, java.util.Iterator)} else false
* @return boolean
*/
boolean isPaging();
boolean isAddItemsSupported();

}
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,6 @@ public interface IRepeaterUtil {
public String isPageScrollBarAtBottom();


/**
* return iterator of those items whose models are equal ,if the model is not equal new item is returned
*
* @param oldIterator old iterator
* @param newIterator new iterator (iterator of the list of expected modelobjects)
* @return
*/
Iterator<Item> reuseItemsIfModelsEqual(Iterator<Item> oldIterator, Iterator<Item> newIterator);

/**
* throw this exception if quickview's parent is not found
*
Expand Down
32 changes: 2 additions & 30 deletions wicket-quickview/src/main/java/com/aplombee/RepeaterUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.IMarkupFragment;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.lang.Args;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -137,7 +132,7 @@ public int safeLongToInt(long value) {
@Override
public final void parentNotSuitable(IQuickView quickView) {
Args.notNull(quickView, "quickview");
if (quickView.getReuseStrategy() .isPaging()) {
if (!quickView.getReuseStrategy() .isAddItemsSupported()) {
return;
}
MarkupContainer parent = quickView.getParent();
Expand Down Expand Up @@ -169,34 +164,11 @@ public final void outPutMarkupIdNotTrue(IQuickView quickView) {
@Override
public final void reuseStategyNotSupportedForItemsNavigation(IQuickView quickView) {
Args.notNull(quickView, "quickview");
if ( quickView.getReuseStrategy().isPaging()) {
if (!quickView.getReuseStrategy().isAddItemsSupported()) {
throw new ReuseStrategyNotSupportedException(" stategy is not supported for itemsnavigator ");
}
}

@Override
public final Iterator<Item> reuseItemsIfModelsEqual(Iterator<Item> oldIterator, Iterator<Item> newIterator) {
List<Item> list = new ArrayList<Item>();
while (newIterator.hasNext()) {
Item newItem = newIterator.next();
Item old = null;
if (oldIterator.hasNext()) {
old = (Item) oldIterator.next();
}
if (old == null) {
list.add(newItem);
} else {
if (!old.getModel().equals(newItem.getModel())) {
list.add(newItem);
} else {
list.add(old);
}
}
}
return list.iterator();
}



protected String scripts(String regex, String input) {
int regexEnd = end(regex, input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.apache.wicket.model.IModel;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.Iterator;

Expand Down Expand Up @@ -37,8 +36,8 @@ public void assertAddItems(IQuickReuseStrategy strategy){

}

public void assertIsPaging(IQuickReuseStrategy strategy){
Assert.assertFalse(strategy.isPaging());
public void assertIsAddItemsSupported(IQuickReuseStrategy strategy){
Assert.assertTrue(strategy.isAddItemsSupported());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.apache.wicket.markup.repeater.IItemFactory;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.Iterator;

Expand All @@ -12,8 +11,8 @@
*/
public class AbstractPagingNavigationStrategyTest {

public void assertIsPaging(IQuickReuseStrategy strategy){
Assert.assertTrue(strategy.isPaging());
public void assertIsAddItemsSupported(IQuickReuseStrategy strategy){
Assert.assertFalse(strategy.isAddItemsSupported());
}

public void assertAddItems(IQuickReuseStrategy strategy){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
*/
public class DefaultQuickReuseStrategyTest extends AbstractPagingNavigationStrategyTest {

@Test(groups = {"wicketTests"} ,expectedExceptions = UnsupportedOperationException.class)
@Test(groups = {"wicketTests"} ,expectedExceptions = IRepeaterUtil.ReuseStrategyNotSupportedException.class)
public void addItems_1(){
super.assertAddItems(new DefaultQuickReuseStrategy());
}

@Test(groups = {"wicketTests"})
public void isPaging_1(){
super.assertIsPaging(new DefaultQuickReuseStrategy());
super.assertIsAddItemsSupported(new DefaultQuickReuseStrategy());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void addItems_1(){

@Test(groups = {"wicketTests"})
public void isPaging_1(){
super.assertIsPaging(new ItemsNavigationStrategy());
super.assertIsAddItemsSupported(new ItemsNavigationStrategy());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,6 @@ protected Iterator buildItems(long index, Iterator iterator) {
}





/*
*start index=10
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public class QuickReuseIfModelsEqualStrategyTest extends AbstractPagingNavigatio

@Test(groups = {"wicketTests"})
public void isPaging_1(){
super.assertIsPaging(new QuickReuseIfModelsEqualStrategy());
super.assertIsAddItemsSupported(new QuickReuseIfModelsEqualStrategy());
}

@Test(groups = {"wicketTests"} ,expectedExceptions = UnsupportedOperationException.class)
@Test(groups = {"wicketTests"} ,expectedExceptions = IRepeaterUtil.ReuseStrategyNotSupportedException.class)
public void addItems_1(){
super.assertAddItems(new QuickReuseIfModelsEqualStrategy());
}
Expand Down
Loading

0 comments on commit 4eb6df9

Please sign in to comment.