List of usage examples for java.util List set
E set(int index, E element);
From source file:Randomizer.java
public void randomize(List list) { int size = list.size(); for (int i = 0; i <= size; i++) { int j = nextInt(size); Object obj = list.get(i); list.set(i, list.get(i + j)); list.set(i + j, obj);/* ww w. j a va 2 s . co m*/ size--; } }
From source file:com.google.dart.java2dart.engine.EngineAnnotationProcessor.java
private void replaceInvocationArgumentWithNamed(SimpleFormalParameter parameter) { String parameterName = parameter.getIdentifier().getName(); FormalParameterList parameterList = (FormalParameterList) parameter.getParent(); AstNode member = parameterList.getParent(); int index = parameterList.getParameters().indexOf(parameter); if (member instanceof MethodDeclaration) { MethodDeclaration method = (MethodDeclaration) member; List<MethodInvocation> invocations = context.getInvocations(method); for (MethodInvocation invocation : invocations) { List<Expression> arguments = invocation.getArgumentList().getArguments(); Expression argument = arguments.get(index); arguments.set(index, namedExpression(parameterName, argument)); }//from www . j av a2s . c om } }
From source file:de.micromata.genome.util.text.TextSplitterUtils.java
/** * Parse tokens, but also ignore tokenizing inside quotes. The quote sign itself can be quoted with \\. * /*from w w w .java 2 s. c o m*/ * Inside the quoted only the quote sign will be unescaped, all other \\ will be remain. * * @param text the text * @param tokens the tokens * @param returnDelimiter the return delimiter * @param quoteChar the quote char * @return list of tokens * @since 1.2.1 */ public static List<String> parseQuotedStringTokens(String text, String[] tokens, boolean returnDelimiter, char quoteChar) { Token[] tks = new Token[tokens.length + 1]; int i = 0; int quoteTk = -5; for (; i < tokens.length; ++i) { String p = tokens[i]; if (p.length() == 1) { tks[i] = new CharToken(i + 1, p.charAt(0)); } else { tks[i] = new StringToken(i + 1, p); } } char escapeChar = '\\'; tks[tks.length - 1] = new CharToken(quoteTk, quoteChar); List<TokenResult> tksr = TextSplitterUtils.parseStringTokens(text, tks, escapeChar, true, true); List<String> ret = new ArrayList<String>(); TokenResult tk; String ecapeQuote = "" + escapeChar + quoteChar; boolean previousWasSplitter = true; nextMainLoop: for (i = 0; i < tksr.size(); ++i) { tk = tksr.get(i); if (tk.getTokenType() == quoteTk) { StringBuilder sb = new StringBuilder(); ++i; for (; i < tksr.size(); ++i) { tk = tksr.get(i); if (tk.getTokenType() == quoteTk) { if (previousWasSplitter == true) { ret.add(sb.toString()); } else { ret.set(ret.size() - 1, ret.get(ret.size() - 1) + sb.toString()); } previousWasSplitter = false; continue nextMainLoop; } String s = tk.getConsumed(); s = StringUtils.replace(s, ecapeQuote, "" + quoteChar); sb.append(s); } throw new IllegalArgumentException("Missing end Quote in " + text); } if (tk.getTokenType() == 0) { if (previousWasSplitter == false) { ret.set(ret.size() - 1, ret.get(ret.size() - 1) + unescape(tk.getConsumed(), escapeChar)); } else { ret.add(unescape(tk.getConsumed(), escapeChar)); } previousWasSplitter = false; } else { previousWasSplitter = true; if (returnDelimiter == true) { ret.add(tk.getConsumed()); } } } return ret; }
From source file:edu.uci.ics.hyracks.api.client.impl.JobActivityGraphBuilder.java
private <K, V> void insertIntoIndexedMap(Map<K, List<V>> map, K key, int index, V value) { List<V> vList = map.get(key); if (vList == null) { vList = new ArrayList<V>(); map.put(key, vList);/*from w w w .j av a 2 s.c o m*/ } extend(vList, index); vList.set(index, value); }
From source file:de.tudarmstadt.ukp.dkpro.spelling.experiments.hoo2012.hoo2011.FixedCandidateTrigramProbabilityDetector.java
private List<String> getChangedWords(String edit, List<String> words, int offset) { List<String> changedWords = new ArrayList<String>(words); changedWords.set(offset, edit); return changedWords; }
From source file:eionet.cr.web.action.JsonActionBean.java
/** * * @return//from ww w. j a v a 2 s . c o m * @throws DAOException */ public Resolution harvestSources() throws DAOException { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Getting harvest source suggestions ..."); } long startTime = System.currentTimeMillis(); String query = getContext().getRequestParameter("query"); List<String> sourceUrls = DAOFactory.get().getDao(HarvestSourceDAO.class).filter(query, 101, 0); if (sourceUrls.size() == 101) { sourceUrls.set(100, "Narrow your search for more ..."); } else if (sourceUrls.isEmpty()) { sourceUrls.add("No suggestions found!"); } if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Harvest source suggestions retrieved in " + (System.currentTimeMillis() - startTime) + " ms"); } return createSuggestionsResolution(sourceUrls, query); }
From source file:com.huateng.startup.init.MenuInfoUtil.java
/** * ??//w w w .j a v a 2s .co m */ @SuppressWarnings("unchecked") public static void init() { String hql = "from com.huateng.po.TblFuncInf t where t.FuncType in ('0','1','2') order by t.FuncId"; ICommQueryDAO commQueryDAO = (ICommQueryDAO) ContextUtil.getBean("CommQueryDAO"); List<TblFuncInf> funcInfList = commQueryDAO.findByHQLQuery(hql); for (int i = 0, n = funcInfList.size(); i < n; i++) { TblFuncInf tblFuncInf = funcInfList.get(i); if (Constants.MENU_LVL_1.equals(tblFuncInf.getFuncType())) {//?? Map<String, Object> menuBean = new LinkedHashMap<String, Object>(); String menuId = tblFuncInf.getFuncId().toString().trim(); menuBean.put(Constants.MENU_ID, menuId); menuBean.put(Constants.MENU_TEXT, tblFuncInf.getFuncName().trim()); menuBean.put(Constants.MENU_CLS, Constants.MENU_FOLDER); allMenuBean.addJSONArrayElement(menuBean); } else if (Constants.MENU_LVL_2.equals(tblFuncInf.getFuncType())) {//?? Map<String, Object> menuBean = new LinkedHashMap<String, Object>(); menuBean.put(Constants.MENU_ID, tblFuncInf.getFuncId().toString().trim()); menuBean.put(Constants.MENU_TEXT, tblFuncInf.getFuncName().trim()); menuBean.put(Constants.MENU_PARENT_ID, tblFuncInf.getFuncParentId().toString().trim()); menuBean.put(Constants.MENU_CLS, Constants.MENU_FOLDER); addLvl2Menu(menuBean); } else if (Constants.MENU_LVL_3.equals(tblFuncInf.getFuncType())) { Map<String, Object> menuBean = new LinkedHashMap<String, Object>(); menuBean.put(Constants.MENU_ID, tblFuncInf.getFuncId().toString().trim()); menuBean.put(Constants.MENU_TEXT, tblFuncInf.getFuncName().trim()); menuBean.put(Constants.MENU_PARENT_ID, tblFuncInf.getFuncParentId().toString().trim()); menuBean.put(Constants.MENU_LEAF, true); menuBean.put(Constants.MENU_URL, tblFuncInf.getPageUrl().trim()); menuBean.put(Constants.MENU_CLS, Constants.MENU_FILE); if ("-".equals(tblFuncInf.getIconPath().trim())) { menuBean.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM); } else { menuBean.put(Constants.TOOLBAR_ICON, tblFuncInf.getIconPath().trim()); } addLvl3Menu(menuBean); } } //?? List<Object> menuLvl1List = allMenuBean.getDataList(); for (int i = 0; i < menuLvl1List.size(); i++) { Map<String, Object> menuLvl1Bean = (Map<String, Object>) menuLvl1List.get(i); if (!menuLvl1Bean.containsKey(Constants.MENU_CHILDREN)) { menuLvl1List.remove(i); i--; continue; } List<Object> menuLvl2List = (List<Object>) menuLvl1Bean.get(Constants.MENU_CHILDREN); for (int j = 0; j < menuLvl2List.size(); j++) { Map<String, Object> menuLvl2Bean = (Map<String, Object>) menuLvl2List.get(j); if (!menuLvl2Bean.containsKey(Constants.MENU_CHILDREN)) { menuLvl2List.remove(j); menuLvl1Bean.put(Constants.MENU_CHILDREN, menuLvl2List); menuLvl1List.set(i, menuLvl1Bean); allMenuBean.setDataList(menuLvl1List); j--; } } } }
From source file:fr.inria.atlanmod.neoemf.data.berkeleydb.store.DirectWriteBerkeleyDBListsStore.java
@Override protected Object setReference(PersistentEObject object, EReference eReference, int index, PersistentEObject value) {//from w w w . j av a2 s . c o m Object oldId; FeatureKey featureKey = FeatureKey.from(object, eReference); updateContainment(object, eReference, value); updateInstanceOf(value); if (!eReference.isMany()) { oldId = persistenceBackend.storeValue(featureKey, value.id()); } else { List<Object> list = manyValueFrom(getFromMap(featureKey)); oldId = list.get(index); list.set(index, value.id()); persistenceBackend.storeValue(featureKey, list.toArray()); } return isNull(oldId) ? null : eObject((Id) oldId); }
From source file:fr.inria.atlanmod.neoemf.data.berkeleydb.store.DirectWriteBerkeleyDBListsStore.java
@Override protected Object setAttribute(PersistentEObject object, EAttribute eAttribute, int index, Object value) { Object oldValue;// w w w . j a v a2s . c o m FeatureKey featureKey = FeatureKey.from(object, eAttribute); if (!eAttribute.isMany()) { oldValue = persistenceBackend.storeValue(featureKey, serializeToProperty(eAttribute, value)); } else { List<Object> list = manyValueFrom(getFromMap(featureKey)); oldValue = list.get(index); list.set(index, serializeToProperty(eAttribute, value)); persistenceBackend.storeValue(featureKey, list.toArray()); oldValue = parseProperty(eAttribute, oldValue); } return parseProperty(eAttribute, oldValue); }
From source file:net.sf.eclipsecs.ui.quickfixes.coding.StringLiteralEqualityQuickfix.java
/** * {@inheritDoc}// www .ja v a2s. com */ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartPosition) { return new ASTVisitor() { public boolean visit(InfixExpression node) { if (containsPosition(lineInfo, node.getStartPosition())) { StringLiteral literal = null; Expression otherOperand = null; if (node.getLeftOperand() instanceof StringLiteral) { literal = (StringLiteral) node.getLeftOperand(); otherOperand = node.getRightOperand(); } else if (node.getRightOperand() instanceof StringLiteral) { literal = (StringLiteral) node.getRightOperand(); otherOperand = node.getLeftOperand(); } else { return true; } Expression replacementNode = null; MethodInvocation equalsInvocation = node.getAST().newMethodInvocation(); equalsInvocation.setName(node.getAST().newSimpleName("equals")); //$NON-NLS-1$ equalsInvocation.setExpression((Expression) ASTNode.copySubtree(node.getAST(), literal)); equalsInvocation.arguments().add(ASTNode.copySubtree(node.getAST(), otherOperand)); // if the string was compared with != create a not // expression if (node.getOperator().equals(InfixExpression.Operator.NOT_EQUALS)) { PrefixExpression prefixExpression = node.getAST().newPrefixExpression(); prefixExpression.setOperator(PrefixExpression.Operator.NOT); prefixExpression.setOperand(equalsInvocation); replacementNode = prefixExpression; } else { replacementNode = equalsInvocation; } replaceNode(node, replacementNode); } return true; } /** * Replaces the given node with the replacement node (using * reflection since I am not aware of a proper API to do this). * * @param node * the node to replace * @param replacementNode * the replacement */ private void replaceNode(ASTNode node, ASTNode replacementNode) { try { if (node.getLocationInParent().isChildProperty()) { String property = node.getLocationInParent().getId(); String setterMethodName = "set" + StringUtils.capitalize(property); Class testClass = node.getClass(); while (testClass != null) { try { Method setterMethod = node.getParent().getClass().getMethod(setterMethodName, testClass); setterMethod.invoke(node.getParent(), replacementNode); break; } catch (NoSuchMethodException e) { testClass = testClass.getSuperclass(); } } } else if (node.getLocationInParent().isChildListProperty()) { Method listMethod = node.getParent().getClass() .getMethod(node.getLocationInParent().getId(), (Class<?>[]) null); List list = (List) listMethod.invoke(node.getParent(), (Object[]) null); list.set(list.indexOf(node), replacementNode); } } catch (InvocationTargetException e) { CheckstyleLog.log(e); } catch (IllegalAccessException e) { CheckstyleLog.log(e); } catch (NoSuchMethodException e) { CheckstyleLog.log(e); } } }; }