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:de.fau.cs.osr.hddiff.HDDiff.java

private void buildCompleteChildSeq(DiffNode n, ArrayList<DiffNode> seq) {
    seq.clear();
    for (DiffNode c = n.getFirstChild(); c != null; c = c.getNextSibling())
        seq.add(c);/*from  www  .  j a va 2 s  .c  o  m*/
}

From source file:de.fau.cs.osr.hddiff.HDDiff.java

private void buildUnmatchedChildSeq(DiffNode n, ArrayList<DiffNode> seq) {
    seq.clear();
    for (DiffNode c = n.getFirstChild(); c != null; c = c.getNextSibling()) {
        if (!isMatched(c))
            seq.add(c);/*from w  ww. j  a  va2 s  .co m*/
    }
}

From source file:net.sourceforge.mipa.predicatedetection.lattice.WindowedLatticeChecker.java

private void growLattice(LocalState localState, int id) {
    if (mappedLattice.size() == 0) {
        LocalState[] globalState = new LocalState[children.length];
        String[] index = new String[children.length];
        for (int i = 0; i < children.length; i++) {
            if (i != id) {
                globalState[i] = windowedLocalStateSet.get(i).get(windowedLocalStateSet.get(i).size() - 1);
                index[i] = globalState[i].getID();
            }//from  w w w  .  j av  a  2  s  . c om
        }
        globalState[id] = localState;
        index[id] = localState.getID();
        AbstractLatticeIDNode node = createNode(globalState, index);

        ArrayList<String> setID = new ArrayList<String>();
        ArrayList<AbstractLatticeIDNode> set = new ArrayList<AbstractLatticeIDNode>();
        set.add(node);
        setID.add(StringUtils.join(index, ' '));

        while (!set.isEmpty()) {
            AbstractLatticeIDNode newNode = set.remove(0);
            if (isCGS(newNode)) {
                set.clear();
                setID.clear();
                grow(newNode, id);
                break;
            } else {
                for (int i = 0; i < children.length; i++) {
                    if (i == id) {
                        continue;
                    }
                    index = new String[children.length];
                    globalState = new LocalState[children.length];
                    for (int j = 0; j < children.length; j++) {
                        index[j] = newNode.getID()[j];
                        globalState[j] = newNode.getGlobalState()[j];
                    }
                    index[i] = Integer.toString(Integer.valueOf(index[i]) - 1);
                    if (!setID.contains(StringUtils.join(index, ' ')) && indexIsValid(index, id)) {
                        globalState[i] = localStateSet.get(i).get(Integer.valueOf(index[i]));
                        set.add(createNode(globalState, index));
                        setID.add(StringUtils.join(index, ' '));
                    }
                }
            }
        }
    } else {
        if (maxCGS.getGlobalState()[id]
                .equals(localStateSet.get(id).get(Integer.valueOf(localState.getID()) - 1))) {
            LocalState[] globalState = new LocalState[children.length];
            String[] index = new String[children.length];
            for (int i = 0; i < children.length; i++) {
                if (i != id) {
                    globalState[i] = maxCGS.getGlobalState()[i];
                    index[i] = globalState[i].getID();
                }
            }
            index[id] = localState.getID();
            globalState[id] = localState;
            AbstractLatticeIDNode newNode = createNode(globalState, index);
            if (isCGS(newNode)) {
                grow(newNode, id);
            }
        }
    }
}

From source file:com.erudika.para.persistence.AWSDynamoDAO.java

