Example usage for java.util ArrayList set

List of usage examples for java.util ArrayList set

Introduction

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

Prototype

public E set(int index, E element) 

Source Link

Document

Replaces the element at the specified position in this list with the specified element.

Usage

From source file:org.sakaiproject.tool.assessment.shared.impl.questionpool.QuestionPoolServiceImpl.java

public String getUserPoolAttachmentReport(String userId, Long poolId, String contextToReplace) {
    String parsedText = null;//w w  w  . j  a  v  a 2 s. com
    UserPoolAttachmentReport upar = new UserPoolAttachmentReport();

    boolean flagQuestionPoolUpdated = false;
    boolean flagTextUpdated = false;
    boolean flagAttachmentUpdated = false;
    boolean flagAnswerUpdated = false;

    ItemService itemService = new ItemService();

    //Get user's pool with questions.
    //QuestionPoolFacade qpf = this.getPool(poolId, userId);
    QuestionPoolDataIfc qpf = this.getPool(poolId, userId);

    if (qpf == null) {
        upar.addToReport("POOL ID: " + poolId + " NOT FOUND IN USER " + userId + ".");
        return upar.toString();
    }
    upar.addToReport("POOL ---> " + qpf.getTitle() + " - POOL ID: " + qpf.getQuestionPoolId() + "\n\n");

    Iterator iter = this.getAllItems(poolId).iterator();

    while (iter.hasNext()) {
        ItemFacade itemData = (ItemFacade) iter.next();

        //Parsing the question text looking for embedded attachments.
        Set misItemText = itemData.getItemTextSet();

        HashSet newItemTextSet = new HashSet(); //Modified question text.
        HashSet newAnswerSet = new HashSet(); //Modified answers text.

        Iterator itemTextIter = misItemText.iterator();
        while (itemTextIter.hasNext()) {
            //Looking for bad attachments in question text.
            ItemText iti = (ItemText) itemTextIter.next();
            upar.addToReport("Question Text ---> " + iti.getText() + "\n");

            parsedText = upar.findAttachmentsInText(iti.getText(), contextToReplace);
            if (!parsedText.equals(iti.getText())) {
                flagTextUpdated = true;
                iti.setText(parsedText);
            }

            //Looking for bad attachments in question text.
            Set myAnswerSet = iti.getAnswerSet();
            Iterator answerIter = myAnswerSet.iterator();
            while (answerIter.hasNext()) {
                Answer myAnswer = (Answer) answerIter.next();
                parsedText = upar.findAttachmentsInText(myAnswer.getText(), contextToReplace);
                if (!parsedText.equals(myAnswer.getText())) {
                    flagAnswerUpdated = flagTextUpdated = true;
                    myAnswer.setText(parsedText);
                }
                newAnswerSet.add(myAnswer);
            }

            if (flagAnswerUpdated)
                iti.setAnswerSet(newAnswerSet);
            flagAnswerUpdated = false;

            newItemTextSet.add(iti);
        }
        if (flagTextUpdated)
            itemData.setItemTextSet(newItemTextSet);

        //Looking for bad attachments in question's attachments (out of CKEditor).
        StringBuilder uploadedAttachments = new StringBuilder();
        ArrayList misAttachments = (ArrayList<ItemAttachmentIfc>) itemData.getItemAttachmentList();
        if (misAttachments.size() > 0)
            upar.addToReport("\nFound " + misAttachments.size() + " uploaded attachments in the question.\n\n");
        for (int i = 0; i < misAttachments.size(); i++) {
            ItemAttachmentIfc ia = (ItemAttachmentIfc) misAttachments.get(i);
            //uploadedAttachments.append("src=\""+ia.getLocation()+"\" ");
            parsedText = upar.replaceAttachment(ia.getLocation(), contextToReplace);
            if (!parsedText.equals(ia.getLocation())) {
                flagAttachmentUpdated = true;
                ia.setLocation(parsedText);
                misAttachments.set(i, ia);
            }
        }
        if (flagAttachmentUpdated)
            itemData.setItemAttachmentSet(new HashSet(misAttachments));

        if (flagTextUpdated || flagAttachmentUpdated) {
            flagQuestionPoolUpdated = true;
            itemService.saveItem(itemData);
        }

        flagTextUpdated = false;
        flagAttachmentUpdated = false;
    }
    if (flagQuestionPoolUpdated)
        this.savePool(qpf);
    return upar.getReport();
}

