Example usage for java.util ArrayList clear

List of usage examples for java.util ArrayList clear

Introduction

In this page you can find the example usage for java.util ArrayList clear.

Prototype

public void clear() 

Source Link

Document

Removes all of the elements from this list.

Usage

From source file:com.miz.service.TraktTvShowsSyncService.java

private void updateTvShowCollection() {
    int count = mLocalCollection.size();
    if (count > 0) {
        ArrayList<TraktTvShow> collection = new ArrayList<TraktTvShow>();

        for (int i = 0; i < count; i++) {
            if (!mTraktCollection.containsKey(mLocalCollection.get(i).getId())) {
                // This show isn't in the Trakt library, so we'll add everything
                collection.add(mLocalCollection.get(i));
            } else {

                TraktTvShow traktTemp = mTraktCollection.get(mLocalCollection.get(i).getId());
                TraktTvShow temp = new TraktTvShow(mLocalCollection.get(i).getId(),
                        mLocalCollection.get(i).getTitle());

                // This show is in the Trakt library, so we'll have to check each episode in each season
                Multimap<String, String> seasonsMap = mLocalCollection.get(i).getSeasons();
                Set<String> seasons = seasonsMap.keySet();
                for (String season : seasons) {
                    Collection<String> episodes = seasonsMap.get(season);
                    for (String episode : episodes) {
                        if (!traktTemp.contains(MizLib.removeIndexZero(season),
                                MizLib.removeIndexZero(episode))) {
                            temp.addEpisode(season, episode);
                        }//from w ww  .  j av a 2 s  . c o  m
                    }
                }

                if (temp.getSeasons().size() > 0)
                    collection.add(temp);
            }
        }

        count = collection.size();
        for (int i = 0; i < count; i++) {
            Trakt.addTvShowToLibrary(collection.get(i), getApplicationContext());
        }

        // Clean up
        collection.clear();
        collection = null;

        mTraktCollection.clear();
        mTraktCollection = null;
    }
}

From source file:com.miz.service.TraktTvShowsSyncService.java

private void updateWatchedTvShows() {
    int count = mLocalWatched.size();
    if (count > 0) {
        ArrayList<TraktTvShow> watched = new ArrayList<TraktTvShow>();

        for (int i = 0; i < count; i++) {
            if (!mTraktWatched.containsKey(mLocalWatched.get(i).getId())) {
                // This show isn't in the Trakt library, so we'll add everything
                watched.add(mLocalWatched.get(i));
            } else {

                TraktTvShow traktTemp = mTraktWatched.get(mLocalWatched.get(i).getId());
                TraktTvShow temp = new TraktTvShow(mLocalWatched.get(i).getId(),
                        mLocalWatched.get(i).getTitle());

                // This show is in the Trakt library, so we'll have to check each episode in each season
                Multimap<String, String> seasonsMap = mLocalWatched.get(i).getSeasons();
                Set<String> seasons = seasonsMap.keySet();
                for (String season : seasons) {
                    Collection<String> episodes = seasonsMap.get(season);
                    for (String episode : episodes) {
                        if (!traktTemp.contains(MizLib.removeIndexZero(season),
                                MizLib.removeIndexZero(episode))) {
                            temp.addEpisode(MizLib.removeIndexZero(season), MizLib.removeIndexZero(episode));
                        }/*from   w  w  w .j  a  v a 2s. c  o m*/
                    }
                }

                if (temp.getSeasons().size() > 0)
                    watched.add(temp);
            }
        }

        count = watched.size();
        for (int i = 0; i < count; i++) {
            Trakt.markTvShowAsWatched(watched.get(i), getApplicationContext());
        }

        // Clean up
        watched.clear();
        watched = null;

        mTraktWatched.clear();
        mTraktWatched = null;
    }
}

From source file:com.ibm.bi.dml.hops.rewrite.ProgramRewriter.java

/**
 * /*from  ww w  .j  ava  2  s .  c o m*/
 * @param sb
 * @return
 * @throws HopsException
 */