@Override
public <P extends ParaObject> Map<String, P> readAll(String appid, List<String> keys, boolean getAllColumns) {
    if (keys == null || keys.isEmpty() || StringUtils.isBlank(appid)) {
        return new LinkedHashMap<String, P>();
    }//from   w w w.j  a v  a2  s  .  co m

    Map<String, P> results = new LinkedHashMap<String, P>(keys.size(), 0.75f, true);
    ArrayList<Map<String, AttributeValue>> keyz = new ArrayList<Map<String, AttributeValue>>(MAX_KEYS_PER_READ);

    int batchSteps = 1;
    if ((keys.size() > MAX_KEYS_PER_READ)) {
        batchSteps = (keys.size() / MAX_KEYS_PER_READ) + ((keys.size() % MAX_KEYS_PER_READ > 0) ? 1 : 0);
    }

    Iterator<String> it = keys.iterator();
    int j = 0;

    for (int i = 0; i < batchSteps; i++) {
        while (it.hasNext() && j < MAX_KEYS_PER_READ) {
            String key = it.next();
            results.put(key, null);
            keyz.add(Collections.singletonMap(Config._KEY, new AttributeValue(key)));
            j++;
        }

        KeysAndAttributes kna = new KeysAndAttributes().withKeys(keyz);
        if (!getAllColumns) {
            kna.setAttributesToGet(Arrays.asList(Config._KEY, Config._TYPE));
        }

        batchGet(Collections.singletonMap(getTableNameForAppid(appid), kna), results);
        keyz.clear();
        j = 0;
    }
    logger.debug("DAO.readAll() {}", results.size());
    return results;
}

From source file:de.fau.cs.osr.hddiff.HDDiff.java

private void fillPartnerPath(DiffNode partner, ArrayList<DiffNode> path1) {
    path1.clear();
    DiffNode node = partner;//  w  ww  .  jav a  2 s .  com
    DiffNode parent = node.getParent();
    if (parent != null) {
        node = parent;
        parent = parent.getParent();
        while (parent != null) {
            path1.add(node);
            node = parent;
            parent = parent.getParent();
        }
    }
    Collections.reverse(path1);
}

From source file:com.layer.atlas.AtlasMessagesList.java

public void updateValues() {
    if (conv == null)
        return;/*from  w w  w  .ja  v a  2  s  .  c om*/

    long started = System.currentTimeMillis();

    List<Message> messages = client.getMessages(conv);
    cells.clear();
    if (messages.isEmpty())
        return;

    latestReadMessage = null;
    latestDeliveredMessage = null;

    ArrayList<Cell> messageItems = new ArrayList<AtlasMessagesList.Cell>();
    for (Message message : messages) {
        // System messages have `null` user ID
        if (message.getSender().getUserId() == null)
            continue;

        messageItems.clear();
        buildCellForMessage(message, messageItems);
        cells.addAll(messageItems);
    }

    updateDeliveryStatus(messages);

    // calculate heads/tails
    int currentItem = 0;
    int clusterId = currentItem;
    String currentUser = null;
    long lastMessageTime = 0;
    Calendar calLastMessage = Calendar.getInstance();
    Calendar calCurrent = Calendar.getInstance();
    long clusterTimeSpan = 60 * 1000; // 1 minute
    long oneHourSpan = 60 * 60 * 1000; // 1 hour
    for (int i = 0; i < cells.size(); i++) {
        Cell item = cells.get(i);
        boolean newCluster = false;
        if (!item.messagePart.getMessage().getSender().getUserId().equals(currentUser)) {
            newCluster = true;
        }
        Date sentAt = item.messagePart.getMessage().getSentAt();
        if (sentAt == null)
            sentAt = new Date();

        if (sentAt.getTime() - lastMessageTime > clusterTimeSpan) {
            newCluster = true;
        }

        if (newCluster) {
            clusterId = currentItem;
            if (i > 0)
                cells.get(i - 1).clusterTail = true;
        }

        // check time header is needed
        if (sentAt.getTime() - lastMessageTime > oneHourSpan) {
            item.timeHeader = true;
        }
        calCurrent.setTime(sentAt);
        if (calCurrent.get(Calendar.DAY_OF_YEAR) != calLastMessage.get(Calendar.DAY_OF_YEAR)) {
            item.timeHeader = true;
        }

        item.clusterHeadItemId = clusterId;
        item.clusterItemId = currentItem++;

        currentUser = item.messagePart.getMessage().getSender().getUserId();
        lastMessageTime = sentAt.getTime();
        calLastMessage.setTime(sentAt);
        if (false && debug)
            Log.d(TAG, "updateValues() item: " + item);
    }
    cells.get(cells.size() - 1).clusterTail = true; // last one is always a tail

    if (debug)
        Log.d(TAG, "updateValues() parts finished in: " + (System.currentTimeMillis() - started));
    messagesAdapter.notifyDataSetChanged();

}

