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

The following are Jave code examples for showing how to use set() of the java.util.List class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: letv   File: OpReorderer.java   View Source Code Vote up 6 votes
private void swapMoveAdd(List<UpdateOp> list, int move, UpdateOp moveOp, int add, UpdateOp addOp) {
    int offset = 0;
    if (moveOp.itemCount < addOp.positionStart) {
        offset = 0 - 1;
    }
    if (moveOp.positionStart < addOp.positionStart) {
        offset++;
    }
    if (addOp.positionStart <= moveOp.positionStart) {
        moveOp.positionStart += addOp.itemCount;
    }
    if (addOp.positionStart <= moveOp.itemCount) {
        moveOp.itemCount += addOp.itemCount;
    }
    addOp.positionStart += offset;
    list.set(move, addOp);
    list.set(add, moveOp);
}
 
Example 2
Project: SimpleRssReader   File: SharedPrefUtils.java   View Source Code Vote up 6 votes
@SuppressWarnings({"ResultOfMethodCallIgnored", "ConstantConditions"})
public static void updateFeedMetaDataAt(final Context context, final int position,
                                        final List<String> metaData) {
    final LinkedListMultimap<String, String> map = getFeedMetaData(context);

    final String currentTitle = getFeedMetaDataTitleAt(context, position);
    final String newTitle = metaData.get(TITLE);
    final String category = metaData.get(FEED_ID);

    final List<String> values = new ArrayList<>(map.removeAll(currentTitle));
    values.set(CATEGORY, category);

    map.putAll(newTitle, values);

    putFeedMetaData(context, map);
    updateCurrentFeedAdapterPosition(context, newTitle);
}
 
Example 3
Project: lams   File: QueryLoader.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
@Override
protected List getResultList(List results, ResultTransformer resultTransformer) throws QueryException {
	// meant to handle dynamic instantiation queries...
	HolderInstantiator holderInstantiator = buildHolderInstantiator( resultTransformer );
	if ( holderInstantiator.isRequired() ) {
		for ( int i = 0; i < results.size(); i++ ) {
			Object[] row = ( Object[] ) results.get( i );
			Object result = holderInstantiator.instantiate(row);
			results.set( i, result );
		}

		if ( !hasSelectNew() && resultTransformer != null ) {
			return resultTransformer.transformList(results);
		}
		else {
			return results;
		}
	}
	else {
		return results;
	}
}
 
Example 4
Project: pvdisplay   File: MonthlyFragment.java   View Source Code Vote up 5 votes
private List<MonthlyPvDatum> createFullYear(int year, List<MonthlyPvDatum> monthPvData) {
    List<MonthlyPvDatum> fullYear = new ArrayList<>();
    for (int month = 1; month <= 12; month++) {
        fullYear.add(new MonthlyPvDatum(year, month, 0));
    }
    for (MonthlyPvDatum monthlyPvDatum : monthPvData) {
        int fullYearIndex = monthlyPvDatum.getMonth() - 1;
        fullYear.set(fullYearIndex, monthlyPvDatum);
    }
    return fullYear;
}
 
Example 5
Project: SimpleRssReader   File: TypedValueUtils.java   View Source Code Vote up 5 votes
public static void resolveResourceIds(final Activity activity, final List<Integer> idRes) {
    final TypedValue tv = new TypedValue();
    final Resources.Theme theme = activity.getTheme();

    int i = 0;

    for (final int res : idRes) {
        theme.resolveAttribute(res, tv, true);
        idRes.set(i, tv.resourceId);
        i++;
    }
}
 
Example 6
Project: sierra   File: NucAminoAligner.java   View Source Code Vote up 5 votes
/**
 * Remove only deletion/NNNs from the beginning and the end of alignment
 *
 * @param sequence
 * @param firstAA
 * @param lastAA
 * @param mutations
 * @param frameShifts
 * @return
 */
