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:org.alfresco.repo.tagging.UpdateTagScopesQuartzJob.java

protected void execute(final ActionService actionService,
        final UpdateTagScopesActionExecuter updateTagsAction) {
    // Process// ww w .j a v a  2s.com
    final ArrayList<NodeRef> tagNodes = new ArrayList<NodeRef>();
    final HashSet<NodeRef> handledTagNodes = new HashSet<NodeRef>();

    while (true) {
        // Fetch a batch of the pending changes
        AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>() {
            public Void doWork() throws Exception {
                tagNodes.clear();
                tagNodes.addAll(updateTagsAction.searchForTagScopesPendingUpdates());
                return null;
            }
        }, AuthenticationUtil.getSystemUserName());

        // If we're on our 2nd loop round for any of them, then skip them from now on
        // (This can happen if another thread is already processing one of them)
        Iterator<NodeRef> it = tagNodes.iterator();
        while (it.hasNext()) {
            NodeRef nodeRef = it.next();
            if (handledTagNodes.contains(nodeRef)) {
                it.remove();
                if (logger.isDebugEnabled())
                    logger.debug("Tag scope " + nodeRef
                            + " must be being processed by another Thread, not updating it");
            }
        }

        // Log what we found to process
        if (logger.isDebugEnabled()) {
            logger.debug("Checked for tag scopes with pending tag updates, found " + tagNodes);
        }

        // If we're out of tag scopes, stop!
        if (tagNodes.size() == 0)
            break;

        // Have the action run for these tag scope nodes
        // Needs to run synchronously
        Action action = actionService.createAction(UpdateTagScopesActionExecuter.NAME);
        action.setParameterValue(UpdateTagScopesActionExecuter.PARAM_TAG_SCOPES, (Serializable) tagNodes);
        actionService.executeAction(action, null, false, false);

        // Record the scopes we've just done
        handledTagNodes.addAll(tagNodes);
    }
}

From source file:edu.upenn.cis.FastAlign.java

/**
 * Populates source and target token lists with integerized tokens.
 * //from   w w w. j a  va 2 s  . c  om
 * @param line  a line of the bitext
 * @param src  the list to be populated with source tokens
 * @param tgt  the list to be populated with target tokens
 */
private void ParseLine(final String line, ArrayList<Integer> src, ArrayList<Integer> trg) {
    final int kDIV = d.Convert("|||");
    ArrayList<Integer> tmp = new ArrayList<Integer>();
    src.clear();
    trg.clear();
    d.ConvertWhitespaceDelimitedLine(line, tmp);
    int i = 0;
    while (i < tmp.size() && tmp.get(i) != kDIV) {
        src.add(tmp.get(i));
        ++i;
    }
    if (i < tmp.size() && tmp.get(i) == kDIV) {
        ++i;
        for (; i < tmp.size(); ++i)
            trg.add(tmp.get(i));
    }
}

From source file:com.yoctopuce.YoctoAPI.YFiles.java

/**
 * Returns a list of YFileRecord objects that describe files currently loaded
 * in the filesystem./*from w  w w  .ja  v a2  s . c  om*/
 *
 * @param pattern : an optional filter pattern, using star and question marks
 *         as wildcards. When an empty pattern is provided, all file records
 *         are returned.
 *
 * @return a list of YFileRecord objects, containing the file path
 *         and name, byte size and 32-bit CRC of the file content.
 *
 * @throws YAPI_Exception on error
 */
public ArrayList<YFileRecord> get_list(String pattern) throws YAPI_Exception {
    byte[] json;
    ArrayList<String> filelist = new ArrayList<String>();
    ArrayList<YFileRecord> res = new ArrayList<YFileRecord>();
    json = sendCommand(String.format("dir&f=%s", pattern));
    filelist = _json_get_array(json);
    res.clear();
    for (String ii : filelist) {
        res.add(new YFileRecord(ii));
    }
    return res;
}

From source file:net.micode.fileexplorer.FileViewActivity.java