private ArrayList<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus status)
        throws HopsException {
    ArrayList<StatementBlock> ret = new ArrayList<StatementBlock>();
    ret.add(sb);

    //recursive invocation
    if (sb instanceof FunctionStatementBlock) {
        FunctionStatementBlock fsb = (FunctionStatementBlock) sb;
        FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
        fstmt.setBody(rewriteStatementBlocks(fstmt.getBody(), status));
    } else if (sb instanceof WhileStatementBlock) {
        WhileStatementBlock wsb = (WhileStatementBlock) sb;
        WhileStatement wstmt = (WhileStatement) wsb.getStatement(0);
        wstmt.setBody(rewriteStatementBlocks(wstmt.getBody(), status));
    } else if (sb instanceof IfStatementBlock) {
        IfStatementBlock isb = (IfStatementBlock) sb;
        IfStatement istmt = (IfStatement) isb.getStatement(0);
        istmt.setIfBody(rewriteStatementBlocks(istmt.getIfBody(), status));
        istmt.setElseBody(rewriteStatementBlocks(istmt.getElseBody(), status));
    } else if (sb instanceof ForStatementBlock) //incl parfor
    {
        //maintain parfor context information (e.g., for checkpointing)
        boolean prestatus = status.isInParforContext();
        if (sb instanceof ParForStatementBlock)
            status.setInParforContext(true);

        ForStatementBlock fsb = (ForStatementBlock) sb;
        ForStatement fstmt = (ForStatement) fsb.getStatement(0);
        fstmt.setBody(rewriteStatementBlocks(fstmt.getBody(), status));

        status.setInParforContext(prestatus);
    }

    //apply rewrite rules
    for (StatementBlockRewriteRule r : _sbRuleSet) {
        ArrayList<StatementBlock> tmp = new ArrayList<StatementBlock>();
        for (StatementBlock sbc : ret)
            tmp.addAll(r.rewriteStatementBlock(sbc, status));

        //take over set of rewritten sbs      
        ret.clear();
        ret.addAll(tmp);
    }

    return ret;
}

From source file:com.actionbarsherlock.internal.nineoldandroids.animation.AnimatorSet.java

/**
 * This method sorts the current set of nodes, if needed. The sort is a simple
 * DependencyGraph sort, which goes like this:
 * - All nodes without dependencies become 'roots'
 * - while roots list is not null/*from  www.  java  2 s. c o  m*/
 * -   for each root r
 * -     add r to sorted list
 * -     remove r as a dependency from any other node
 * -   any nodes with no dependencies are added to the roots list
 */
private void sortNodes() {
    if (mNeedsSort) {
        mSortedNodes.clear();
        ArrayList<Node> roots = new ArrayList<Node>();
        int numNodes = mNodes.size();
        for (int i = 0; i < numNodes; ++i) {
            Node node = mNodes.get(i);
            if (node.dependencies == null || node.dependencies.size() == 0) {
                roots.add(node);
            }
        }
        ArrayList<Node> tmpRoots = new ArrayList<Node>();
        while (roots.size() > 0) {
            int numRoots = roots.size();
            for (int i = 0; i < numRoots; ++i) {
                Node root = roots.get(i);
                mSortedNodes.add(root);
                if (root.nodeDependents != null) {
                    int numDependents = root.nodeDependents.size();
                    for (int j = 0; j < numDependents; ++j) {
                        Node node = root.nodeDependents.get(j);
                        node.nodeDependencies.remove(root);
                        if (node.nodeDependencies.size() == 0) {
                            tmpRoots.add(node);
                        }
                    }
                }
            }
            roots.clear();
            roots.addAll(tmpRoots);
            tmpRoots.clear();
        }
        mNeedsSort = false;
        if (mSortedNodes.size() != mNodes.size()) {
            throw new IllegalStateException("Circular dependencies cannot exist" + " in AnimatorSet");
        }
    } else {
        // Doesn't need sorting, but still need to add in the nodeDependencies list
        // because these get removed as the event listeners fire and the dependencies
        // are satisfied
        int numNodes = mNodes.size();
        for (int i = 0; i < numNodes; ++i) {
            Node node = mNodes.get(i);
            if (node.dependencies != null && node.dependencies.size() > 0) {
                int numDependencies = node.dependencies.size();
                for (int j = 0; j < numDependencies; ++j) {
                    Dependency dependency = node.dependencies.get(j);
                    if (node.nodeDependencies == null) {
                        node.nodeDependencies = new ArrayList<Node>();
                    }
                    if (!node.nodeDependencies.contains(dependency.node)) {
                        node.nodeDependencies.add(dependency.node);
                    }
                }
            }
            // nodes are 'done' by default; they become un-done when started, and done
            // again when ended
            node.done = false;
        }
    }
}

