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.gudong.appkit.ui.helper.AppItemAnimator.java

@Override
public void runPendingAnimations() {
    boolean additionsPending = !mPendingAdditions.isEmpty();
    if (!additionsPending) {
        // nothing to animate
        return;/*  ww w  .  j  av  a 2s.  co  m*/
    }
    if (additionsPending) {
        final ArrayList<RecyclerView.ViewHolder> additions = new ArrayList<>();
        additions.addAll(mPendingAdditions);
        mAdditionsList.add(additions);
        mPendingAdditions.clear();

        Runnable adder = new Runnable() {
            @Override
            public void run() {
                for (RecyclerView.ViewHolder holder : additions) {
                    animateAddImpl(holder);
                }
                additions.clear();
                mAdditionsList.remove(additions);
            }
        };
        adder.run();
    }
}

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

/**
 * Returns a list of YWlanRecord objects that describe detected Wireless networks.
 * This list is not updated when the module is already connected to an acces point (infrastructure mode).
 * To force an update of this list, adhocNetwork() must be called to disconnect
 * the module from the current network. The returned list must be unallocated by the caller.
 *
 * @return a list of YWlanRecord objects, containing the SSID, channel,
 *         link quality and the type of security of the wireless network.
 *
 * @throws YAPI_Exception on error//from   w w w .j a  v a2s .  c  o  m
 */
public ArrayList<YWlanRecord> get_detectedWlans() throws YAPI_Exception {
    byte[] json;
    ArrayList<String> wlanlist = new ArrayList<String>();
    ArrayList<YWlanRecord> res = new ArrayList<YWlanRecord>();
    // may throw an exception
    json = _download("wlan.json?by=name");
    wlanlist = _json_get_array(json);
    res.clear();
    for (String ii : wlanlist) {
        res.add(new YWlanRecord(ii));
    }
    return res;
}

From source file:IK.AbstractArmature.java

private void iterateCCD(double dampening, SegmentedArmature chain) {
    AbstractBone currentBone = chain.segmentTip;
    ArrayList<Rot> rotations = new ArrayList<Rot>();

    for (int i = 0; i <= chain.chainLength; i++) {

        rotations.clear();
        /*if(currentBone.constraints != null) { 
           currentBone.constraints.limitingAxes.globalCoords = currentBone.constraints.limitingAxes.relativeTo(currentBone.constraints.limitingAxes.parent.globalCoords);
        }*///w  ww  .j  a va2 s . c om

        for (SegmentedArmature pinnedTarget : chain.pinnedDescendants) {
            Ray currentRay = new Ray(currentBone.getBase(), pinnedTarget.segmentTip.getTip());
            Ray goalRay = new Ray(currentBone.getBase(), pinnedTarget.segmentTip.pinnedTo());
            rotations.add(new Rot(currentRay.heading(), goalRay.heading()));
        }

        Rot rotateToTarget = G.averageRotation(rotations);

        double angle = rotateToTarget.getAngle();
        DVector axis = rotateToTarget.getAxis();

        angle = Math.min(angle, dampening);
        currentBone.rotateBy(new Rot(axis, angle).rotation);

        currentBone.snapToConstraints();
        currentBone = currentBone.parent;

    }
}

From source file:edu.oregonstate.eecs.mcplan.search.fsss.EpsilonGreedyRefinementOrder.java

@Override
protected SubtreeRefinementOrder<S, A> chooseSubtree() {
    if (rng.nextDouble() > epsilon) {
        // Greedy choice of the *2nd-best* action
        final FsssAbstractActionNode<S, A> aan = root.astar_random();
        assert (aan != null);

        final ArrayList<SubtreeRefinementOrder<S, A>> astar = new ArrayList<SubtreeRefinementOrder<S, A>>();
        double ustar = -Double.MAX_VALUE;
        for (final SubtreeRefinementOrder<S, A> subtree : subtrees.values()) {
            final FsssAbstractActionNode<S, A> ai = subtree.rootAction();
            if (ai == aan) {
                // Skip the optimal subtree
                continue;
            }//from  w w w  .java  2  s  .  c  om
            final double u = ai.U();
            if (u > ustar) {
                ustar = u;
                astar.clear();
                astar.add(subtree);
            } else if (u >= ustar) {
                astar.add(subtree);
            }
        }

        final SubtreeRefinementOrder<S, A> subtree = astar.get(rng.nextInt(astar.size()));
        //         System.out.println( "\tEpsilonGreedyRefinementOrder: greedy choice " + subtree.rootAction() );
        return subtree;
    } else {
        // Random choice
        final int choice = rng.nextInt(subtrees.size());
        final Iterator<SubtreeRefinementOrder<S, A>> itr = subtrees.values().iterator();
        for (int i = 0; i < choice; ++i) {
            itr.next();
        }
        final SubtreeRefinementOrder<S, A> subtree = itr.next();
        //         System.out.println( "\tEpsilonGreedyRefinementOrder: random subtree " + subtree.rootAction() );
        return subtree;
    }
}

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