public boolean onRefreshFileList(String path, FileSortHelper sort) {
    File file = new File(path);
    if (!file.exists() || !file.isDirectory()) {
        return false;
    }/*  w w  w  . j a  va  2  s  . c om*/
    final int pos = computeScrollPosition(path);
    ArrayList<FileInfo> fileList = mFileNameList;
    fileList.clear();

    File[] listFiles = file.listFiles(mFileCagetoryHelper.getFilter());
    if (listFiles == null)
        return true;

    for (File child : listFiles) {
        // do not show selected file if in move state
        if (mFileViewInteractionHub.isMoveState() && mFileViewInteractionHub.isFileSelected(child.getPath()))
            continue;

        String absolutePath = child.getAbsolutePath();
        if (Util.isNormalFile(absolutePath) && Util.shouldShowFile(absolutePath)) {
            FileInfo lFileInfo = Util.GetFileInfo(child, mFileCagetoryHelper.getFilter(),
                    Settings.instance().getShowDotAndHiddenFiles());
            if (lFileInfo != null) {
                fileList.add(lFileInfo);
            }
        }
    }

    sortCurrentList(sort);
    showEmptyView(fileList.size() == 0);
    mFileListView.post(new Runnable() {
        @Override
        public void run() {
            mFileListView.setSelection(pos);
        }
    });
    return true;
}

From source file:org.apache.hadoop.hbase.regionserver.compactions.SortedCompactionPolicy.java

/**
 * @param candidates pre-filtrate/*ww w .  ja v a 2  s . c o  m*/
 * @return filtered subset forget the compactionSelection if we don't have enough files
 */
protected ArrayList<StoreFile> checkMinFilesCriteria(ArrayList<StoreFile> candidates, int minFiles) {
    if (candidates.size() < minFiles) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Not compacting files because we only have " + candidates.size()
                    + " files ready for compaction. Need " + minFiles + " to initiate.");
        }
        candidates.clear();
    }
    return candidates;
}

From source file:com.utdallas.s3lab.smvhunter.monkey.LogcatMonitor.java

@Override
public void run() {

    //monitor the logcat for analysis
    Process pr = null;//from  w w  w  . j av  a2  s .c  o  m
    try {
        pr = NetworkMonitor
                .execCommand(String.format(LOGCAT, WindowUpdate.adbLocation, device.getSerialNumber()));
        BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream()));
        String s = null;

        ArrayList<String> tmpList = new ArrayList<String>();
        while ((s = br.readLine()) != null) {
            String forPrinting = NetworkMonitor.getStringforPrinting(device.getSerialNumber(),
                    System.currentTimeMillis(), s);
            tmpList.add(forPrinting);

            //write every 100 lines
            if (tmpList.size() == 100) {
                FileUtils.writeLines(new File(MonkeyMe.logCatLocation), tmpList, true);
                tmpList.clear();
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (pr != null) {
            pr.destroy();
        }
    }
}

From source file:edu.ucdenver.bios.power.ConditionalOrthogonalPolynomial3FactorTest.java

/**
 * Test GLMM(F) with 1,2, and 3 Factor polynomial
 * contrasts in C and U matrices/*from   w w  w.ja v  a 2 s. c  o m*/
 */
