use of java.util.LinkedList in project FastAdapter by mikepenz.
the class SubItemUtil method delete.
/**
* deletes all items in identifiersToDelete collection from the adapter respecting if there are sub items or not
* subitems are removed from their parents sublists, main items are directly removed
*
* @param fastAdapter the adapter to remove the items from
* @param identifiersToDelete ids of items to remove
* @param notifyParent if true, headers of removed items will be notified about the change of their child items
* @param deleteEmptyHeaders if true, empty headers will be removed from the adapter
* @return List of items that have been removed from the adapter
*/
public static List<IItem> delete(final FastAdapter fastAdapter, Collection<Long> identifiersToDelete, boolean notifyParent, boolean deleteEmptyHeaders) {
List<IItem> deleted = new ArrayList<>();
if (identifiersToDelete == null || identifiersToDelete.size() == 0) {
return deleted;
}
// we use a LinkedList, because this has performance advantages when modifying the listIterator during iteration!
// Modifying list is O(1)
LinkedList<Long> identifiers = new LinkedList<>(identifiersToDelete);
// we delete item per item from the adapter directly or from the parent
// if keepEmptyHeaders is false, we add empty headers to the selected items set via the iterator, so that they are processed in the loop as well
IItem item, parent;
int pos, parentPos;
boolean expanded;
Long identifier;
ListIterator<Long> it = identifiers.listIterator();
while (it.hasNext()) {
identifier = it.next();
pos = fastAdapter.getPosition(identifier);
item = fastAdapter.getItem(pos);
// search for parent - if we find one, we remove the item from the parent's subitems directly
parent = getParent(item);
if (parent != null) {
parentPos = fastAdapter.getPosition(parent);
boolean success = ((IExpandable) parent).getSubItems().remove(item);
// check if parent is expanded and notify the adapter about the removed item, if necessary (only if parent is visible)
if (parentPos != -1 && ((IExpandable) parent).isExpanded()) {
fastAdapter.notifyAdapterSubItemsChanged(parentPos, ((IExpandable) parent).getSubItems().size() + 1);
}
// if desired, notify the parent about it's changed items (only if parent is visible!)
if (parentPos != -1 && notifyParent) {
expanded = ((IExpandable) parent).isExpanded();
fastAdapter.notifyAdapterItemChanged(parentPos);
// expand the item again if it was expanded before calling notifyAdapterItemChanged
if (expanded) {
fastAdapter.expand(parentPos);
}
}
deleted.add(item);
if (deleteEmptyHeaders && ((IExpandable) parent).getSubItems().size() == 0) {
it.add(parent.getIdentifier());
it.previous();
}
} else if (pos != -1) {
// if we did not find a parent, we remove the item from the adapter
IAdapter adapter = fastAdapter.getAdapter(pos);
boolean success = false;
if (adapter instanceof IItemAdapter) {
success = ((IItemAdapter) adapter).remove(pos) != null;
if (success) {
fastAdapter.notifyAdapterItemRemoved(pos);
}
}
boolean isHeader = item instanceof IExpandable && ((IExpandable) item).getSubItems() != null;
// Log.d("DELETE", "success=" + success + " | deletedId=" + item.getIdentifier() + "(" + (isHeader ? "EMPTY HEADER" : "ITEM WITHOUT HEADER") + ")");
deleted.add(item);
}
}
return deleted;
}
use of java.util.LinkedList in project mockito by mockito.
the class DefaultStubbingLookupListener method potentialArgMismatches.
private static List<Invocation> potentialArgMismatches(Invocation invocation) {
List<Invocation> matchingStubbings = new LinkedList<Invocation>();
Collection<Stubbing> stubbings = mockingDetails(invocation.getMock()).getStubbings();
for (Stubbing s : stubbings) {
if (!s.wasUsed() && s.getInvocation().getMethod().getName().equals(invocation.getMethod().getName())) {
matchingStubbings.add(s.getInvocation());
}
}
return matchingStubbings;
}
use of java.util.LinkedList in project head by mifos.
the class CenterScheduleCreationUsingCustomerServiceIntegrationTest method saveHoliday.
private void saveHoliday(DateTime start, DateTime through, RepaymentRuleTypes rule) throws Exception {
HolidayDetails holidayDetails = new HolidayDetails("testHoliday", start.toDate(), through.toDate(), rule.getValue());
List<Short> officeIds = new LinkedList<Short>();
officeIds.add((short) 1);
IntegrationTestObjectMother.createHoliday(holidayDetails, officeIds);
}
use of java.util.LinkedList in project head by mifos.
the class ValidatorsTest method testIntValidator.
public void testIntValidator() throws Exception {
Validator val = new IntValidator();
Assert.assertEquals(42, val.validate("42"));
Assert.assertEquals(42, val.validate("042"));
checkException(val, "notanumber", ErrorType.INVALID_INT.toString());
// check error when given wrong type
checkException(val, new LinkedList(), ErrorType.WRONG_TYPE.toString());
checkException(val, " 042", ErrorType.INVALID_INT.toString());
}
use of java.util.LinkedList in project head by mifos.
the class QuestionnaireMapperTest method getSectionWithOneMultiSelectQuestion.
private Section getSectionWithOneMultiSelectQuestion(int sectionQuestionId, String sectionName, String questionName, String... choices) {
Section section = new Section(sectionName);
List<SectionQuestion> sectionQuestions = new ArrayList<SectionQuestion>();
SectionQuestion sectionQuestion = new SectionQuestion();
sectionQuestion.setId(sectionQuestionId);
sectionQuestion.setSection(section);
QuestionEntity questionEntity = new QuestionEntity();
questionEntity.setQuestionText(questionName);
questionEntity.setAnswerType(AnswerType.MULTISELECT);
LinkedList<QuestionChoiceEntity> questionChoiceEntities = new LinkedList<QuestionChoiceEntity>();
for (String choice : choices) {
QuestionChoiceEntity questionChoiceEntity = new QuestionChoiceEntity();
questionChoiceEntity.setChoiceText(choice);
questionChoiceEntities.add(questionChoiceEntity);
}
questionEntity.setChoices(questionChoiceEntities);
sectionQuestion.setQuestion(questionEntity);
sectionQuestions.add(sectionQuestion);
section.setQuestions(sectionQuestions);
return section;
}
Aggregations