From source file:edu.oregonstate.eecs.mcplan.util.Fn.java

public static <T> ArrayList<T> memcpy(final ArrayList<T> dest, final ArrayList<T> src) {
    assert (dest.size() == src.size());
    for (int i = 0; i < dest.size(); ++i) {
        dest.set(i, src.get(i));
    }//w w w.  j  av  a 2 s .  c  o  m
    return dest;
}

From source file:org.apache.hive.hcatalog.templeton.HiveDelegator.java

private List<String> makeBasicArgs(String execute, String srcFile, String otherFiles, String statusdir,
        String completedUrl, boolean enablelog, Boolean enableJobReconnect)
        throws URISyntaxException, IOException, InterruptedException {
    ArrayList<String> args = new ArrayList<String>();

    ArrayList<String> allFiles = new ArrayList<String>();
    if (TempletonUtils.isset(srcFile)) {
        allFiles.add(TempletonUtils.hadoopFsFilename(srcFile, appConf, runAs));
    }/* www .j  av a  2 s.  co m*/

    if (TempletonUtils.isset(otherFiles)) {
        String[] ofs = TempletonUtils.hadoopFsListAsArray(otherFiles, appConf, runAs);
        allFiles.addAll(Arrays.asList(ofs));
    }

    args.addAll(makeLauncherArgs(appConf, statusdir, completedUrl, allFiles, enablelog, enableJobReconnect,
            JobType.HIVE));

    if (appConf.hiveArchive() != null && !appConf.hiveArchive().equals("")) {
        args.add(ARCHIVES);
        args.add(appConf.hiveArchive());
    }

    //ship additional artifacts, for example for Tez
    String extras = appConf.get(AppConfig.HIVE_EXTRA_FILES);
    if (extras != null && extras.length() > 0) {
        boolean foundFiles = false;
        for (int i = 0; i < args.size(); i++) {
            if (FILES.equals(args.get(i))) {
                String value = args.get(i + 1);
                args.set(i + 1, value + "," + extras);
                foundFiles = true;
            }
        }
        if (!foundFiles) {
            args.add(FILES);
            args.add(extras);
        }
        String[] extraFiles = appConf.getStrings(AppConfig.HIVE_EXTRA_FILES);
        StringBuilder extraFileNames = new StringBuilder();
        //now tell LaunchMapper which files it should add to HADOOP_CLASSPATH
        for (String file : extraFiles) {
            Path p = new Path(file);
            extraFileNames.append(p.getName()).append(",");
        }
        addDef(args, JobSubmissionConstants.HADOOP_CLASSPATH_EXTRAS, extraFileNames.toString());
    }
    return args;
}

From source file:com.aegiswallet.actions.CurrencyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.currency_view);

    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    getActionBar().setCustomView(R.layout.aegis_send_actionbar);

    TextView titleTextView = (TextView) findViewById(R.id.action_bar_title_text);
    titleTextView.setText(getString(R.string.currencies_activity_label));

    ImageButton backButton = (ImageButton) findViewById(R.id.action_bar_icon_back);
    backButton.setOnClickListener(new View.OnClickListener() {
        @Override//from   w ww. j a v  a 2 s.co m
        public void onClick(View view) {
            Intent openMainActivity = new Intent(context, MainActivity.class);
            openMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            context.startActivity(openMainActivity);
            finish();
        }
    });

    ArrayList<CurrencyPojo> currencies = new ArrayList<CurrencyPojo>();

    JSONObject jsonObject = BasicUtils.parseJSONData(getApplicationContext(),
            Constants.BLOCKCHAIN_CURRENCY_FILE_NAME);

    if (jsonObject != null) {

        Iterator i = jsonObject.keys();
        while (i.hasNext()) {

            try {
                String currency = (String) i.next();
                JSONObject detailObj = jsonObject.getJSONObject(currency);
                CurrencyPojo newPojo = new CurrencyPojo(currency, detailObj.getDouble("last"),
                        detailObj.getString("symbol"));

                currencies.add(newPojo);
            } catch (JSONException e) {
                Log.e("Currency Activity", "JSON Exception " + e.getMessage());
            }
        }

        String currentCurrency = prefs.getString(Constants.CURRENCY_PREF_KEY, null);
        CurrencyPojo firstPojo = currencies.get(0);

        for (int j = 0; j < currencies.size(); j++) {
            CurrencyPojo pojo = currencies.get(j);
            if (pojo.getCurrency().equals(currentCurrency)) {
                currencies.set(0, pojo);
                currencies.set(j, firstPojo);
            }
        }

    }

    CurrencyAdapter currencyAdapter = new CurrencyAdapter(this, R.layout.currency_list_item, currencies, prefs);

    ListView transactionListView = (ListView) findViewById(R.id.currency_list);
    transactionListView.setAdapter(currencyAdapter);

}