From source file:com.ichi2.libanki.Models.java

private Object[] _reqForTemplate(JSONObject m, ArrayList<String> flds, JSONObject t) {
    try {//from  ww w .ja  v  a2s.  c  o m
        ArrayList<String> a = new ArrayList<String>();
        ArrayList<String> b = new ArrayList<String>();
        for (String f : flds) {
            a.add("ankiflag");
            b.add("");
        }
        Object[] data;
        data = new Object[] { 1l, 1l, m.getLong("id"), 1l, t.getInt("ord"), "",
                Utils.joinFields(a.toArray(new String[a.size()])) };
        String full = mCol._renderQA(data).get("q");
        data = new Object[] { 1l, 1l, m.getLong("id"), 1l, t.getInt("ord"), "",
                Utils.joinFields(b.toArray(new String[b.size()])) };
        String empty = mCol._renderQA(data).get("q");
        // if full and empty are the same, the template is invalid and there is no way to satisfy it
        if (full.equals(empty)) {
            return new Object[] { "none", new JSONArray(), new JSONArray() };
        }
        String type = "all";
        JSONArray req = new JSONArray();
        ArrayList<String> tmp = new ArrayList<String>();
        for (int i = 0; i < flds.size(); i++) {
            tmp.clear();
            tmp.addAll(a);
            tmp.set(i, "");
            data[6] = Utils.joinFields(tmp.toArray(new String[tmp.size()]));
            // if no field content appeared, field is required
            if (!mCol._renderQA(data).get("q").contains("ankiflag")) {
                req.put(i);
            }
        }
        if (req.length() > 0) {
            return new Object[] { type, req };
        }
        // if there are no required fields, switch to any mode
        type = "any";
        req = new JSONArray();
        for (int i = 0; i < flds.size(); i++) {
            tmp.clear();
            tmp.addAll(b);
            tmp.set(i, "1");
            data[6] = Utils.joinFields(tmp.toArray(new String[tmp.size()]));
            // if not the same as empty, this field can make the card non-blank
            if (!mCol._renderQA(data).get("q").equals(empty)) {
                req.put(i);
            }
        }
        return new Object[] { type, req };
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.camel.component.olingo2.api.impl.Olingo2AppImpl.java

private ODataResponse parseBatchRequest(final Edm edm, final List<Olingo2BatchRequest> batchParts)
        throws IOException, EntityProviderException, ODataApplicationException, EdmException,
        URISyntaxException {/*from www .ja va  2  s .co  m*/

    // create Batch request from parts
    final ArrayList<BatchPart> parts = new ArrayList<BatchPart>();
    final ArrayList<BatchChangeSetPart> changeSetParts = new ArrayList<BatchChangeSetPart>();

    final Map<String, String> contentIdMap = new HashMap<String, String>();

    for (Olingo2BatchRequest batchPart : batchParts) {

        if (batchPart instanceof Olingo2BatchQueryRequest) {

            // need to add change set parts collected so far??
            if (!changeSetParts.isEmpty()) {
                addChangeSetParts(parts, changeSetParts);
                changeSetParts.clear();
                contentIdMap.clear();
            }

            // add to request parts
            final UriInfoWithType uriInfo = parseUri(edm, batchPart.getResourcePath(), null);
            parts.add(createBatchQueryPart(uriInfo, (Olingo2BatchQueryRequest) batchPart));

        } else {

            // add to change set parts
            final BatchChangeSetPart changeSetPart = createBatchChangeSetPart(edm, contentIdMap,
                    (Olingo2BatchChangeRequest) batchPart);
            changeSetParts.add(changeSetPart);
        }
    }

    // add any remaining change set parts
    if (!changeSetParts.isEmpty()) {
        addChangeSetParts(parts, changeSetParts);
    }

    final String boundary = BOUNDARY_PREFIX + UUID.randomUUID();
    InputStream batchRequest = EntityProvider.writeBatchRequest(parts, boundary);
    // add two blank lines before all --batch boundaries
    // otherwise Olingo2 EntityProvider parser barfs in the server!!!
    final byte[] bytes = EntityProvider.readBinary(batchRequest);
    final String batchRequestBody = new String(bytes, Consts.UTF_8);
    batchRequest = new ByteArrayInputStream(
            batchRequestBody.replaceAll("--(batch_)", "\r\n\r\n--$1").getBytes(Consts.UTF_8));

    final String contentHeader = BATCH_CONTENT_TYPE + BOUNDARY_PARAMETER + boundary;
    return ODataResponse.entity(batchRequest).contentHeader(contentHeader).build();
}

From source file:com.mifos.mifosxdroid.online.SurveyQuestion.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setContentView(R.layout.activity_survey_question);
    context = SurveyQuestion.this;
    myPreference = new MyPreference();
    myPreference.resetScorecard(this);
    btnNext = (Button) findViewById(R.id.btnNext);

    fragments = new Vector<Fragment>();

    Intent mIntent = getIntent();//from ww  w.  j ava2 s .  co m
    surveyId = mIntent.getIntExtra("SurveyId", 0);
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor edt = sharedPreferences.edit();
    edt.putInt("SURVEY_ID", surveyId);
    edt.commit();

    ((MifosApplication) this.getApplication()).api.surveyService.getSurvey(surveyId, new Callback<Survey>() {
        @Override
        public void success(final Survey survey, Response response) {

            if (survey != null) {

                String answer[] = new String[10];

                ArrayList<String> answerList = new ArrayList<String>();

                if (survey.getQuestionDatas() != null && survey.getQuestionDatas().size() > 0) {
                    for (int i = 0; i < survey.getQuestionDatas().size(); i++) {
                        qs = survey.getQuestionDatas().get(i).getText();
                        qid = survey.getQuestionDatas().get(i).getQuestionId();
                        if (survey.getQuestionDatas().get(i).getResponseDatas().size() > 0) {
                            for (int j = 0; j < survey.getQuestionDatas().get(i).getResponseDatas()
                                    .size(); j++) {
                                answer[j] = survey.getQuestionDatas().get(i).getResponseDatas().get(j)
                                        .getText();

                                answerList.add(answer[j]);
                            }

                        }

                        String[] answerArr = new String[answerList.size()];
                        answerArr = answerList.toArray(answerArr);
                        fragments.add(SurveyQuestionFragment.newInstance(i, qs, surveyId, answerArr));
                        answerList.clear();
                    }

                    fragments.add(SurveyLastFragment.newInstance(1, "You have reached the end of Survey"));
                    mPagerAdapter.notifyDataSetChanged();

                }

            }

        }

        @Override
        public void failure(RetrofitError retrofitError) {
            Toast.makeText(SurveyQuestion.this, "Survey not found.", Toast.LENGTH_SHORT).show();

        }
    });

    this.mPagerAdapter = new SurveyPagerAdapter(super.getSupportFragmentManager(), fragments);

    pager = (ViewPager) super.findViewById(R.id.surveyPager);

    pager.setAdapter(this.mPagerAdapter);

    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {

            if (pager.getCurrentItem() == mPagerAdapter.getCount() - 1) {
                btnNext.setVisibility(View.GONE);
            }
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            if (pager.getCurrentItem() == mPagerAdapter.getCount() - 1) {
                btnNext.setVisibility(View.GONE);
            }

        }

        @Override
        public void onPageScrollStateChanged(int state) {
            // Called when the scroll state changes:
            // SCROLL_STATE_IDLE, SCROLL_STATE_DRAGGING, SCROLL_STATE_SETTLING
        }

    });
    Button btnNext = (Button) findViewById(R.id.btnNext);
    btnNext.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (fragmentCommunicator != null)
                fragmentCommunicator.passDataToFragment(pfqid, pfrid, pfrvalue);
            int current = pager.getCurrentItem();

            if (current < fragments.size())
                pager.setCurrentItem(current + 1, true);

        }
    });

}

