Java Code Examples for java.util.ArrayList.set()

The following are Jave code examples for showing how to use set() of the java.util.ArrayList class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Metodo-de-Gaus-Com-Pivot   File: Controle.java   Source Code and License Vote up 6 votes
/**
 * Metodo usado para pegar pegar a linha linha do pivot e de seguida fazer a permutacao de linhas! colocando acima a linha do pivot
 * @param matriz - matriz dos valores
 * @param coluna - coluna com a qual estamos a trabalhar
 * @return matriz com zeros abaixo do pivot
 */
public ArrayList<ArrayList<Double>> retornarMatrizComPivot(ArrayList<ArrayList<Double>> matriz,int coluna){
    int linhaDoPivot = this.retornarLinhaDoPivot(matriz, coluna);
    
    ArrayList<Double> auxParaTroca = new ArrayList();
    auxParaTroca = matriz.get(coluna);
    matriz.set(coluna, matriz.get(linhaDoPivot));
    matriz.set(linhaDoPivot, auxParaTroca);
    
    /**
     * Para q possa imprimir a matriz depois de fazer a permutacao de linhas
     */
    this.imprimirMatriz(matriz);
    
    return retornarZeroAbaixo(matriz, coluna);
}
 
Example 2
Project: ZentrelaRPG   File: Dungeon.java   Source Code and License Vote up 6 votes
public ArrayList<String> getDisplay() {
    if (desc == null) {
        desc = new ArrayList<String>();
        desc.add(ChatColor.GOLD + "Recommended Level: " + ChatColor.YELLOW + recLevel);
        desc.add(ChatColor.AQUA + description);
        desc.add("");
        desc.add(ChatColor.WHITE + "Tips");
        for (String s : tips) {
            ArrayList<String> temp = RFormatter.stringToLore(s, "   ");
            if (temp.size() > 0)
                temp.set(0, "-" + temp.get(0).substring(2));
            for (String t : temp)
                desc.add(ChatColor.GRAY + t);
        }
    }
    return desc;
}
 
Example 3
Project: AOSP-Kayboard-7.1.2   File: PointerTrackerQueue.java   Source Code and License Vote up 6 votes
public void remove(final Element pointer) {
    synchronized (mExpandableArrayOfActivePointers) {
        if (DEBUG) {
            Log.d(TAG, "remove: " + pointer + " " + this);
        }
        final ArrayList<Element> expandableArray = mExpandableArrayOfActivePointers;
        final int arraySize = mArraySize;
        int newIndex = 0;
        for (int index = 0; index < arraySize; index++) {
            final Element element = expandableArray.get(index);
            if (element == pointer) {
                if (newIndex != index) {
                    Log.w(TAG, "Found duplicated element in remove: " + pointer);
                }
                continue; // Remove this element from the expandableArray.
            }
            if (newIndex != index) {
                // Shift this element toward the beginning of the expandableArray.
                expandableArray.set(newIndex, element);
            }
            newIndex++;
        }
        mArraySize = newIndex;
    }
}
 
Example 4
Project: TeamNote   File: NoticeDaoImplTest.java   Source Code and License Vote up 6 votes
@Test
public void testUpdateNotice() {
    ArrayList<String> notices = new ArrayList<String>();
    notices.add("haha");
    Notice notice = new Notice(1, notices);
    noticeDao.addNotice(notice);

    notice = noticeDao.getAllNotices().get(0);
    notices = notice.getNotices();
    notices.set(0, "heihei");
    notice.setNotices(notices);
    noticeDao.updateNotice(notice);

    Assert.assertEquals(noticeDao.getAllNotices().get(0).getNotices(), notice.getNotices());

    noticeDao.deleteNotice(notice);
}
 
Example 5
Project: Neural-Network-Programming-with-Java-SecondEdition   File: NeuralOutputData.java   Source Code and License Vote up 5 votes
public ArrayList<Double> getMeanNeuralData(){
    ArrayList<Double> result=new ArrayList<>();
    for(int j=0;j<numberOfOutputs;j++){
        Double r=0.0;
        result.add(r);
        for(int k=0;k<numberOfRecords;k++){
            r+=neuralData.get(k).get(j);
        }
        result.set(j, r/((double)numberOfRecords));
    }
    return result;
}
 