From source file:edu.oregonstate.eecs.mcplan.util.Fn.java

/**
 * Fisher-Yates shuffle. This version does only 'n' swaps, so the first
 * 'n' elements of the array will be randomly selected from among the
 * entire array./*from w w w. j  av a 2  s . co  m*/
 * @param rng
 * @param a
 */
public static <T> void shuffle(final RandomGenerator rng, final ArrayList<T> a, final int n) {
    for (int i = 0; i < n; ++i) {
        final int j = i + rng.nextInt(n - i);
        final T temp = a.get(j);
        a.set(j, a.get(i));
        a.set(i, temp);
    }
}

From source file:edu.upenn.ircs.lignos.morsel.MorphLearner.java

private void incrementalScoreTransforms(ArrayList<Transform> hypTransforms,
        Map<String, Transform> indexedTransforms, Lexicon lex, boolean reEval, boolean doubling) {
    // If the transform is in the index, reuse it
    for (int i = 0; i < hypTransforms.size(); i++) {
        Transform hypTransform = hypTransforms.get(i);
        Transform scoredTransform = indexedTransforms.get(hypTransform.toKey());

        // Reuse the old one if possible, otherwise score from scratch
        if (scoredTransform != null) {
            hypTransforms.set(i, scoredTransform);
        } else {//w  ww .java2  s .  co  m
            Transform.scoreTransform(hypTransform, lex, reEval, doubling);
        }
    }
}

From source file:nl.mpcjanssen.simpletask.AddTask.java

private void replaceDueDate(@NotNull CharSequence newDueDate) {
    // save current selection and length
    int start = textInputField.getSelectionStart();
    int end = textInputField.getSelectionEnd();
    int length = textInputField.getText().length();
    int sizeDelta;
    ArrayList<String> lines = new ArrayList<String>();
    Collections.addAll(lines, textInputField.getText().toString().split("\\n", -1));

    // For some reason the currentLine can be larger than the amount of lines in the EditText
    // Check for this case to prevent any array index out of bounds errors
    int currentLine = getCurrentCursorLine(textInputField);
    if (currentLine > lines.size() - 1) {
        currentLine = lines.size() - 1;/* w w  w  .j  a  v a 2  s  .  c o m*/
    }
    if (currentLine != -1) {
        Task t = new Task(0, lines.get(currentLine));
        t.setDueDate(newDueDate.toString());
        lines.set(currentLine, t.inFileFormat());
        textInputField.setText(Util.join(lines, "\n"));
    }
    // restore selection
    int newLength = textInputField.getText().length();
    sizeDelta = newLength - length;
    int newStart = Math.max(0, start + sizeDelta);
    int newEnd = Math.min(end + sizeDelta, newLength);
    newEnd = Math.max(newStart, newEnd);
    textInputField.setSelection(newStart, newEnd);
}

From source file:com.github.paradam.support.v4.infinitepager.InfiniteFragmentStatePagerAdapter.java

