Search in sources :

Example 56 with LinkedList

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;
}
Also used : IExpandable(com.mikepenz.fastadapter.IExpandable) ArrayList(java.util.ArrayList) IItemAdapter(com.mikepenz.fastadapter.IItemAdapter) IItem(com.mikepenz.fastadapter.IItem) IAdapter(com.mikepenz.fastadapter.IAdapter) LinkedList(java.util.LinkedList)

Example 57 with LinkedList

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;
}
Also used : Stubbing(org.mockito.stubbing.Stubbing) Invocation(org.mockito.invocation.Invocation) MatchableInvocation(org.mockito.invocation.MatchableInvocation) LinkedList(java.util.LinkedList)

Example 58 with LinkedList

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);
}
Also used : HolidayDetails(org.mifos.dto.domain.HolidayDetails) LinkedList(java.util.LinkedList)

Example 59 with LinkedList

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());
}
Also used : LinkedList(java.util.LinkedList)

Example 60 with LinkedList

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;
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Section(org.mifos.platform.questionnaire.domain.Section) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)10512 Test (org.junit.Test)1487 List (java.util.List)1463 HashMap (java.util.HashMap)1371 ArrayList (java.util.ArrayList)1313 Map (java.util.Map)871 IOException (java.io.IOException)800 File (java.io.File)695 HashSet (java.util.HashSet)605 LinkedHashMap (java.util.LinkedHashMap)382 GenericValue (org.apache.ofbiz.entity.GenericValue)296 Iterator (java.util.Iterator)277 Set (java.util.Set)255 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)232 Date (java.util.Date)222 Collection (java.util.Collection)201 Delegator (org.apache.ofbiz.entity.Delegator)162 Locale (java.util.Locale)158 URL (java.net.URL)154 BufferedReader (java.io.BufferedReader)146