@Test
public void testOneToThreeFactorPolynomialContrasts() {
    // set up the matrices
    GLMMPowerParameters params = buildInputsWithoutContrasts();
    // run over all tests
    boolean first = true;
    for (GLMMTestFactory.Test test : GLMMTestFactory.Test.values()) {
        params.clearTestList();
        params.addTest(test);
        // calculate all of the 3 factor polynomial contrasts
        ArrayList<Factor> withinFactorList = new ArrayList<Factor>();
        withinFactorList.add(factorD);
        withinFactorList.add(factorE);
        withinFactorList.add(factorF);
        ArrayList<Factor> betweenFactorList = new ArrayList<Factor>();
        betweenFactorList.add(factorA);
        betweenFactorList.add(factorB);
        betweenFactorList.add(factorC);
        OrthogonalPolynomialContrastCollection withinSubjectContrasts = OrthogonalPolynomials
                .withinSubjectContrast(withinFactorList);
        OrthogonalPolynomialContrastCollection betweenSubjectContrasts = OrthogonalPolynomials
                .betweenSubjectContrast(betweenFactorList);
        // run power for 1 factor contrasts
        RealMatrix U = withinSubjectContrasts.getMainEffectContrast(factorD).getContrastMatrix();
        RealMatrix C = betweenSubjectContrasts.getMainEffectContrast(factorA).getContrastMatrix();
        RealMatrix thetaNull = MatrixUtils.getRealMatrixWithFilledValue(C.getRowDimension(),
                U.getColumnDimension(), 0);
        params.setWithinSubjectContrast(U);
        params.setBetweenSubjectContrast(new FixedRandomMatrix(C.getData(), null, true));
        params.setTheta(thetaNull);
        checker.checkPower(params);
        if (first) {
            matrixAltStringBuffer
                    .append("\\newpage\\textbf{Contrasts for the test of the A x D interaction}\n\n");
            appendMatrix("\\mathbf{C}'", C.transpose());
            appendMatrix("\\mathbf{U}", U);
        }
        // run power for 2 factor contrasts
        ArrayList<Factor> intFactors = new ArrayList<Factor>();
        intFactors.add(factorD);
        intFactors.add(factorE);
        U = withinSubjectContrasts.getInteractionContrast(intFactors).getContrastMatrix();
        intFactors.clear();
        intFactors.add(factorA);
        intFactors.add(factorB);
        C = betweenSubjectContrasts.getInteractionContrast(intFactors).getContrastMatrix();
        thetaNull = MatrixUtils.getRealMatrixWithFilledValue(C.getRowDimension(), U.getColumnDimension(), 0);
        params.setWithinSubjectContrast(U);
        params.setBetweenSubjectContrast(new FixedRandomMatrix(C.getData(), null, true));
        params.setTheta(thetaNull);
        checker.checkPower(params);
        if (first) {
            matrixAltStringBuffer
                    .append("\\newpage\\textbf{Contrasts for the test of the A x B x D x E interaction}\n\n");
            appendMatrix("\\mathbf{C}'", C.transpose());
            appendMatrix("\\mathbf{U}", U);
        }

        // run power for 3 factor contrasts
        intFactors.clear();
        intFactors.add(factorD);
        intFactors.add(factorE);
        intFactors.add(factorF);
        U = withinSubjectContrasts.getInteractionContrast(intFactors).getContrastMatrix();
        intFactors.clear();
        intFactors.add(factorA);
        intFactors.add(factorB);
        intFactors.add(factorC);
        C = betweenSubjectContrasts.getInteractionContrast(intFactors).getContrastMatrix();
        thetaNull = MatrixUtils.getRealMatrixWithFilledValue(C.getRowDimension(), U.getColumnDimension(), 0);
        params.setWithinSubjectContrast(U);
        params.setBetweenSubjectContrast(new FixedRandomMatrix(C.getData(), null, true));
        params.setTheta(thetaNull);
        checker.checkPower(params);
        if (first) {
            matrixAltStringBuffer.append(
                    "\\newpage\\textbf{Contrasts for the test of the A x B x C x D x E x F interaction}\n\n");
            appendMatrix("\\mathbf{C}'", C.transpose());
            appendMatrix("\\mathbf{U}", U);
            first = false;
        }
    }

    // output the results

    // we reset the tests to include all
    params.clearTestList();
    for (GLMMTestFactory.Test test : GLMMTestFactory.Test.values()) {
        params.addTest(test);
    }
    ValidationReportBuilder reportBuilder = new ValidationReportBuilder();
    reportBuilder.createValidationReportAsStdout(checker, TITLE, false);
    assertTrue("results outside tolerance: " + TOLERANCE, checker.isSASDeviationBelowTolerance(TOLERANCE));
}

From source file:com.yoctopuce.YoctoAPI.YSensor.java

