Search in sources :

Example 51 with LinkedList

use of java.util.LinkedList in project head by mifos.

the class MifosBatchJob method computeMissedJobLaunches.

@SuppressWarnings("unchecked")
public List<Date> computeMissedJobLaunches(Date from, Date to, Trigger trigger, boolean onDemandRun) throws Exception {
    List<Date> missedLaunches = new LinkedList<Date>();
    if (trigger instanceof CronTrigger) {
        CronTrigger cronTrigger = new CronTrigger();
        cronTrigger.setStartTime(from);
        cronTrigger.setNextFireTime(from);
        String cronExpression = ((CronTrigger) trigger).getCronExpression();
        try {
            cronTrigger.setCronExpression(cronExpression);
        } catch (ParseException pe) {
            throw new Exception(pe);
        }
        List<Date> computationOutcome = TriggerUtils.computeFireTimesBetween(cronTrigger, null, from, to);
        missedLaunches.addAll(computationOutcome);
        missedLaunches.remove(0);
        if (!onDemandRun && missedLaunches.size() > 0) {
            missedLaunches.remove(missedLaunches.size() - 1);
        }
    } else if (trigger instanceof SimpleTrigger) {
        SimpleTrigger simpleTrigger = new SimpleTrigger();
        simpleTrigger.setStartTime(from);
        simpleTrigger.setNextFireTime(from);
        simpleTrigger.setRepeatInterval(((SimpleTrigger) trigger).getRepeatInterval());
        simpleTrigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
        List<Date> computationOutcome = TriggerUtils.computeFireTimesBetween(simpleTrigger, null, from, to);
        missedLaunches.addAll(computationOutcome);
        missedLaunches.remove(0);
        if (!onDemandRun && missedLaunches.size() > 0) {
            missedLaunches.remove(missedLaunches.size() - 1);
        }
    }
    return missedLaunches;
}
Also used : CronTrigger(org.quartz.CronTrigger) LinkedList(java.util.LinkedList) List(java.util.List) ParseException(java.text.ParseException) SimpleTrigger(org.quartz.SimpleTrigger) LinkedList(java.util.LinkedList) Date(java.util.Date) ParseException(java.text.ParseException) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) JobExecutionException(org.quartz.JobExecutionException) JobInstanceAlreadyCompleteException(org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException)

Example 52 with LinkedList

use of java.util.LinkedList in project head by mifos.

the class ClassUtils method getClasses.

public static Iterable<Class<?>> getClasses(String packageName, String endsWith) throws ClassNotFoundException, IOException {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    assert classLoader != null;
    String path = packageName.replace('.', '/');
    Enumeration<URL> resources = classLoader.getResources(path);
    List<File> dirs = new ArrayList<File>();
    while (resources.hasMoreElements()) {
        URL resource = resources.nextElement();
        // NOPMD by ugupta on 11/29/11 7:25 PM
        dirs.add(new File(resource.getFile()));
    }
    List<Class<?>> classes = new LinkedList<Class<?>>();
    for (File directory : dirs) {
        findClasses(directory, packageName, endsWith, classes);
    }
    return classes;
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) URL(java.net.URL) LinkedList(java.util.LinkedList)

Example 53 with LinkedList

use of java.util.LinkedList in project FastAdapter by mikepenz.

the class ExpandableMultiselectDeleteSampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    //as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater
    //https://github.com/mikepenz/Android-Iconics
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    // get RecyclerView
    final RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.sample_collapsible);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter
    fastItemAdapter = new FastItemAdapter<>();
    fastItemAdapter.withPositionBasedStateManagement(false).withSelectable(true).withMultiSelect(true).withSelectOnLongClick(true).withOnPreClickListener(new FastAdapter.OnClickListener<IItem>() {

        @Override
        public boolean onClick(View v, IAdapter<IItem> adapter, IItem item, int position) {
            //we handle the default onClick behavior for the actionMode. This will return null if it didn't do anything and you can handle a normal onClick
            Boolean res = mActionModeHelper.onClick(ExpandableMultiselectDeleteSampleActivity.this, item);
            // so that the click listener is not fired
            if (res != null && !res)
                return true;
            return res != null ? res : false;
        }
    }).withOnClickListener(new FastAdapter.OnClickListener<IItem>() {

        @Override
        public boolean onClick(View v, IAdapter<IItem> adapter, IItem item, int position) {
            // check if the actionMode consumes the click. This returns true, if it does, false if not
            if (!mActionModeHelper.isActive())
                Toast.makeText(ExpandableMultiselectDeleteSampleActivity.this, ((SimpleSubItem) item).name + " clicked!", Toast.LENGTH_SHORT).show();
            //                        else
            //                            mFastAdapter.notifyItemChanged(position); // im Bsp. ist das nicht nötig, k.A. warum ich das machen muss!
            mRangeSelectorHelper.onClick();
            return false;
        }
    }).withOnPreLongClickListener(new FastAdapter.OnLongClickListener<IItem>() {

        @Override
        public boolean onLongClick(View v, IAdapter<IItem> adapter, IItem item, int position) {
            boolean actionModeWasActive = mActionModeHelper.isActive();
            ActionMode actionMode = mActionModeHelper.onLongClick((AppCompatActivity) ExpandableMultiselectDeleteSampleActivity.this, position);
            mRangeSelectorHelper.onLongClick(position);
            if (actionMode != null) {
                //we want color our CAB
                ExpandableMultiselectDeleteSampleActivity.this.findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(ExpandableMultiselectDeleteSampleActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));
                // start the drag selection
                mDragSelectTouchListener.startDragSelection(position);
            }
            //if we have no actionMode we do not consume the event
            return actionMode != null && !actionModeWasActive;
        }
    });
    // provide a custom title provider that even shows the count of sub items
    mActionModeHelper = new ActionModeHelper(fastItemAdapter, R.menu.cab, new ActionBarCallBack()).withTitleProvider(new ActionModeHelper.ActionModeTitleProvider() {

        @Override
        public String getTitle(int selected) {
            return selected + "/" + SubItemUtil.countItems(fastItemAdapter.getItemAdapter(), false);
        }
    }).withSupportSubItems(true);
    // this will take care of selecting range of items via long press on the first and afterwards on the last item
    mRangeSelectorHelper = new RangeSelectorHelper(fastItemAdapter).withSavedInstanceState(savedInstanceState).withActionModeHelper(mActionModeHelper);
    // setup the drag select listener and add it to the RecyclerView
    mDragSelectTouchListener = new DragSelectTouchListener().withSelectListener(new DragSelectTouchListener.OnDragSelectListener() {

        @Override
        public void onSelectChange(int start, int end, boolean isSelected) {
            mRangeSelectorHelper.selectRange(start, end, isSelected, true);
            // we handled the long press, so we reset the range selector
            mRangeSelectorHelper.reset();
        }
    });
    rv.addOnItemTouchListener(mDragSelectTouchListener);
    // do basic RecyclerView setup
    rv.setLayoutManager(new LinearLayoutManager(this));
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    rv.setAdapter(fastItemAdapter);
    //fill with some sample data
    List<IItem> items = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        if (i % 2 == 0) {
            final HeaderSelectionItem expandableItem = new HeaderSelectionItem();
            expandableItem.withSubSelectionProvider(new HeaderSelectionItem.ISubSelectionProvider() {

                @Override
                public int getSelectedSubItems() {
                    return SubItemUtil.countSelectedSubItems(fastItemAdapter, expandableItem);
                }
            }).withName("Test " + (i + 1)).withDescription("ID: " + (i + 1)).withIdentifier(i + 1);
            //.withIsExpanded(true) don't use this in such a setup, use adapter.expand() to expand all items instead
            //add subitems so we can showcase the collapsible functionality
            List<IItem> subItems = new LinkedList<>();
            for (int ii = 1; ii <= 5; ii++) {
                final SimpleSubItem sampleItem = new SimpleSubItem();
                sampleItem.withName("-- Test " + (i + 1) + "." + ii).withDescription("ID: " + (i + 1) * 100 + ii).withIdentifier((i + 1) * 100 + ii);
                subItems.add(sampleItem);
            }
            expandableItem.withSubItems(subItems);
            items.add(expandableItem);
        } else {
            SimpleSubItem sampleItem = new SimpleSubItem();
            sampleItem.withName("Test " + (i + 1)).withDescription("ID: " + (i + 1)).withIdentifier(i + 1);
            items.add(sampleItem);
        }
    }
    fastItemAdapter.add(items);
    fastItemAdapter.expand();
    fastItemAdapter.withSelectionListener(new ISelectionListener() {

        @Override
        public void onSelectionChanged(IItem item, boolean selected) {
            if (item instanceof SimpleSubItem) {
                IItem headerItem = ((SimpleSubItem) item).getParent();
                if (headerItem != null) {
                    int pos = fastItemAdapter.getAdapterPosition(headerItem);
                    // Important: notify the header directly, not via the notifyadapterItemChanged!
                    // we just want to update the view and we are sure, nothing else has to be done
                    fastItemAdapter.notifyItemChanged(pos);
                }
            }
        }
    });
    //restore selections (this has to be done after the items were added
    fastItemAdapter.withSavedInstanceState(savedInstanceState);
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
    // restore action mode
    if (savedInstanceState != null)
        mActionModeHelper.checkActionMode(this);
}
Also used : ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ISelectionListener(com.mikepenz.fastadapter.ISelectionListener) SlideDownAlphaAnimator(com.mikepenz.itemanimators.SlideDownAlphaAnimator) IItem(com.mikepenz.fastadapter.IItem) IAdapter(com.mikepenz.fastadapter.IAdapter) Toolbar(android.support.v7.widget.Toolbar) SimpleSubItem(com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem) RangeSelectorHelper(com.mikepenz.fastadapter_extensions.RangeSelectorHelper) HeaderSelectionItem(com.mikepenz.fastadapter.app.items.HeaderSelectionItem) AppCompatActivity(android.support.v7.app.AppCompatActivity) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) LinkedList(java.util.LinkedList) ActionMode(android.support.v7.view.ActionMode) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) IconicsLayoutInflater(com.mikepenz.iconics.context.IconicsLayoutInflater) ActionModeHelper(com.mikepenz.fastadapter_extensions.ActionModeHelper) DragSelectTouchListener(com.michaelflisar.dragselectrecyclerview.DragSelectTouchListener)