Example 6
Project: Neural-Network-Programming-with-Java-SecondEdition   File: NeuralInputData.java   Source Code and License Vote up 5 votes
public ArrayList<Double> getMeanInputData(){
    ArrayList<Double> result=new ArrayList<>();
    for(int i=0;i<numberOfInputs;i++){
        Double r=0.0;
        result.add(r);
        for(int k=0;k<numberOfRecords;k++){
            r+=data.get(k).get(i);
        }
        result.set(i, r/((double)numberOfRecords));
    }
    return result;
}
 
Example 7
Project: modern.core.java.repo   File: Courses.java   Source Code and License Vote up 5 votes
private ArrayList<Double> selectCourseCost() {
    ArrayList<Double> coursePrice = new ArrayList<Double>();
    coursePrice.add(500D);
    coursePrice.add(600D);
    coursePrice.add(750D);
    coursePrice.add(800D);
    coursePrice.add(1100D);
    coursePrice.add(3, 2300D);
    coursePrice.add(1490D);
    coursePrice.set(4, 1500D);
    coursePrice.get(0);
    return coursePrice;

}
 
Example 8
Project: guava-mock   File: ListEqualsTester.java   Source Code and License Vote up 5 votes
@CollectionSize.Require(absent = CollectionSize.ZERO)
public void testEquals_otherListWithDifferentElements() {
  ArrayList<E> other = new ArrayList<E>(getSampleElements());
  other.set(other.size() / 2, getSubjectGenerator().samples().e3());
  assertFalse(
      "A List should not equal another List containing different elements.",
      getList().equals(other));
}
 
Example 9
Project: Neural-Network-Programming-with-Java-SecondEdition   File: NeuralInputData.java   Source Code and License Vote up 5 votes
public ArrayList<Double> getMeanInputData(){
    ArrayList<Double> result=new ArrayList<>();
    for(int i=0;i<numberOfInputs;i++){
        Double r=0.0;
        result.add(r);
        for(int k=0;k<numberOfRecords;k++){
            r+=data.get(k).get(i);
        }
        result.set(i, r/((double)numberOfRecords));
    }
    return result;
}
 
Example 10
Project: chiefproject   File: AttributeCreator.java   Source Code and License Vote up 5 votes
private ArrayList<String> AttrCalculation(ArrayList<String> attrTemI){
    int randomID = attrTemI.size();
    int randomI = Integer.parseInt(attrTemI.get(randomID - 2));
    int value,bonuses,impairment;
    for (int i = 1;i < randomID -7;i++){
        value = Integer.parseInt(attrTemI.get(i));
        bonuses = random.nextInt(randomI + 1);
        impairment = random.nextInt(randomI + 1);
        value = value + bonuses - impairment;
        attrTemI.set(i,Integer.toString(value));
    }
    return attrTemI;
}
 
Example 11
Project: CSIS280   File: Main.java   Source Code and License Vote up 5 votes
public static void main(String[] args) {
    ArrayList<Integer> numbers2 = new ArrayList();
    for (int counter = 0 ; counter < 5 ; counter++) {
        numbers2.add(0, counter);
    }
    // 4, 3, 2, 1, 0

    ArrayList<Integer> numbers = new ArrayList();

    numbers.add(10);
    numbers.add(11);
    numbers.add(12);
    numbers.add(13);
    numbers.add(14);
    // 10, 11, 12, 13, 14

    numbers.add(0, 16); // 16, 10, 11, 12, 13, 14

    numbers.add(3, 20); // 16, 10, 11, 20, 12, 13, 14

    // Contains

    numbers.contains(10);

    int indexOfElement = numbers.indexOf(20);

    numbers.set(indexOfElement, 20 * 20);
    // 16, 10, 11, 400, 12, 13, 14
}
 
Example 12
Project: JAddOn   File: ArrayListProcessor.java   Source Code and License Vote up 5 votes
/**
 * Just the run method
 * @param arraylist
 * @param threadPoolSize 
 */