@Override
public void notifyDataSetChanged() {
    onPreNotifyDataSetChange();// ww w.java 2s  .  c o  m
    final int count = getRelativeCount();
    final int margin = getMargin();

    ArrayList<Fragment.SavedState> newSavedState = new ArrayList<Fragment.SavedState>(count);
    ArrayList<Fragment> newFragments = new ArrayList<Fragment>(count);
    SparseArray<Fragment> newDestroyedFragments = new SparseArray<Fragment>();

    int length = mFragments.size();

    for (int x = 0; x < length; x++) {
        Fragment fragment = mFragments.get(x);
        boolean fromDestroyed = false;
        if (fragment == null) {
            // Check if there is a destroyed fragment that was in the list, use that if there is.
            fragment = mDestroyedFragments.get(x);
            fromDestroyed = true;
        }
        int position = getItemPosition(fragment);
        switch (position) {
        case POSITION_UNCHANGED:
            while (newFragments.size() < x + 1) {
                newFragments.add(null);
                newSavedState.add(null);
            }
            if (!fromDestroyed) {
                newFragments.set(x, mFragments.get(x));
            } else {
                newDestroyedFragments.put(x, fragment);
            }
            if (mSavedState.size() > x) {
                newSavedState.set(x, mSavedState.get(x));
            }
            break;
        case POSITION_NONE:
            // Do not add fragment.
            if (!fromDestroyed) {
                if (mCurTransaction == null) {
                    mCurTransaction = mFragmentManager.beginTransaction();
                }
                mCurTransaction.remove(mFragments.get(x));
            }
            break;
        default:
            position = (position - margin + count) % count;
            while (newFragments.size() < position + 1) {
                newFragments.add(null);
                newSavedState.add(null);
            }
            if (!fromDestroyed) {
                newFragments.set(position, fragment);
            } else {
                newDestroyedFragments.put(position, fragment);
            }
            if (mSavedState.size() > x) {
                newSavedState.set(position, mSavedState.get(x));
            }
        }
    }

    mSavedState = newSavedState;
    mFragments = newFragments;
    mDestroyedFragments = newDestroyedFragments;

    super.notifyDataSetChanged();
}

From source file:nl.mpcjanssen.simpletask.AddTask.java

private void replaceThresholdDate(@NotNull CharSequence newThresholdDate) {
    // save current selection and length
    int start = textInputField.getSelectionStart();
    int end = textInputField.getSelectionEnd();
    int length = textInputField.getText().length();
    int sizeDelta;
    ArrayList<String> lines = new ArrayList<String>();
    Collections.addAll(lines, textInputField.getText().toString().split("\\n", -1));

    // For some reason the currentLine can be larger than the amount of lines in the EditText
    // Check for this case to prevent any array index out of bounds errors
    int currentLine = getCurrentCursorLine(textInputField);
    if (currentLine > lines.size() - 1) {
        currentLine = lines.size() - 1;//from  ww w  .  ja v a  2  s  .co m
    }
    if (currentLine != -1) {
        Task t = new Task(0, lines.get(currentLine));
        t.setThresholdDate(newThresholdDate.toString());
        lines.set(currentLine, t.inFileFormat());
        textInputField.setText(Util.join(lines, "\n"));
    }
    // restore selection
    int newLength = textInputField.getText().length();
    sizeDelta = newLength - length;
    int newStart = Math.max(0, start + sizeDelta);
    int newEnd = Math.min(end + sizeDelta, newLength);
    newEnd = Math.max(newStart, newEnd);
    textInputField.setSelection(start, end);
}

From source file:com.globalsight.everest.tda.TdaHelper.java

private void sortMatchList(ArrayList matchList) {
    for (int i = 0; i < matchList.size() - 1; i++) {
        LeverageTDAResult tdaResult1 = (LeverageTDAResult) matchList.get(i);

        for (int j = i + 1; j < matchList.size(); j++) {
            LeverageTDAResult tdaResult2 = (LeverageTDAResult) matchList.get(j);

            if (PecentToInt(tdaResult1.getMatchPercent()) < PecentToInt(tdaResult2.getMatchPercent())) {
                LeverageTDAResult temp = tdaResult1;
                tdaResult1 = tdaResult2;
                tdaResult2 = temp;/*from   ww w .jav  a 2  s .  c  o  m*/
            }

            tdaResult1.setOrderNum(TmCoreManager.LM_ORDER_NUM_START_TDA + i);
            tdaResult2.setOrderNum(TmCoreManager.LM_ORDER_NUM_START_TDA + j);
            matchList.set(i, tdaResult1);
            matchList.set(j, tdaResult2);
        }
    }

    // remember the segment whose match percent and match content is all
    // same
    ArrayList<LeverageTDAResult> sameArray = new ArrayList<LeverageTDAResult>();

    for (int i = 0; i < matchList.size() - 1; i++) {
        LeverageTDAResult tdaResult1 = (LeverageTDAResult) matchList.get(i);

        for (int j = i + 1; j < matchList.size(); j++) {
            LeverageTDAResult tdaResult2 = (LeverageTDAResult) matchList.get(j);

            if (PecentToInt(tdaResult1.getMatchPercent()) == PecentToInt(tdaResult2.getMatchPercent())
                    && tdaResult1.getResultText().equals(tdaResult2.getResultText())) {
                if (!sameArray.contains(tdaResult2)) {
                    sameArray.add(tdaResult2);
                }
            }
        }
    }

    matchList.removeAll(sameArray);
}