Example 54 with LinkedList

use of java.util.LinkedList in project FastAdapter by mikepenz.

the class ExpandableSampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    //as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater
    //https://github.com/mikepenz/Android-Iconics
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.sample_collapsible);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter
    fastItemAdapter = new FastItemAdapter<>();
    fastItemAdapter.withSelectable(true);
    //get our recyclerView and do basic setup
    RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
    rv.setLayoutManager(new LinearLayoutManager(this));
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    rv.setAdapter(fastItemAdapter);
    //fill with some sample data
    List<IItem> items = new ArrayList<>();
    for (int i = 1; i <= 100; i++) {
        if (i % 10 == 0) {
            SimpleSubExpandableItem expandableItem = new SimpleSubExpandableItem();
            expandableItem.withName("Test " + i).withIdentifier(100 + 1);
            //add subitems so we can showcase the collapsible functionality
            List<IItem> subItems = new LinkedList<>();
            for (int ii = 1; ii <= 5; ii++) {
                SimpleSubItem sampleItem = new SimpleSubItem();
                sampleItem.withName("-- Test " + ii).withIdentifier(1000 + ii);
                subItems.add(sampleItem);
            }
            expandableItem.withSubItems(subItems);
            items.add(expandableItem);
        } else {
            items.add(new SimpleSubItem().withName("Test " + i).withIdentifier(100 + i));
        }
    }
    fastItemAdapter.add(items);
    //restore selections (this has to be done after the items were added
    fastItemAdapter.withSavedInstanceState(savedInstanceState);
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
}
Also used : SimpleSubItem(com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem) SimpleSubExpandableItem(com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) LinkedList(java.util.LinkedList) SlideDownAlphaAnimator(com.mikepenz.itemanimators.SlideDownAlphaAnimator) RecyclerView(android.support.v7.widget.RecyclerView) IItem(com.mikepenz.fastadapter.IItem) IconicsLayoutInflater(com.mikepenz.iconics.context.IconicsLayoutInflater) Toolbar(android.support.v7.widget.Toolbar)

Example 55 with LinkedList

use of java.util.LinkedList in project FastAdapter by mikepenz.

the class SubItemUtil method deleteSelected.

/**
     * deletes all selected items from the adapter respecting if the are sub items or not
     * subitems are removed from their parents sublists, main items are directly removed
     *
     * @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> deleteSelected(final FastAdapter fastAdapter, boolean notifyParent, boolean deleteEmptyHeaders) {
    List<IItem> deleted = new ArrayList<>();
    // we use a LinkedList, because this has performance advantages when modifying the listIterator during iteration!
    // Modifying list is O(1)
    LinkedList<IItem> selectedItems = new LinkedList<>(getSelectedItems(fastAdapter));
    //        Log.d("DELETE", "selectedItems: " + selectedItems.size());
    // 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;
    ListIterator<IItem> it = selectedItems.listIterator();
    while (it.hasNext()) {
        item = it.next();
        pos = fastAdapter.getPosition(item);
        // 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 its 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);
                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;
            }
            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)

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