private static int[] trimGaps(
		Sequence sequence, int firstAA, int lastAA,
		Collection<Mutation> mutations, Collection<FrameShift> frameShifts) {
	int trimLeft = 0;
	int trimRight = 0;
	int proteinSize = lastAA - firstAA + 1;
	List<Boolean> gapSites = new ArrayList<>(Collections.nCopies(proteinSize, false));
	for (Mutation mut : mutations) {
		int idx = mut.getPosition() - firstAA;
		if (mut.isDeletion() || mut.isUnsequenced()) {
			gapSites.set(idx, true);
		}
	}
	// remove initial deletions
	for (int idx=0; idx < proteinSize; idx ++) {
		if (!gapSites.get(idx)) {
			if (idx > trimLeft) {
				trimLeft = idx;
			}
			break;
		}
	}
	// remove trailing deletions
	for (int idx=proteinSize-1; idx > -1; idx --) {
		if (!gapSites.get(idx)) {
			if (proteinSize - idx - 1 > trimRight) {
				trimRight = proteinSize - idx - 1;
			}
			break;
		}
	}
	return new int[]{trimLeft, trimRight};
}
 
Example 7
Project: convertigo-engine   File: ProcessUtils.java   View Source Code Vote up 5 votes
public static ProcessBuilder getProcessBuilder(String paths, List<String> command) throws IOException {
	if (command == null || command.size() == 0) {
		throw new IOException("No command paramater");
	}
	
	paths = getAllPaths(paths);
	command.set(0, searchFullPath(paths, command.get(0)));
	ProcessBuilder pb = new ProcessBuilder(command);
	Map<String, String> pbEnv = pb.environment();		
	// must set "Path" for Windows 8.1 64
	pbEnv.put(pbEnv.get("PATH") == null ? "Path" : "PATH", paths);
	return pb; 
}
 
Example 8
Project: Solar   File: IQuantumData.java   View Source Code Vote up 5 votes
default void setEntanglementStack(UUID uuid, ItemStack stack, int slot) {
	List<ItemStack> list = getEntanglement(uuid);
	if(!hasSlot(uuid, slot)) {
		if(!stack.isEmpty()) {
			list.add(stack);
		}
	} else if(!stack.isEmpty()) {
		list.set(slot, stack);
	} else {
		list.remove(slot);
	}
}
 
Example 9
Project: n4js   File: Arrays2Test.java   View Source Code Vote up 5 votes
/***/
@Test
public void testReturnCanBeSet() {
	final List<String> ret = transform(new Object[] { "item" }, input -> valueOf(input));
	assertFalse(ret.isEmpty());
	assertTrue("item".equals(getOnlyElement(ret)));
	ret.set(0, "another item");
	assertTrue("another item".equals(getOnlyElement(ret)));
}
 
Example 10
Project: MLE5109-Course-samples   File: ListPuzzle.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    List<Integer> list = new ArrayList<>();
    Integer[] arr = {2,10,3};
    list = Arrays.asList(arr);
    list.set(0, 3);
    System.out.println(list);
    list.add(1);
    System.out.println(list);
}
 
Example 11
Project: Hydrograph   File: ELTSchemaGridWidget.java   View Source Code Vote up 5 votes
private void sequencingOfSchemaFieldsInOrderOfInternalSchemaFields(List<GridRow> outputSchema,
		List<GridRow> internalSchema2) {
	for(int index=0;index<internalSchema2.size();index++){
		if(!StringUtils.equalsIgnoreCase(outputSchema.get(index).getFieldName(), internalSchema2.get(index).getFieldName())){
			outputSchema.set(index,internalSchema2.get(index));
		}
	}
}
 
Example 12
Project: guava-mock   File: CharsTest.java   View Source Code Vote up 5 votes
public void testAsList_toArray_roundTrip() {
  char[] array = { (char) 0, (char) 1, (char) 2 };
  List<Character> list = Chars.asList(array);
  char[] newArray = Chars.toArray(list);

  // Make sure it returned a copy
  list.set(0, (char) 4);
  assertTrue(Arrays.equals(
      new char[] { (char) 0, (char) 1, (char) 2 }, newArray));
  newArray[1] = (char) 5;
  assertEquals((char) 1, (char) list.get(1));
}
 