From source file:br.com.Utilitarios.WorkUpService.java

public void tenhoAtualizacoes() throws SQLException {

    clear();//from  ww w  . j  a va  2s  .  c o m

    // pega atualizacoes do server

    ArrayList<Atualizacoes> atualizacoesAluno = new ArrayList<Atualizacoes>();
    ArrayList<Atualizacoes> atualizacoesPersonal = new ArrayList<Atualizacoes>();

    if (pref.getString("usuario", null) != null) {
        if (pref.getString("tipo", null).equals("personal")) {
            int tenhoAtualizacoes = new Atualizacoes()
                    .buscarAtualizacoesPendentesPersonalWeb(pref.getString("usuario", null));
            if (tenhoAtualizacoes > 0) {
                atualizacoesPersonal = new Atualizacoes()
                        .getAtualizacoesPendentesPersonalWeb(pref.getString("usuario", null));
                for (Atualizacoes a : atualizacoesPersonal) {

                    a.salvarAtualizacao(b);

                }
            }
        } else if (pref.getString("tipo", null).equals("aluno")) {
            int tenhoAtualizacoes = new Atualizacoes()
                    .buscarAtualizacoesPendentesAlunoWeb(pref.getString("usuario", null));
            if (tenhoAtualizacoes > 0) {
                atualizacoesAluno = new Atualizacoes()
                        .getAtualizacoesPendentesAlunoWeb(pref.getString("usuario", null));
                for (Atualizacoes a : atualizacoesAluno) {

                    a.salvarAtualizacao(b);
                }
            }
        }
    }

    atualizacoesAluno.clear();
    atualizacoesPersonal.clear();

    if (pref.getString("usuario", null) != null) {
        if (pref.getString("tipo", null).equals("personal")) {
            int tenhoAtualizacoes = new Atualizacoes().buscarAtualizacoesPendentesPersonal(b,
                    pref.getString("usuario", null));
            if (tenhoAtualizacoes > 0) {
                atualizacoesPersonal = new Atualizacoes().getAtualizacoesPendentesPersonal(b,
                        pref.getString("usuario", null));

                for (Atualizacoes n : atualizacoesPersonal) {
                    solucionarAtualizacoes(n);
                }
            }
        } else if (pref.getString("tipo", null).equals("aluno")) {

            int tenhoAtualizacoes = new Atualizacoes().buscarAtualizacoesPendentesAluno(b,
                    pref.getString("usuario", null));
            if (tenhoAtualizacoes > 0) {
                atualizacoesAluno = new Atualizacoes().getAtualizacoesPendentesAluno(b,
                        pref.getString("usuario", null));

                for (Atualizacoes n : atualizacoesAluno) {
                    solucionarAtualizacoes(n);
                }
            }
        }
    }

}

From source file:com.arlib.floatingsearchview.util.view.MenuView.java

/**
 * Resets the the view to fit into a new
 * available width./*from   w  ww.jav a2s .c  o m*/
 *
 * <p>This clears and then re-inflates the menu items
 * , removes all of its associated action views, and recreates
 * the menu and action items to fit in the new width.</p>
 *
 * @param availWidth the width available for the menu to use. If
 *                   there is room, menu items that are flagged with
 *                   android:showAsAction="ifRoom" or android:showAsAction="always"
 *                   will show as actions.
 */