From source file:com.homechart.app.recyclerlibrary.anims.animators.BaseItemAnimator.java

@Override
public void runPendingAnimations() {
    boolean removalsPending = !mPendingRemovals.isEmpty();
    boolean movesPending = !mPendingMoves.isEmpty();
    boolean changesPending = !mPendingChanges.isEmpty();
    boolean additionsPending = !mPendingAdditions.isEmpty();
    if (!removalsPending && !movesPending && !additionsPending && !changesPending) {
        // nothing to animate
        return;//from  ww  w. j a v a2 s  .  c o  m
    }
    // First, remove stuff
    for (ViewHolder holder : mPendingRemovals) {
        doAnimateRemove(holder);
    }
    mPendingRemovals.clear();
    // Next, move stuff
    if (movesPending) {
        final ArrayList<MoveInfo> moves = new ArrayList<MoveInfo>();
        moves.addAll(mPendingMoves);
        mMovesList.add(moves);
        mPendingMoves.clear();
        Runnable mover = new Runnable() {
            @Override
            public void run() {
                boolean removed = mMovesList.remove(moves);
                if (!removed) {
                    // already canceled
                    return;
                }
                for (MoveInfo moveInfo : moves) {
                    animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX,
                            moveInfo.toY);
                }
                moves.clear();
            }
        };
        if (removalsPending) {
            View view = moves.get(0).holder.itemView;
            ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration());
        } else {
            mover.run();
        }
    }
    // Next, change stuff, to run in parallel with move animations
    if (changesPending) {
        final ArrayList<ChangeInfo> changes = new ArrayList<ChangeInfo>();
        changes.addAll(mPendingChanges);
        mChangesList.add(changes);
        mPendingChanges.clear();
        Runnable changer = new Runnable() {
            @Override
            public void run() {
                boolean removed = mChangesList.remove(changes);
                if (!removed) {
                    // already canceled
                    return;
                }
                for (ChangeInfo change : changes) {
                    animateChangeImpl(change);
                }
                changes.clear();
            }
        };
        if (removalsPending) {
            ViewHolder holder = changes.get(0).oldHolder;
            ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration());
        } else {
            changer.run();
        }
    }
    // Next, add stuff
    if (additionsPending) {
        final ArrayList<ViewHolder> additions = new ArrayList<ViewHolder>();
        additions.addAll(mPendingAdditions);
        mAdditionsList.add(additions);
        mPendingAdditions.clear();
        Runnable adder = new Runnable() {
            public void run() {
                boolean removed = mAdditionsList.remove(additions);
                if (!removed) {
                    // already canceled
                    return;
                }
                for (ViewHolder holder : additions) {
                    doAnimateAdd(holder);
                }
                additions.clear();
            }
        };
        if (removalsPending || movesPending || changesPending) {
            long removeDuration = removalsPending ? getRemoveDuration() : 0;
            long moveDuration = movesPending ? getMoveDuration() : 0;
            long changeDuration = changesPending ? getChangeDuration() : 0;
            long totalDelay = removeDuration + Math.max(moveDuration, changeDuration);
            View view = additions.get(0).itemView;
            ViewCompat.postOnAnimationDelayed(view, adder, totalDelay);
        } else {
            adder.run();
        }
    }
}