Example usage for java.util List set

List of usage examples for java.util List set

Introduction

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

Prototype

E set(int index, E element);

Source Link

Document

Replaces the element at the specified position in this list with the specified element (optional operation).

Usage

From source file:com.thoughtworks.gauge.refactor.RefactoringMethodVisitor.java

private void refactor(MethodDeclaration methodDeclaration, StringLiteralExpr memberValue,
        SingleMemberAnnotationExpr annotation) {
    if (StringEscapeUtils.unescapeJava(memberValue.getValue()).trim()
            .equals(oldStepValue.getStepAnnotationText().trim())) {
        List<Parameter> newParameters = Arrays.asList(new Parameter[paramPositions.size()]);
        memberValue.setValue(newStepValue.getStepAnnotationText());
        List<Parameter> parameters = methodDeclaration.getParameters();
        for (int i = 0, paramPositionsSize = paramPositions.size(); i < paramPositionsSize; i++) {
            if (paramPositions.get(i).getOldPosition() < 0) {
                String paramName = Util.getValidJavaIdentifier(
                        Util.convertToCamelCase("arg " + newStepValue.getParameters().get(i)));
                if (paramName.equals("arg")) {
                    paramName += i;//from  w w w. j  a  v  a2s .  co  m
                }
                newParameters.set(paramPositions.get(i).getNewPosition(),
                        new Parameter(new ClassOrInterfaceType("String"), new VariableDeclaratorId(paramName)));
            } else
                newParameters.set(paramPositions.get(i).getNewPosition(),
                        parameters.get(paramPositions.get(i).getOldPosition()));
        }
        methodDeclaration.setParameters(newParameters);
        annotation.setMemberValue(memberValue);
        this.javaElement = new JavaRefactoringElement(getJavaFileText(methodDeclaration), null);
        this.refactored = true;
    }
}

From source file:com.googlecode.esms.provider.Vodafone.java

@Override
public List<Result> send(SMS sms) {
    int currReceiver = 0;
    int totReceivers = sms.getReceivers().size();
    List<Result> results = new LinkedList<Result>();
    for (int r = 0; r < totReceivers; ++r)
        results.add(Result.UNKNOWN_ERROR);

    try {/*w w w .ja  v a 2  s .  co m*/

        Result login = login();
        if (login != Result.SUCCESSFUL) {
            results.set(0, login);
            return results;
        }

        if (!senderCurrent.equalsIgnoreCase(sender)) {
            if (!doSwapSIM()) {
                results.set(0, Result.SENDER_ERROR);
                return results;
            }
        }

        for (int r = 0; r < totReceivers; ++r) {
            currReceiver = r;

            if (sms.getCaptchaText() == null || sms.getCaptchaText() == "") {
                int precheck = doPrecheck();
                if (precheck != 0) {
                    results.set(r, getResult(precheck));
                    return results;
                }

                int prepare = doPrepare(sms, r);
                if (prepare != 0) {
                    results.set(r, getResult(prepare));
                    return results;
                }

                if (sms.getCaptchaArray() != null) {
                    results.set(r, Result.CAPTCHA_NEEDED);
                    return results;
                }
            }

            // filter wrong CAPTCHA characters
            String captchaText = sms.getCaptchaText();
            if (captchaText != null) {
                captchaText.replaceAll("[^1-9A-NP-Za-np-z]*", "");
                sms.setCaptchaText(captchaText);
            }

            int send = doSend(sms, r);
            if (send != 0) {
                results.set(r, getResult(send));
                return results;
            }
            if (sms.getCaptchaArray() != null) {
                results.set(r, Result.CAPTCHA_NEEDED);
                return results;
            }

            updateCount();
            count += calcFragments(sms.getMessage().length());
            results.set(r, Result.SUCCESSFUL);
        }

    } catch (JDOMException je) {
        je.printStackTrace();
        results.set(currReceiver, Result.PROVIDER_ERROR);
    } catch (Exception e) {
        e.printStackTrace();
        results.set(currReceiver, Result.NETWORK_ERROR);
    }

    return results;
}

From source file:com.quattroresearch.antibody.SequenceFileReader.java

/**
 * Parses .fa Files <p> Parses all chains found in a fasta-formatted file. Sequence can be upper- or lower-case
 * letters, name is everything from ">".
 * //from  ww w. j  a  v a 2s  . c  o m
 * @param file .fa-File to parse
 * @return (List of chainnames, List of chainsequences)
 */