public void reset(int availWidth) {

    if (mMenu == -1)
        return;

    //clean view first
    removeAllViews();
    mActionItems.clear();

    //reset menu
    mMenuBuilder.clearAll();
    getMenuInflater().inflate(mMenu, mMenuBuilder);

    int holdAllItemsCount;

    mMenuItems = mMenuBuilder.getActionItems();
    mMenuItems.addAll(mMenuBuilder.getNonActionItems());

    holdAllItemsCount = mMenuItems.size();

    Collections.sort(mMenuItems, new Comparator<MenuItemImpl>() {
        @Override
        public int compare(MenuItemImpl lhs, MenuItemImpl rhs) {
            return ((Integer) lhs.getOrder()).compareTo(rhs.getOrder());
        }
    });

    List<MenuItemImpl> menuItems = filter(mMenuItems, new MenuItemImplPredicate() {
        @Override
        public boolean apply(MenuItemImpl menuItem) {
            return menuItem.requiresActionButton() || menuItem.requestsActionButton();
        }
    });

    int availItemRoom = availWidth / (int) ACTION_DIMENSION_PX;
    boolean addOverflowAtTheEnd = false;
    if (((menuItems.size() < holdAllItemsCount) || availItemRoom < menuItems.size())) {
        addOverflowAtTheEnd = true;
        availItemRoom--;
    }

    ArrayList<Integer> actionMenuItems = new ArrayList<>();

    if (availItemRoom > 0)
        for (int i = 0; i < menuItems.size(); i++) {

            final MenuItemImpl menuItem = menuItems.get(i);

            if (menuItem.getIcon() != null) {

                ImageView action = getActionHolder();
                action.setImageDrawable(Util.setIconColor(menuItem.getIcon(), mActionIconColor));
                addView(action);
                mActionItems.add(menuItem);

                action.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        if (mMenuCallback != null)
                            mMenuCallback.onMenuItemSelected(mMenuBuilder, menuItem);
                    }
                });

                actionMenuItems.add(menuItem.getItemId());

                availItemRoom--;
                if (availItemRoom == 0)
                    break;
            }
        }

    if (addOverflowAtTheEnd) {

        ImageView overflowAction = getOverflowActionHolder();
        overflowAction.setImageDrawable(Util.setIconColor(
                getResources().getDrawable(R.drawable.ic_more_vert_black_24dp), mOverflowIconColor));
        addView(overflowAction);

        overflowAction.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                mMenuPopupHelper.show();
            }
        });

        mMenuBuilder.setCallback(mMenuCallback);

        mHasOverflow = true;
    }

    for (int id : actionMenuItems)
        mMenuBuilder.removeItem(id);

    actionMenuItems.clear();

    if (mOnVisibleWidthChanged != null)
        mOnVisibleWidthChanged.onVisibleWidthChanged(
                ((int) ACTION_DIMENSION_PX * getChildCount()) - (mHasOverflow ? Util.dpToPx(8) : 0));
}

From source file:com.malin.rxjava.activity.MainActivity.java

private void method20() {

    final int COUNT = 5;
    final int TIME_ALL = 3000;
    final ArrayList<Long> timeList = new ArrayList<>();
    final ArrayList<Long> allList = new ArrayList<>();

    RxView.clicks(findViewById(R.id.iv_image)).map(new Func1<Void, Long>() {
        @Override/*from w  w  w.j  av a 2 s .  co m*/
        public Long call(Void aVoid) {
            return System.currentTimeMillis();
        }
    }).map(new Func1<Long, Boolean>() {
        @Override
        public Boolean call(Long nowTime) {
            allList.add(nowTime);
            timeList.add(nowTime);

            boolean isOver = false;
            Log.d(TAG, "timeList.size():" + timeList.size());
            if (timeList.size() >= COUNT) {

                if (nowTime - timeList.get(0) < TIME_ALL) {
                    isOver = true;
                } else {
                    isOver = false;
                }
                timeList.clear();
            }
            return isOver;
        }
    }).subscribe(new Action1<Boolean>() {
        @Override
        public void call(Boolean aBoolean) {
            if (aBoolean) {
                Toast.makeText(MainActivity.this, "3" + allList.size(), Toast.LENGTH_SHORT)
                        .show();
                allList.clear();
            } else {
                // Toast.makeText(MainActivity.this, "ok "+timeList.size(), Toast.LENGTH_SHORT).show();
            }
        }
    });
}