/**
 * @param candidates pre-filtrate//from w  ww .j a v  a  2 s. c  om
 * @return filtered subset
 * forget the compactionSelection if we don't have enough files
 */
private ArrayList<StoreFile> checkMinFilesCriteria(ArrayList<StoreFile> candidates) {
    int minFiles = comConf.getMinFilesToCompact();
    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:de.hshannover.f4.trust.irondetectprocedures.TrendByValueCW.java

/**
 *
 * @param featureSet//from ww  w .j  a  v a2  s. com
 * @param contextSet
 */
@Override
public void train(List<Feature> featureSet, List<Context> contextSet, Calendar startOfTraining,
        Calendar endOfTraining) {
    // sort features by context parameter timestamp
    Collections.sort(featureSet, new FeatureComparatorForCtxp(ContextParamType.DATETIME));
    // get the training time
    int trainingTime = durationInDays(startOfTraining, endOfTraining);
    logger.info("start training on data from  " + trainingTime + " days");

    ArrayList<Feature> tmpList = new ArrayList<Feature>();
    SimpleRegression tmpRegression = new SimpleRegression();
    double tmpSlope = 0;
    Feature tmpFeature;
    double timestamp;

    for (int i = 0; i < (featureSet.size() - freshness); i++) {
        tmpList.clear();
        tmpRegression.clear();

        // get featues equal to freshness size
        for (int j = 0; j < freshness; j++) {
            tmpFeature = featureSet.get(i + j);
            // get timestamp in UNIX time
            ContextParameter contextParam = tmpFeature
                    .getContextParameterByType(new ContextParamType(ContextParamType.DATETIME));
            Calendar cal = Helper.getXsdStringAsCalendar(contextParam.getValue());
            timestamp = cal.getTime().getTime() / 1000L;

            if (this.startTimeStampAvailable == false) {
                setStartTimeStamp((long) timestamp);
            }

            this.x = getDeltaTime((long) timestamp);
            this.y = round(new Double(tmpFeature.getValue()).doubleValue() / 1000);

            // add data and calculate new slope         
            tmpRegression.addData(x, y);
            tmpSlope = tmpRegression.getSlope();
            logger.info("training step: " + tmpSlope);
            if (!Double.isNaN(tmpSlope)) {
                trained = (trained + tmpSlope) / 2;
            }

        }
    }

    this.trainingDone = true;
    logger.info("training was done. value is " + this.trained);
}

From source file:com.facebook.AccessToken.java

AccessToken(Parcel parcel) {
    this.expires = new Date(parcel.readLong());
    ArrayList<String> permissionsList = new ArrayList<>();
    parcel.readStringList(permissionsList);
    this.permissions = Collections.unmodifiableSet(new HashSet<String>(permissionsList));
    permissionsList.clear();
    parcel.readStringList(permissionsList);
    this.declinedPermissions = Collections.unmodifiableSet(new HashSet<String>(permissionsList));
    this.token = parcel.readString();
    this.source = AccessTokenSource.valueOf(parcel.readString());
    this.lastRefresh = new Date(parcel.readLong());
    this.applicationId = parcel.readString();
    this.userId = parcel.readString();
}

From source file:org.jfree.data.jdbc.JDBCXYDataset.java

/**
 * ExecuteQuery will attempt execute the query passed to it against the
 * provided database connection.  If connection is null then no action is
 * taken.//from   www .  j  a v a  2 s  .com
 *
 * The results from the query are extracted and cached locally, thus
 * applying an upper limit on how many rows can be retrieved successfully.
 *
 * @param  query  the query to be executed.
 * @param  con  the connection the query is to be executed against.
 *
 * @throws SQLException if there is a problem executing the query.
 */
public void executeQuery(Connection con, String query) throws SQLException {

    if (con == null) {
        throw new SQLException("There is no database to execute the query.");
    }

    ResultSet resultSet = null;
    Statement statement = null;
    try {
        statement = con.createStatement();
        resultSet = statement.executeQuery(query);
        ResultSetMetaData metaData = resultSet.getMetaData();

        int numberOfColumns = metaData.getColumnCount();
        int numberOfValidColumns = 0;
        int[] columnTypes = new int[numberOfColumns];
        for (int column = 0; column < numberOfColumns; column++) {
            try {
                int type = metaData.getColumnType(column + 1);
                switch (type) {

                case Types.NUMERIC:
                case Types.REAL:
                case Types.INTEGER:
                case Types.DOUBLE:
                case Types.FLOAT:
                case Types.DECIMAL:
                case Types.BIT:
                case Types.DATE:
                case Types.TIME:
                case Types.TIMESTAMP:
                case Types.BIGINT:
                case Types.SMALLINT:
                    ++numberOfValidColumns;
                    columnTypes[column] = type;
                    break;
                default:
                    columnTypes[column] = Types.NULL;
                    break;
                }
            } catch (SQLException e) {
                columnTypes[column] = Types.NULL;
                throw e;
            }
        }

        if (numberOfValidColumns <= 1) {
            throw new SQLException("Not enough valid columns where generated by query.");
        }

        /// First column is X data
        this.columnNames = new String[numberOfValidColumns - 1];
        /// Get the column names and cache them.
        int currentColumn = 0;
        for (int column = 1; column < numberOfColumns; column++) {
            if (columnTypes[column] != Types.NULL) {
                this.columnNames[currentColumn] = metaData.getColumnLabel(column + 1);
                ++currentColumn;
            }
        }

        // Might need to add, to free memory from any previous result sets
        if (this.rows != null) {
            for (int column = 0; column < this.rows.size(); column++) {
                ArrayList row = (ArrayList) this.rows.get(column);
                row.clear();
            }
            this.rows.clear();
        }

        // Are we working with a time series.
        switch (columnTypes[0]) {
        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            this.isTimeSeries = true;
            break;
        default:
            this.isTimeSeries = false;
            break;
        }

        // Get all rows.
        // rows = new ArrayList();
        while (resultSet.next()) {
            ArrayList newRow = new ArrayList();
            for (int column = 0; column < numberOfColumns; column++) {
                Object xObject = resultSet.getObject(column + 1);
                switch (columnTypes[column]) {
                case Types.NUMERIC:
                case Types.REAL:
                case Types.INTEGER:
                case Types.DOUBLE:
                case Types.FLOAT:
                case Types.DECIMAL:
                case Types.BIGINT:
                case Types.SMALLINT:
                    newRow.add(xObject);
                    break;

                case Types.DATE:
                case Types.TIME:
                case Types.TIMESTAMP:
                    newRow.add(new Long(((Date) xObject).getTime()));
                    break;
                case Types.NULL:
                    break;
                default:
                    System.err.println("Unknown data");
                    columnTypes[column] = Types.NULL;
                    break;
                }
            }
            this.rows.add(newRow);
        }

        /// a kludge to make everything work when no rows returned
        if (this.rows.size() == 0) {
            ArrayList newRow = new ArrayList();
            for (int column = 0; column < numberOfColumns; column++) {
                if (columnTypes[column] != Types.NULL) {
                    newRow.add(new Integer(0));
                }
            }
            this.rows.add(newRow);
        }

        /// Determine max and min values.
        if (this.rows.size() < 1) {
            this.maxValue = 0.0;
            this.minValue = 0.0;
        } else {
            ArrayList row = (ArrayList) this.rows.get(0);
            this.maxValue = Double.NEGATIVE_INFINITY;
            this.minValue = Double.POSITIVE_INFINITY;
            for (int rowNum = 0; rowNum < this.rows.size(); ++rowNum) {
                row = (ArrayList) this.rows.get(rowNum);
                for (int column = 1; column < numberOfColumns; column++) {
                    Object testValue = row.get(column);
                    if (testValue != null) {
                        double test = ((Number) testValue).doubleValue();

                        if (test < this.minValue) {
                            this.minValue = test;
                        }
                        if (test > this.maxValue) {
                            this.maxValue = test;
                        }
                    }
                }
            }
        }

        fireDatasetChanged(new DatasetChangeInfo());
        //TODO: fill in real change info
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (Exception e) {
                // TODO: is this a good idea?
            }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (Exception e) {
                // TODO: is this a good idea?
            }
        }
    }

}

From source file:com.facebook.litho.DataFlowTransitionManager.java

private void fireMountItemAnimationCompleteListeners(AnimationState animationState) {
    if (animationState.mountItem == null) {
        return;//w w w  . j a va 2 s.c o  m
    }

    final ArrayList<OnMountItemAnimationComplete> listeners = animationState.mAnimationCompleteListeners;
    for (int i = 0, listenerSize = listeners.size(); i < listenerSize; i++) {
        listeners.get(i).onMountItemAnimationComplete(animationState.mountItem);
    }
    listeners.clear();
}

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

private void updateTvShowFavorites() {
    ArrayList<TvShow> favs = new ArrayList<TvShow>();
    int count = mShows.size();
    for (int i = 0; i < count; i++)
        if (mShows.get(i).isFavorite() && !mTraktFavorites.contains(mShows.get(i).getId()))
            favs.add(mShows.get(i));//from w  ww  .j a  v  a  2  s.c om

    Trakt.tvShowFavorite(favs, this);

    favs.clear();
    favs = null;
}