private List<String>[] readFastaFile(File file) {
    List<String> foundNames = new ArrayList<String>();
    List<String> foundChains = new ArrayList<String>();
    int current = -1;
    BufferedReader br = null;

    try {
        br = new BufferedReader(new FileReader(file));
        String line;
        while ((line = br.readLine()) != null) {
            String lineClean = line.trim();
            if (!lineClean.isEmpty()) {
                if (lineClean.startsWith(">")) {
                    foundNames.add(lineClean.split(">")[1]);
                    foundChains.add("");
                    current++;
                } else {
                    foundChains.set(current, foundChains.get(current) + lineClean);
                }
            }
        }
    } catch (FileNotFoundException e) {
        JOptionPane.showMessageDialog(parentFrame, "File " + file.getPath() + " was not found.");
        e.printStackTrace();
    } catch (IOException e) {
        JOptionPane.showMessageDialog(parentFrame, "Could not read file. (Line " + (current + 1) + ")");
        e.printStackTrace();
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    List<String>[] result = new List[2];
    result[0] = foundNames;
    result[1] = foundChains;

    return result;
}

From source file:ml.shifu.shifu.core.binning.MunroPatBinning.java

/**
 * set min/max, merge same bins/*from  w w  w  . ja va  2s. co m*/
 * In a very skewed data array, this one may not be well performed
 * 
 * @param bins
 *            input bins
 * @return merged bins
 */
private List<Double> binMerge(List<Double> bins) {
    List<Double> newBins = new ArrayList<Double>();
    if (bins.size() == 0) {
        bins.add(Double.NaN);
        return bins;
    }

    Double cur = bins.get(0);
    newBins.add(cur);

    int i = 1;
    while (i < bins.size()) {
        if (Math.abs(cur - bins.get(i)) > 1e-10) {
            newBins.add(bins.get(i));
        }
        cur = bins.get(i);
        i++;
    }

    if (newBins.size() == 1) {
        // special case since there is only 1 candidate in the bins
        double val = newBins.get(0);
        newBins = Arrays.asList(new Double[] { Double.NEGATIVE_INFINITY, val });
    } else if (newBins.size() == 2) {
        newBins.set(0, Double.NEGATIVE_INFINITY);
    } else {
        newBins.set(0, Double.NEGATIVE_INFINITY);
        // remove the max, and became open interval
        newBins.remove(newBins.size() - 1);
    }
    return newBins;
}

From source file:org.openmrs.web.controller.report.PatientSearchFormController.java

protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj,
        BindException errors) throws Exception {

    String success = "";
    String error = "";
    HttpSession httpSession = request.getSession();
    String view = getSuccessView();
    if (Context.isAuthenticated()) {
        MessageSourceAccessor msa = getMessageSourceAccessor();
        String action = request.getParameter("action");
        if (msa.getMessage("reportingcompatibility.PatientSearch.save").equals(action)) {
            PatientSearchReportObject psroBinded = (PatientSearchReportObject) obj;
            String hiddenName = request.getParameter("hiddenName");
            String hiddenDesc = request.getParameter("hiddenDesc");
            int hasXMLChanged = 0;
            hasXMLChanged = Integer.parseInt(request.getParameter("patientSearchXMLHasChanged"));
            String textAreaXML = request.getParameter("xmlStringTextArea");
            Integer argumentsLength = Integer.valueOf(request.getParameter("argumentsSize"));
            PatientSearch ps = null;//from   w ww .  j  a v  a2  s. co  m
            String valueRoot = "value";
            String hiddenValueRoot = "hiddenValue";
            int testXMLerror = 0;
            List<Integer> needsUpdate = new ArrayList<Integer>();

            for (int i = 0; i < argumentsLength; i++) {
                String hv = request.getParameter(hiddenValueRoot + i);
                String v = request.getParameter(valueRoot + i);

                if (hv.compareTo(v) != 0)
                    needsUpdate.add(i);
            }

            String saved = msa.getMessage("reportingcompatibility.PatientSearch.saved");
            String notsaved = msa.getMessage("reportingcompatibility.PatientSearch.notsaved");
            String invalidXML = msa.getMessage("reportingcompatibility.PatientSearch.invalidXML");
            String title = msa.getMessage("reportingcompatibility.PatientSearch.title");

            boolean hasNewSearchArg = false;
            String newSearchArgName = (String) request.getParameter("newSearchArgName");
            String newSearchArgValue = (String) request.getParameter("newSearchArgValue");
            String newSearchArgClass = (String) request.getParameter("newSearchArgClass");
            if (StringUtils.hasText(newSearchArgName) || StringUtils.hasText(newSearchArgValue)
                    || StringUtils.hasText(newSearchArgClass)) {
                hasNewSearchArg = true;
            }

            if (hiddenName.compareTo(psroBinded.getName()) != 0
                    || hiddenDesc.compareTo(psroBinded.getDescription()) != 0 || needsUpdate.size() > 0
                    || hasXMLChanged == 1 || hasNewSearchArg) {

                if (needsUpdate.size() > 0) {

                    ps = psroBinded.getPatientSearch();
                    List<SearchArgument> searchArguments = ps.getArguments();

                    for (Integer myI : needsUpdate) {
                        SearchArgument sA = (SearchArgument) searchArguments.get(myI);
                        SearchArgument newSA = new SearchArgument();
                        newSA.setName(sA.getName());
                        newSA.setPropertyClass(sA.getPropertyClass());
                        newSA.setValue(request.getParameter(valueRoot + myI));
                        searchArguments.set(myI, newSA);

                    }
                    ps.setArguments(searchArguments);
                    psroBinded.setPatientSearch(ps);
                }

                if (hasXMLChanged == 1) {
                    try {
                        ReportObjectXMLDecoder roxd = new ReportObjectXMLDecoder(textAreaXML);

                        PatientSearchReportObject psroFromXML = (PatientSearchReportObject) roxd
                                .toAbstractReportObject();
                        psroBinded.setDescription(psroFromXML.getDescription());
                        psroBinded.setName(psroFromXML.getName());
                        psroBinded.setPatientSearch(psroFromXML.getPatientSearch());
                        psroBinded.setSubType(psroFromXML.getSubType());
                        psroBinded.setType(psroFromXML.getType());

                    } catch (Exception ex) {
                        log.warn("Invalid Patient Search XML", ex);
                        error += title + " " + notsaved + ", " + invalidXML;
                        testXMLerror++;
                    }
                }

                if (hasNewSearchArg) {
                    if (StringUtils.hasText(newSearchArgName) && StringUtils.hasText(newSearchArgValue)
                            && StringUtils.hasText(newSearchArgClass)) {
                        try {
                            psroBinded.getPatientSearch().addArgument(newSearchArgName, newSearchArgValue,
                                    Class.forName(newSearchArgClass));
                        } catch (Exception e) {
                            error += msa
                                    .getMessage("reportingcompatibility.PatientSearch.invalidSearchArgument");
                        }
                    } else {
                        error += msa.getMessage("reportingcompatibility.PatientSearch.invalidSearchArgument");
                    }
                    log.debug("Patient Search now has arguments: "
                            + psroBinded.getPatientSearch().getArguments());
                }

                if (testXMLerror != 1 || hasNewSearchArg) {
                    ReportObjectService rs = (ReportObjectService) Context
                            .getService(ReportObjectService.class);
                    rs.saveReportObject(psroBinded);
                    success = saved;
                }
            }
        }
    }
    if (!error.equals(""))
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error);
    else if (!success.equals(""))
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success);

    return new ModelAndView(new RedirectView(view));
}