From source file:edu.ku.brc.specify.config.FixAttachments.java

/**
 * @param tableList/*from  w w  w. j  a  va2 s .com*/
 * @param tableIdList
 * @param resultsHashMap
 * @param tblTypeHash
 * @param tableHash
 * @param totalFiles
 */
private void displayBadAttachments(final ArrayList<JTable> tableList, final ArrayList<Integer> tableIdList,
        final HashMap<Integer, Vector<Object[]>> resultsHashMap, final HashMap<Integer, String> tblTypeHash,
        final HashMap<Integer, AttchTableModel> tableHash, final int totalFiles) {
    CellConstraints cc = new CellConstraints();

    int maxWidth = 200;
    int y = 1;
    String rowDef = tableList.size() == 1 ? "f:p:g"
            : UIHelper.createDuplicateJGoodiesDef("p", "10px", tableList.size());
    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", rowDef));
    if (tableList.size() > 1) {
        int i = 0;
        for (JTable table : tableList) {
            Integer tblId = tableIdList.get(i++);
            int numRows = table.getModel().getRowCount();

            PanelBuilder pb2 = new PanelBuilder(new FormLayout("f:p:g", "p,2px,f:p:g"));
            if (resultsHashMap.size() > 1) {
                UIHelper.calcColumnWidths(table, numRows < 15 ? numRows + 1 : 15, maxWidth);
            } else {
                UIHelper.calcColumnWidths(table, 15, maxWidth);
            }
            pb2.addSeparator(tblTypeHash.get(tblId), cc.xy(1, 1));
            pb2.add(UIHelper.createScrollPane(table), cc.xy(1, 3));
            pb.add(pb2.getPanel(), cc.xy(1, y));
            y += 2;
        }
    } else {
        UIHelper.calcColumnWidths(tableList.get(0), 15, maxWidth);
        pb.add(UIHelper.createScrollPane(tableList.get(0)), cc.xy(1, 1));
    }
    tableList.clear();

    pb.setDefaultDialogBorder();

    JScrollPane panelSB = UIHelper.createScrollPane(pb.getPanel());
    panelSB.setBorder(BorderFactory.createEmptyBorder());
    Dimension dim = panelSB.getPreferredSize();
    panelSB.setPreferredSize(new Dimension(dim.width + 10, 600));

    final int totFiles = totalFiles;
    String title = String.format("Attachment Information - %d files to recover.", totalFiles);
    CustomDialog dlg = new CustomDialog((Dialog) null, title, true, CustomDialog.OKCANCELAPPLYHELP, panelSB) {
        @Override
        protected void helpButtonPressed() {
            File file = produceSummaryReport(resultsHashMap, tableHash, totFiles);
            try {
                AttachmentUtils.openURI(file.toURI());
            } catch (Exception e) {
            }
        }

        @Override
        protected void applyButtonPressed() {
            boolean isOK = UIRegistry.displayConfirm("Clean up",
                    "Are you sure you want to remove all references to the missing attachments?", "Remove",
                    "Cancel", JOptionPane.WARNING_MESSAGE);
            if (isOK) {
                super.applyButtonPressed();
            }
        }
    };

    dlg.setCloseOnApplyClk(true);
    dlg.setCancelLabel("Skip");
    dlg.setOkLabel("Recover Files");
    dlg.setHelpLabel("Show Summary");
    dlg.setApplyLabel("Delete References");
    dlg.createUI();
    dlg.pack();

    dlg.setVisible(true);

    if (dlg.getBtnPressed() == CustomDialog.OK_BTN) {
        reattachFiles(resultsHashMap, tableHash, totalFiles);

    } else if (dlg.getBtnPressed() == CustomDialog.APPLY_BTN) {
        doAttachmentRefCleanup(resultsHashMap, tableHash, totFiles);
    }

}