Example 13
Project: elasticsearch_my   File: ParentBulkByScrollTask.java   View Source Code Vote up 5 votes
private void addResultsToList(List<StatusOrException> sliceStatuses) {
    for (AtomicArray.Entry<Tuple<BulkByScrollResponse, Exception>> t : results.asList()) {
        if (t.value != null) {
            if (t.value.v1() != null) {
                sliceStatuses.set(t.index, new StatusOrException(t.value.v1().getStatus()));
            } else {
                sliceStatuses.set(t.index, new StatusOrException(t.value.v2()));
            }
        }
    }
}
 
Example 14
Project: openjdk-jdk10   File: DoWhile.java   View Source Code Vote up 5 votes
@Override
public boolean removeSelf() {
    IRNode header = getChildren().get(DoWhilePart.HEADER.ordinal());
    List<IRNode> siblings = getParent().getChildren();
    int index = siblings.indexOf(this);
    siblings.set(index++, loop.initialization);
    if (header instanceof Block) {
        siblings.addAll(index, header.getChildren());
    } else {
        siblings.add(index, header);
    }
    return true;
}
 
Example 15
Project: empiria.player   File: GeneralVariablesJUnitTest.java   View Source Code Vote up 5 votes
@Test
public void answersModification_setByMutator_collectionShouldBeCopied() {
    // given
    GeneralVariables gv = new GeneralVariables();
    List<String> answers = Lists.newArrayList("a");
    gv.setAnswers(answers);

    // when
    answers.set(0, "b");

    // then
    assertThat(gv.getAnswers().get(0)).isEqualTo("a");

}
 
Example 16
Project: Pogamut3   File: SharedKnowledgeDatabase.java   View Source Code Vote up 5 votes
/**
 * UNSYNC 
 * @return
 */
private int getUnusedAgentNumber() {		
	List<Boolean> used = new ArrayList<Boolean>(registeredAgents.size()+1);
	for (Integer agentNumber : registeredAgents.getMap().values()) {
		used.set(agentNumber, true);
	}
	for (int i = 0; i < used.size(); ++i) {
		if (used.get(i) == null || !used.get(i)) {
			return i;
		}
	}
	// SHOULD NOT REACH HERE!
	throw new RuntimeException("registeredAgents corrupted!");
}
 
Example 17
Project: alfresco-data-model   File: MimetypeMap.java   View Source Code Vote up 5 votes
/**
 * Copies and sorts the supplied mimetypes by their file extensions
 * @param mimetypes to be sorted
 * @return a new List of sorted mimetypes
 */
private Collection<String> sortMimetypesByExt(Collection<String> mimetypes)
{
    List<String> result = new ArrayList<String>(mimetypes);
    for (int i=result.size()-1; i>= 0; i--)
    {
        result.set(i, getExtension(result.get(i)));
    }
    Collections.sort(result);
    for (int i=result.size()-1; i>= 0; i--)
    {
        result.set(i, getMimetype(result.get(i)));
    }
    return result;
}
 
Example 18
Project: ProjectAres   File: PickerMatchModule.java   View Source Code Vote up 4 votes
/**
 * Generate current picker contents for the given player
 */
private ItemStack[] createWindowContents(final MatchPlayer player) {
    final List<ItemStack> slots = new ArrayList<>();

    final Set<Team> teams = getChoosableTeams(player);
    if(!teams.isEmpty()) {
        // Auto-join button at start of row
        if(teams.size() > 1) {

            final JoinResult autoResult = jmm.queryJoin(player, JoinRequest.user());
            if(autoResult.isVisible()) {
                slots.add(createAutoJoinButton(player));
            }
        }

        // Team buttons
        if(teams.size() > 1 || !hasJoined(player)) {
            for(Team team : teams) {
                slots.add(createTeamJoinButton(player, team));
            }
        }
    }

    // Skip to next empty row
    while(slots.size() % WIDTH != 0) slots.add(null);

    // Class buttons
    if(hasClasses) {
        for(PlayerClass cls : getMatch().getMatchModule(ClassMatchModule.class).getClasses()) {
            slots.add(createClassButton(player, cls));
        }
    }

    // Pad last row to width
    while(slots.size() % WIDTH != 0) slots.add(null);

    if(hasJoined(player)) {
        // Put leave button in first empty slot of the last column
        for(int slot = WIDTH - 1;; slot += WIDTH) {
            while(slots.size() <= slot) {
                slots.add(null);
            }

            if(slots.get(slot) == null) {
                slots.set(slot, createLeaveButton(player));
                break;
            }
        }
    }

    return slots.toArray(new ItemStack[slots.size()]);
}
 