static int _decodeCalibrationPoints(String calibParams, ArrayList<Integer> intPt, ArrayList<Double> rawPt,
        ArrayList<Double> calPt) throws YAPI_Exception {

    intPt.clear();
    rawPt.clear();/*w w  w .j a va  2 s  . c  o  m*/
    calPt.clear();
    if (calibParams.equals("") || calibParams.equals("0")) {
        // old format: no calibration
        return 0;
    }
    if (calibParams.indexOf(',') != -1) {
        // old format -> device must do the calibration
        return -1;
    }
    // new format
    ArrayList<Integer> iCalib = YAPI._decodeWords(calibParams);
    if (iCalib.size() < 2) {
        // bad format
        return -1;
    }
    if (iCalib.size() == 2) {
        // no calibration
        return 0;
    }
    int pos = 0;
    double calibrationOffset = iCalib.get(pos++);
    double divisor = iCalib.get(pos++);
    int calibType = iCalib.get(pos++);
    if (calibType == 0) {
        return 0;
    }
    // parse calibration parameters
    while (pos < iCalib.size()) {
        int ival = iCalib.get(pos++);
        double fval;
        if (calibType <= 10) {
            fval = (ival + calibrationOffset) / divisor;
        } else {
            fval = YAPI._decimalToDouble(ival);
        }
        intPt.add(ival);
        if ((intPt.size() & 1) == 1) {
            rawPt.add(fval);
        } else {
            calPt.add(fval);
        }
    }
    if (intPt.size() < 10) {
        return -1;
    }
    return calibType;
}

From source file:com.ultramegasoft.flavordex2.fragment.ViewPhotosFragment.java

@Override
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor data) {
    final ArrayList<PhotoHolder> photos = getPhotos();
    photos.clear();
    long id;/*  w  ww  . j a v a 2s .  c o  m*/
    String hash;
    String path;
    int pos;
    Uri uri;
    while (data.moveToNext()) {
        id = data.getLong(data.getColumnIndex(Tables.Photos._ID));
        hash = data.getString(data.getColumnIndex(Tables.Photos.HASH));
        path = data.getString(data.getColumnIndex(Tables.Photos.PATH));
        pos = data.getInt(data.getColumnIndex(Tables.Photos.POS));
        uri = PhotoUtils.parsePath(path);
        if (uri != null) {
            photos.add(new PhotoHolder(id, hash, uri, pos));
        }
    }

    notifyDataChanged();

    getLoaderManager().destroyLoader(0);
}

From source file:net.sourceforge.ondex.cytoscape.task.ScanForKeysTask.java

/**
 * starts the task./*from ww w.  ja  v  a2 s  .co  m*/
 */
public void run() {
    monitor.setPercentCompleted(0);
    monitor.setStatus("scanning...");

    CyAttributes nodeAtts = Cytoscape.getNodeAttributes();
    String[] ans = nodeAtts.getAttributeNames();

    HashMap<String, HashMap<String, String>> anMap = new HashMap<String, HashMap<String, String>>();
    for (String an : ans) {
        anMap.put(an, new HashMap<String, String>());
    }

    Map<String, Integer> counts = LazyMap.decorate(new HashMap<String, Integer>(), new Factory<Integer>() {
        @Override
        public Integer create() {
            return Integer.valueOf(0);
        }
    });

    ArrayList<String> clashedANs = new ArrayList<String>();
    ArrayList<String> remainingANs = new ArrayList<String>();
    for (String an : ans) {
        remainingANs.add(an);
    }

    int[] index = network.getNodeIndicesArray();
    for (int i = 0; i < index.length; i++) {
        String nodeId = network.getNode(index[i]).getIdentifier();
        clashedANs.clear();
        for (String an : remainingANs) {
            Object val = nodeAtts.getAttribute(nodeId, an);
            if (val != null && val instanceof String) {
                String sval = (String) val;

                int oldcount = counts.get(an);
                counts.put(an, oldcount + 1);

                HashMap<String, String> map = anMap.get(an);
                if (map.get(sval) == null) {
                    map.put(sval, nodeId);
                } else {//an has clashes!
                    clashedANs.add(an);
                }
            }
        }
        remainingANs.removeAll(clashedANs);
        if (remainingANs.size() == 0) {
            break;
        }
        monitor.setPercentCompleted((i * 100) / index.length);
    }

    for (String an : ans) {
        if (counts.get(an) == 0) {
            remainingANs.remove(an);
        }
    }

    monitor.setPercentCompleted(100);
    monitor.setStatus("done");

    keys = remainingANs;
}