private final void processPrivate(final ArrayList<Object> arraylist, final int threadPoolSize) {
    final ExecutorService executor = Executors.newFixedThreadPool(threadPoolSize);
    if(arraylist.size() >= threadPoolSize && arraylist.size() >= MINARRAYLISTSIZE) {
        final int steps = arraylist.size() / threadPoolSize;
        for(int i = 0; i < threadPoolSize; i++) {
            final int u = i;
            Runnable run = new Runnable() {
                
                @Override
                public void run() {
                    final int extra = ((u == threadPoolSize - 1) ? (steps * threadPoolSize) - arraylist.size() : 0);
                    for(int z = 0; z < steps + extra; z++) {
                        final int pos = (u * steps + z);
                        arraylist.set(pos, process(arraylist.get(pos)));
                    }
                }
                
            };
            executor.execute(run);
        }
        executor.shutdown();
        try {
            executor.awaitTermination(1, TimeUnit.DAYS);
        } catch (Exception ex) {
        }
    } else {
        for(int i = 0; i < arraylist.size(); i++) {
            arraylist.set(i, process(arraylist.get(i)));
        }
    }
}
 
Example 13
Project: Neural-Network-Programming-with-Java-SecondEdition   File: Neuron.java   Source Code and License Vote up 5 votes
public ArrayList<Double> calcBatch(ArrayList<ArrayList<Double>> _input){
    ArrayList<Double> result = new ArrayList<>();
    for(int i=0;i<_input.size();i++){
        result.add(0.0);
        Double _outputBeforeActivation=0.0;
        for(int j=0;j<numberOfInputs;j++){
            _outputBeforeActivation+=(j==numberOfInputs?bias:_input.get(i).get(j))*weight.get(j);
        }
        result.set(i,activationFunction.calc(_outputBeforeActivation));
    }
    return result;
}
 
Example 14
Project: OpenDiabetes   File: TestScripts.java   Source Code and License Vote up 4 votes
/**
 * Run java org.hsqldb.util.TestScripts --help.
 * For each script run, the connection will be closed or persisted
 * depending on whether "--ephConnId=x" or "--persistConnId=x" preceded
 * the file name (defaulting to closing).
 * So, by default, for each script file, a new connection will be made
 * and closed immediately after the script runs.
 */
public static void main(String[] argv) {

    if (argv.length > 0 && argv[0].equals("--help")) {
        System.err.println(SYNTAX_MSG);
        System.exit(2);
    }

    ArrayList scripts   = new ArrayList();
    ArrayList connIds   = new ArrayList();
    ArrayList retains   = new ArrayList();
    int       i         = -1;
    int       curscript = 0;

    // java.util.ArrayLists may contain null elements.
    connIds.add(null);
    retains.add(null);

    String newName = null;

    while (++i < argv.length) {
        if (argv[i].startsWith("--ephConnId=")) {
            newName = getIdName(argv[i]);

            if (newName == null
                    || connIds.set(connIds.size() - 1, getIdName(argv[i]))
                       != null) {
                System.err.println(SYNTAX_MSG);
                System.exit(2);
            }

            if (retains.set(retains.size() - 1, Boolean.FALSE) != null) {
                System.err.println(SYNTAX_MSG);
                System.exit(2);
            }
        } else if (argv[i].startsWith("--persistConnId=")) {
            newName = getIdName(argv[i]);

            if (newName == null
                    || connIds.set(connIds.size() - 1, newName) != null) {
                System.err.println(SYNTAX_MSG);
                System.exit(2);
            }

            if (retains.set(retains.size() - 1, Boolean.TRUE) != null) {
                System.err.println(SYNTAX_MSG);
                System.exit(2);
            }
        } else if (argv[i].startsWith("-")) {
            System.err.println(SYNTAX_MSG);
            System.exit(2);
        } else {
            scripts.add(argv[i]);
            connIds.add(null);
            retains.add(null);
        }
    }

    test(DEF_URL, DEF_USER, DEF_PASSWORD, DEF_DB,
         (String[]) scripts.toArray(new String[0]),
         (String[]) connIds.toArray(new String[0]),
         (Boolean[]) retains.toArray(new Boolean[0]));
}
 
Example 15
Project: atlas   File: SsaRenamer.java   Source Code and License Vote up 4 votes
/**
 * Renames all the variables in this block and inserts appriopriate
 * phis in successor blocks.
 */