Example 19
Project: Excel-to-POJO   File: FileParser.java   View Source Code Vote up 4 votes
public Map<Class<? extends Inventory>, List<Inventory>> parseFile() throws Exception {

		sheetFormats = formatLoader.loadFromJson();
		workbook = new XSSFWorkbook(new FileInputStream(excelFile));
		// greater workbook sheets doesnot matter rather if we only want to parse first
		// few sheets ?
		if (workbook.getNumberOfSheets() < sheetFormats.size())
			throw new FileParsingException("format number of sheets is greater than excel number of sheets");

		List<SheetParser> sheetParsingTasks = new ArrayList<>();

		// package in which POJO resides
		Class<? extends Inventory> clazz;
		for (final SheetFormat sf : sheetFormats) {
			clazz = InventoryFactory.getClazz(sf.getName());

			if (clazz == null)
				throw new SheetParsingException("Name of the Sheet doesnot match POJO Class Name");
			sheetParsingTasks.add(new SheetParser(workbook.getSheetAt(sf.getIndex()), sf, clazz));
		
		}
		ExecutorService pool = Executors.newFixedThreadPool(sheetParsingTasks.size() + 2);

		List<Future<List<Inventory>>> results = pool.invokeAll(sheetParsingTasks);

		Map<Class<? extends Inventory>, List<Inventory>> map = new HashMap<>();

		int n = results.size();
		for (int count = 0, i = 0; count < n;) {

			if (results.get(i) != null && results.get(i).isDone()) {
				count++;
				try {
					List<Inventory> list = results.get(i).get();
					try {
						clazz = list.get(0).getClass();
						// allow duplicates
						if (map.containsKey(clazz))
							map.get(clazz).addAll(list);
						else
							map.put(clazz, list);
						results.set(i, null);
					} catch (IndexOutOfBoundsException e) {
						log.warn("Sheet " + sheetFormats.get(i).getIndex() + 1 + "/"
								+ sheetFormats.get(i).getName() + " is empty");
					}
				} catch (ExecutionException | InterruptedException | NullPointerException ex ) {
					List<String> errors = new ArrayList<String>();
					Arrays.stream(ex.getStackTrace()).forEach(e->errors.add(e.toString()));
					log.error("error in parsing excel file  at : {}" , errors);
				}

			} else
				i = (i + 1) % n;

		}

		return map;
	}
 
Example 20
Project: Backmemed   File: GuiContainerCreative.java   View Source Code Vote up 4 votes
protected void renderToolTip(ItemStack stack, int x, int y)
{
    if (selectedTabIndex == CreativeTabs.SEARCH.getTabIndex())
    {
        List<String> list = stack.getTooltip(this.mc.player, this.mc.gameSettings.advancedItemTooltips);
        CreativeTabs creativetabs = stack.getItem().getCreativeTab();

        if (creativetabs == null && stack.getItem() == Items.ENCHANTED_BOOK)
        {
            Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(stack);

            if (map.size() == 1)
            {
                Enchantment enchantment = (Enchantment)map.keySet().iterator().next();

                for (CreativeTabs creativetabs1 : CreativeTabs.CREATIVE_TAB_ARRAY)
                {
                    if (creativetabs1.hasRelevantEnchantmentType(enchantment.type))
                    {
                        creativetabs = creativetabs1;
                        break;
                    }
                }
            }
        }

        if (creativetabs != null)
        {
            list.add(1, "" + TextFormatting.BOLD + TextFormatting.BLUE + I18n.format(creativetabs.getTranslatedTabLabel(), new Object[0]));
        }

        for (int i = 0; i < list.size(); ++i)
        {
            if (i == 0)
            {
                list.set(i, stack.getRarity().rarityColor + (String)list.get(i));
            }
            else
            {
                list.set(i, TextFormatting.GRAY + (String)list.get(i));
            }
        }

        this.drawHoveringText(list, x, y);
    }
    else
    {
        super.renderToolTip(stack, x, y);
    }
}