From source file:MSUmpire.LCMSPeakStructure.LCMSPeakMS1.java

public void PeakClusterDetection()
        throws FileNotFoundException, IOException, InterruptedException, ExecutionException,
        ParserConfigurationException, SAXException, DataFormatException, XmlPullParserException {

    if (Resume && ReadIfProcessed()) {
        return;/*from   ww w .ja  va 2s  .co  m*/
    }
    CreatePeakFolder();
    ArrayList<ScanCollection> scanCollections = new ArrayList<>();
    //Calculate how many point per minute when we do B-spline peak smoothing
    parameter.NoPeakPerMin = (int) (parameter.SmoothFactor / GetSpectrumParser().GetMS1CycleTime());
    Logger.getRootLogger()
            .info("MS1 average cycle time : " + GetSpectrumParser().GetMS1CycleTime() * 60 + " seconds");

    if (MS1Windows == null || MS1Windows.isEmpty()) {
        //The data has only one MS1 scan set
        ScanCollection scanCollection = GetSpectrumParser().GetAllScanCollectionByMSLabel(true, true, true,
                false, parameter.startRT, parameter.endRT);
        scanCollections.add(scanCollection);
    } else {
        //Get MS1 ScanCollection for each MS1 scan set
        for (XYData window : MS1Windows.keySet()) {
            scanCollections.add(GetSpectrumParser().GetScanCollectionMS1Window(window, true));
        }
    }

    PDHandlerMS1 detection = new PDHandlerMS1(this, NoCPUs, parameter.MS1PPM);
    //Set the flag to tell the program to do targeted peak detection.
    if (parameter.TargetIDOnly) {
        detection.SetTargetedDetectionOnly();
    }

    if (IDsummary != null) {
        //If identifications are present, assign mz-RT for each PSM into targeted peak detection list.
        for (PSM psm : IDsummary.PSMList.values()) {
            for (int i = 0; i < parameter.MinNoPeakCluster; i++) {
                detection.AddToInclusionList(psm.GetObsrIsotopicMz(i), psm.RetentionTime);
            }
        }
        Logger.getRootLogger().info("No. of targeted PSM IDs:" + IDsummary.PSMList.size());
    }
    //Start detect MS1 peak curve and isotope clusters
    detection.DetectPeakClusters(scanCollections);

    //Release scan collection data structure
    scanCollections.clear();
    scanCollections = null;

    //Find closet scan number for each detected isotope peak cluster
    MapScanNoForPeakClusters();

    //Export peak cluster CSV table
    if (ExportPeakClusterTable) {
        ExportPeakClusterResultCSV();
    }

    //Export peak cluster serialization file
    if (SaveSerializationFile) {
        ExportPeakCluster();
    }
}

From source file:gdsc.core.clustering.ClusteringEngine.java

/**
 * Join valid links between clusters. Resets the link candidates.
 * // w  ww . j a  v a  2  s.c o m
 * @param grid
 * @param nXBins
 * @param nYBins
 * @param candidates
 *            Re-populate will all the remaining clusters
 */
private void joinLinks(Cluster[][] grid, int nXBins, int nYBins, ArrayList<Cluster> candidates) {
    candidates.clear();

    for (int yBin = 0; yBin < nYBins; yBin++) {
        for (int xBin = 0; xBin < nXBins; xBin++) {
            for (Cluster c1 = grid[xBin][yBin]; c1 != null; c1 = c1.next) {
                if (c1.validLink()) {
                    c1.add(c1.closest);
                }
                // Reset the link candidates
                c1.closest = null;

                // Store all remaining clusters
                if (c1.n != 0) {
                    candidates.add(c1);
                }
            }

            // Reset the grid
            grid[xBin][yBin] = null;
        }
    }
}