public void process() {
    /*
     * From Appel:
     *
     * Rename(n) =
     *   for each statement S in block n   // 'statement' in 'block'
     */

    block.forEachInsn(this);

    updateSuccessorPhis();

    // Delete all move insns in this block.
    ArrayList<SsaInsn> insns = block.getInsns();
    int szInsns = insns.size();

    for (int i = szInsns - 1; i >= 0 ; i--) {
        SsaInsn insn = insns.get(i);
        SsaInsn replaceInsn;

        replaceInsn = insnsToReplace.get(insn);

        if (replaceInsn != null) {
            insns.set(i, replaceInsn);
        } else if (insn.isNormalMoveInsn()
                && !movesToKeep.contains(insn)) {
            insns.remove(i);
        }
    }

    // Store the start states for our dom children.
    boolean first = true;
    for (SsaBasicBlock child : block.getDomChildren()) {
        if (child != block) {
            // Don't bother duplicating the array for the first child.
            RegisterSpec[] childStart = first ? currentMapping
                : dupArray(currentMapping);

            startsForBlocks[child.getIndex()] = childStart;
            first = false;
        }
    }

    // currentMapping is owned by a child now.
}
 
Example 16
Project: CausalNet   File: Coreferencer.java   Source Code and License Vote up 4 votes
public static ArrayList<String> getdCoreferencedText(String text){
	Annotation document = new Annotation(text);
	pipeline.annotate(document);
	ArrayList<String> sentences = new ArrayList<String>();
	DocumentPreprocessor dp = new DocumentPreprocessor(
		new StringReader(text));
	ArrayList<List<HasWord>> processedText = new ArrayList<List<HasWord>>();
	for (List<HasWord> sentence : dp){
		processedText.add(sentence);
	}
	
	//用 representative mention 把 mention替换掉
	Map<Integer, CorefChain> graph = 
	document.get(CorefChainAnnotation.class);
	for (Map.Entry<Integer, CorefChain> entry : graph.entrySet()){
		CorefChain c = entry.getValue();
		
		CorefMention cm = c.getRepresentativeMention();
		for (Entry<IntPair, Set<CorefMention>> e : 
			c.getMentionMap().entrySet()){
			if (cm.endIndex - cm.startIndex >2){
				continue; //如果representative mention 词数大于2 就不换了
			}
			for(CorefMention mention : e.getValue()){
				perClusterUpdateSen(processedText,
						mention.sentNum,cm.sentNum,
					cm.startIndex,cm.endIndex,
					mention.startIndex,mention.endIndex);
			}
		}
	}
	
	for (List<HasWord> senlist : processedText){
		sentences.add("");
		for (HasWord word:senlist){
			if (!word.toString().equals("")){
				//System.out.print(word.toString()+" ");
				String str = sentences.
						get(sentences.size()-1) + word.toString().toLowerCase()+" ";
				sentences.set(sentences.size()-1, str);
			}
		}
		
		//System.out.println();
	}
	for (int i=0; i < sentences.size(); i++){
		String s = sentences.get(i);
		sentences.set(i, (""+s.charAt(0)).toUpperCase() + s.substring(1)) ;
	}
	return sentences;
}
 
Example 17
Project: Android_RuuvitagScannner   File: DBHandler.java   Source Code and License Vote up 4 votes
public ArrayList<Cursor> getData(String Query){
    //get writable database
    SQLiteDatabase sqlDB = this.getWritableDatabase();
    String[] columns = new String[] { "message" };
    //an array list of cursor to save two cursors one has results from the query
    //other cursor stores error message if any errors are triggered
    ArrayList<Cursor> alc = new ArrayList<Cursor>(2);
    MatrixCursor Cursor2= new MatrixCursor(columns);
    alc.add(null);
    alc.add(null);

    try{
        String maxQuery = Query ;
        //execute the query results will be save in Cursor c
        Cursor c = sqlDB.rawQuery(maxQuery, null);

        //add value to cursor2
        Cursor2.addRow(new Object[] { "Success" });

        alc.set(1,Cursor2);
        if (null != c && c.getCount() > 0) {

            alc.set(0,c);
            c.moveToFirst();

            return alc ;
        }
        return alc;
    } catch(SQLException sqlEx){
        Log.d("printing exception", sqlEx.getMessage());
        //if any exceptions are triggered save the error message to cursor an return the arraylist
        Cursor2.addRow(new Object[] { ""+sqlEx.getMessage() });
        alc.set(1,Cursor2);
        return alc;
    } catch(Exception ex){
        Log.d("printing exception", ex.getMessage());
        //if any exceptions are triggered save the error message to cursor an return the arraylist
        Cursor2.addRow(new Object[] { ""+ex.getMessage() });
        alc.set(1,Cursor2);
        return alc;
    }
}
 