From source file:ai.grakn.test.graql.shell.GraqlShellIT.java

private String[] specifyUniqueKeyspace(String[] args) {
    List<String> argList = Lists.newArrayList(args);

    int keyspaceIndex = argList.indexOf("-k") + 1;
    if (keyspaceIndex == 0) {
        argList.add("-k");
        argList.add(GraqlShell.DEFAULT_KEYSPACE);
        keyspaceIndex = argList.size() - 1;
    }/*  w  ww  .  j a va  2 s  .c o  m*/

    argList.set(keyspaceIndex, argList.get(keyspaceIndex) + keyspaceSuffix);

    return argList.toArray(new String[argList.size()]);
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo.java

/**
 * The List targets will be modified./*from  w w  w .  ja  va 2  s  .  co m*/
 */
public void subInUris(Map<String, String> varsToVals, List<String> targets) {
    if (varsToVals == null || varsToVals.isEmpty() || targets == null)
        return;

    for (int i = 0; i < targets.size(); i++) {
        String result = targets.get(i);
        if (result == null)
            continue;
        for (String key : varsToVals.keySet()) {
            result = subInUris(key, varsToVals.get(key), result);
        }
        targets.set(i, result);
    }
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.RemoveRedundantVariablesRule.java

/**
 * Replace the projects's variables with their corresponding representative
 * from the equivalence class map (if any).
 * We cannot use the VariableSubstitutionVisitor here because the project ops
 * maintain their variables as a list and not as expressions.
 *//*from w ww  .  jav a2  s  . c  om*/
private boolean replaceProjectVars(ProjectOperator op) throws AlgebricksException {
    List<LogicalVariable> vars = op.getVariables();
    int size = vars.size();
    boolean modified = false;
    for (int i = 0; i < size; i++) {
        LogicalVariable var = vars.get(i);
        List<LogicalVariable> equivalentVars = equivalentVarsMap.get(var);
        if (equivalentVars == null) {
            continue;
        }
        // Replace with equivalence class representative.
        LogicalVariable representative = equivalentVars.get(0);
        if (representative != var) {
            vars.set(i, equivalentVars.get(0));
            modified = true;
        }
    }
    return modified;
}

From source file:additionalpipes.client.gui.GuiTeleportTether.java

@SuppressWarnings("unchecked")
@Override/*from  ww  w  .  j  ava2  s.c  om*/
protected void drawItemStackTooltip(ItemStack stack, int x, int y) {
    int side = ArrayUtils.indexOf(clientProps.tetherInventory.getStacks(), stack);
    if (side != -1) {
        List<String> list = stack.getTooltip(mc.thePlayer, mc.gameSettings.advancedItemTooltips);

        String type;
        switch (side) {
        case 0:
            type = "north";
            break;
        case 1:
            type = "east";
            break;
        case 2:
            type = "south";
            break;
        case 3:
            type = "west";
            break;
        default:
            type = "self";
            break;
        }
        list.add(1, EnumChatFormatting.AQUA + StringUtils.localize("tile.teleportTether." + type));

        for (int i = 0; i < list.size(); ++i) {
            if (i == 0) {
                list.set(i, "\u00a7" + Integer.toHexString(stack.getRarity().rarityColor) + list.get(i));
            } else {
                list.set(i, EnumChatFormatting.GRAY + list.get(i));
            }
        }

        FontRenderer font = stack.getItem().getFontRenderer(stack);
        drawHoveringText(list, x, y, font == null ? fontRenderer : font);
    } else {
        super.drawItemStackTooltip(stack, x, y);
    }
}

From source file:io.pelle.mango.db.dao.BaseEntityDAO.java

@SuppressWarnings("unchecked")
private <T extends IBaseEntity> T mergeRecursive(T entity, String currentPath) {

    // TODO use dirty paths?
    for (ObjectFieldDescriptor fieldDescriptor : new ObjectFieldIterator(entity)) {

        Object sourceValue = fieldDescriptor.getSourceValue(entity);
        if (sourceValue instanceof IBaseEntity) {

            checkLoaded(entity, fieldDescriptor);

            IBaseEntity entityAttribute = (IBaseEntity) sourceValue;
            IBaseEntity mergedEntityAttribute = mergeRecursive(entityAttribute, currentPath);

            try {
                fieldDescriptor.getSourceWriteMethod().invoke(entity, mergedEntityAttribute);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }/*from  w  ww .  jav a  2  s .  c  om*/

        } else if (sourceValue instanceof List) {

            checkLoaded(entity, fieldDescriptor);

            List<Object> sourceList = (List<Object>) sourceValue;

            for (int i = 0; i < sourceList.size(); i++) {

                Object listItem = sourceList.get(i);

                if (listItem instanceof IBaseEntity) {
                    IBaseEntity baseEntityListItem = (IBaseEntity) listItem;
                    IBaseEntity mergedEntityListItem = mergeRecursive(baseEntityListItem, currentPath);
                    sourceList.set(i, mergedEntityListItem);
                } else {
                    sourceList.set(i, listItem);
                }
            }

            continue;
        }
    }

    return this.entityManager.merge(entity);

}