Example 18
Project: AOSP-Kayboard-7.1.2   File: Suggest.java   Source Code and License Vote up 4 votes
private void getSuggestedWordsForBatchInput(final WordComposer wordComposer,
        final NgramContext ngramContext, final Keyboard keyboard,
        final SettingsValuesForSuggestion settingsValuesForSuggestion,
        final int inputStyle, final int sequenceNumber,
        final OnGetSuggestedWordsCallback callback) {
    final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
            wordComposer.getComposedDataSnapshot(), ngramContext, keyboard,
            settingsValuesForSuggestion, SESSION_ID_GESTURE, inputStyle);
    // For transforming words that don't come from a dictionary, because it's our best bet
    final Locale locale = mDictionaryFacilitator.getLocale();
    final ArrayList<SuggestedWordInfo> suggestionsContainer =
            new ArrayList<>(suggestionResults);
    final int suggestionsCount = suggestionsContainer.size();
    final boolean isFirstCharCapitalized = wordComposer.wasShiftedNoLock();
    final boolean isAllUpperCase = wordComposer.isAllUpperCase();
    if (isFirstCharCapitalized || isAllUpperCase) {
        for (int i = 0; i < suggestionsCount; ++i) {
            final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
            final Locale wordlocale = wordInfo.mSourceDict.mLocale;
            final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo(
                    wordInfo, null == wordlocale ? locale : wordlocale, isAllUpperCase,
                    isFirstCharCapitalized, 0 /* trailingSingleQuotesCount */);
            suggestionsContainer.set(i, transformedWordInfo);
        }
    }

    if (SHOULD_REMOVE_PREVIOUSLY_REJECTED_SUGGESTION
            && suggestionsContainer.size() > 1
            && TextUtils.equals(suggestionsContainer.get(0).mWord,
               wordComposer.getRejectedBatchModeSuggestion())) {
        final SuggestedWordInfo rejected = suggestionsContainer.remove(0);
        suggestionsContainer.add(1, rejected);
    }
    SuggestedWordInfo.removeDups(null /* typedWord */, suggestionsContainer);

    // For some reason some suggestions with MIN_VALUE are making their way here.
    // TODO: Find a more robust way to detect distracters.
    for (int i = suggestionsContainer.size() - 1; i >= 0; --i) {
        if (suggestionsContainer.get(i).mScore < SUPPRESS_SUGGEST_THRESHOLD) {
            suggestionsContainer.remove(i);
        }
    }

    // In the batch input mode, the most relevant suggested word should act as a "typed word"
    // (typedWordValid=true), not as an "auto correct word" (willAutoCorrect=false).
    // Note that because this method is never used to get predictions, there is no need to
    // modify inputType such in getSuggestedWordsForNonBatchInput.
    final SuggestedWordInfo pseudoTypedWordInfo = suggestionsContainer.isEmpty() ? null
            : suggestionsContainer.get(0);

    callback.onGetSuggestedWords(new SuggestedWords(suggestionsContainer,
            suggestionResults.mRawSuggestions,
            pseudoTypedWordInfo,
            true /* typedWordValid */,
            false /* willAutoCorrect */,
            false /* isObsoleteSuggestions */,
            inputStyle, sequenceNumber));
}
 
Example 19
Project: SparkIsax   File: IndexHashParams.java   Source Code and License Vote up 3 votes
public static ArrayList<Integer> generateChildCardinality(ArrayList<Integer> arSequenceCards) {

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

    if (arSequenceCards.size() < 1) {
      // System.out.println("no symbols");
      return arCards;
    }

    int iLSF = arSequenceCards.get(0); // node_sax_key.symbols.get(0).Cardinality + 1;
    int index = 0;

    for (int x = 0; x < arSequenceCards.size(); x++) {

      if (iLSF > arSequenceCards.get(x)) {

        iLSF = arSequenceCards.get(x);
        index = x;

      }

      arCards.add(arSequenceCards.get(x));

    }

    arCards.set(index, arCards.get(index) << 1);

    return arCards;

  }
 
Example 20
Project: Kaeon-FUSION   File: Set.java   Source Code and License Vote up 3 votes
@SuppressWarnings("unchecked")
public Object onCommand(Element element, ArrayList<Object> processed) {
	
	ArrayList<Object> list = (ArrayList<Object>) processed.get(0);
	int index = Integer.parseInt("" + processed.get(1)) - 1;

	while(list.size() < index)
		list.add(null);
	
	list.set(index, processed.get(2));
	
	return null;
}