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:edu.unc.lib.dl.cdr.services.model.FailedEnhancementMapTest.java

@Test
public void test() throws Exception {
    java.util.List<String> test = Arrays.asList("one", "two");
    test.set(1, "barf");
    System.out.println(test);//from  w  w  w.  j ava  2s .  c om
}

From source file:it.incipict.tool.profiles.util.ProfilesToolUtils.java

public static List<Double> calcRanks(List<Survey> surveys) {
    List<Double> ranks = new ArrayList<Double>();
    Map<String, Double> TextualAnswersMap = new Survey().getTextualAnswersMap();

    int count = 0;
    for (Survey survey : surveys) {
        Map<String, Double> surveyMap = survey.getTextualAnswersMap();
        count++;// w  w w .j  a v a2 s  . c o  m
        for (int i = 0; i < survey.getAnswers().size(); i++) {
            String r = survey.getAnswers().get(i);
            // first of all sum the answersVectors for all surveys of this
            // profile and store the sum in a new list
            // this condition match the numerical values
            if (r.matches("\\d*")) {
                if (count == 1) {
                    // first survey
                    ranks.add(Double.parseDouble(r));
                } else {
                    // sum all elements of vector (REMARK: A+B = a1+b1,
                    // a2+b2, ..., an+bn)
                    ranks.set(i, (ranks.get(i) + Double.parseDouble(r)));
                }
            }
            // now count all strings occurences in textualAnswers
            // (checkbox/radio/etc..)
            // for the current survey.
            else {
                if (surveyMap.containsKey(r)) {
                    Double old = TextualAnswersMap.get(r);
                    TextualAnswersMap.replace(r, (old + surveyMap.get(r)));
                }
            }
        }
    }
    // append in queue all hashmap's values.
    List<Double> mapValues = new ArrayList<Double>(TextualAnswersMap.values());
    ranks.addAll(mapValues);

    // finally calculate the statistical average for each element of vector
    // divided by total of surveys.
    for (int i = 0; i < ranks.size(); i++) {
        Double f = ranks.get(i);
        ranks.set(i, ((f / surveys.size())));
    }
    // Normalizing the matrix with 0-1 probabilistic value.
    // Note: in INCIPICT Survey Form the max range for the questions 1-27 is 5
    // Divide this answers per 5
    // because we want to obtain as result a probabilistic matrix with 0-1 values 
    // for this reason we divide all elements by they max range value
    // in this mode we obtain a percentage values 0%-100% represented by double values (0.00-1.00)
    ranks = (ProfilesToolUtils.divideByScalar(ranks, SCALAR, RANGE_START, RANGE_END));

    // return the ranks list for this profile.
    return ranks;
}

From source file:ml.shifu.shifu.util.NormalUtils.java

/**
 * Normalize variable by (modelType, normMethod). One variable val could be normalized into multi double value
 *
 * @param modelConfig - to check modelType. TreeModel or NN/LR model?
 * @param cutoff      - cutoff for ZScale
 * @param config      - variable configuration
 * @param val         - raw variable value
 * @return - most normalization method return 1 element double list,
 * but OneHot will will return multi-elements double list
 *///from   ww w .j  a v a  2  s .  co m
private static List<Double> computeNumericNormResult(ModelConfig modelConfig, double cutoff,
        ColumnConfig config, String val) {
    List<Double> normalizeValue = null;
    if (CommonUtils.isTreeModel(modelConfig.getAlgorithm())) {
        try {
            normalizeValue = Arrays.asList(new Double[] { Double.parseDouble(val) });
        } catch (Exception e) {
            normalizeValue = Arrays.asList(new Double[] { Normalizer.defaultMissingValue(config) });
        }
    } else {
        normalizeValue = Normalizer.normalize(config, val, cutoff, modelConfig.getNormalizeType());
    }

    if (CollectionUtils.isNotEmpty(normalizeValue)) {
        for (int i = 0; i < normalizeValue.size(); i++) {
            Double nval = normalizeValue.get(i);
            if (Double.isInfinite(nval) || Double.isNaN(nval)) {
                // if the value is Infinite or NaN, treat it as missing value
                // should treat Infinite as missing value also?
                normalizeValue.set(i, defaultMissingValue(config));
            }
        }
    }
    return normalizeValue;
}

From source file:cn.sel.wetty.interceptor.AccessLogger.java

private String getHeaders(HttpServletResponse response) {
    List<String> headers = response.getHeaderNames().stream().collect(Collectors.toList());
    for (int i = 0; i < headers.size(); i++) {
        String header = headers.get(i);
        headers.set(i, String.format("%s=%s", header, response.getHeader(header)));
    }/*from  w ww . j  av  a  2 s  .com*/
    return Arrays.toString(headers.toArray(new String[headers.size()]));
}

From source file:quanlyhocvu.api.mongodb.DAO.DiemDAO.java

public boolean updateDiemSo(String loaiDiem, String idDiem, Float diemCu, Float diemMoi) {
    DiemDTO dto = getDiemById(idDiem);/*from  w  w  w  . ja v a  2s  . com*/
    if (loaiDiem == "DiemKTMieng") {
        List<Float> tempList = dto.getListDiemKTMieng();
        int index = tempList.indexOf(diemCu);
        tempList.set(index, diemMoi);
        dto.setListDiemKTMieng(tempList);
    } else if (loaiDiem == "DiemKT15") {
        List<Float> tempList = dto.getListDiemKT15();
        int index = tempList.indexOf(diemCu);
        tempList.set(index, diemMoi);
        dto.setListDiemKTMieng(tempList);
    } else if (loaiDiem == "DiemKT15") {
        List<Float> tempList = dto.getListDiemKT1Tiet();
        int index = tempList.indexOf(diemCu);
        tempList.set(index, diemMoi);
        dto.setListDiemKTMieng(tempList);
    } else if (loaiDiem == "DiemGiuaKy") {
        dto.setDiemGiuaKy(diemMoi);
    } else if (loaiDiem == "DiemCuoiKy") {
        dto.setDiemCuoiKy(diemMoi);
    }

    update(dto);
    return true;
}

From source file:jef.tools.collection.CollectionUtils.java

/**
 * List???list/*from w  ww  .j  a  va2 s  . c  o m*/
 * 
 * @param list
 *            List
 * @param index
 *            ??
 * @param value
 *            
 */
public static <T> void setElement(List<T> list, int index, T value) {
    if (index == list.size()) {
        list.add(value);
    } else if (index > list.size()) {
        for (int i = list.size(); i < index; i++) {
            list.add(null);
        }
        list.add(value);
    } else {
        list.set(index, value);
    }
}

From source file:io.mapzone.arena.analytics.graph.ui.OlFeatureGraphUI.java

@Override
public void updateGeometry(Edge edge, Node node, Coordinate newCoordinate) {
    OlFeature line = edges.get(edge.key());
    if (line != null) {
        LineStringGeometry geometry = ((LineStringGeometry) line.geometry.get());
        List<Coordinate> coordinates = geometry.coordinates.get();
        coordinates.set((edge.key().startsWith(node.key())) ? 0 : 1, newCoordinate);
        geometry.coordinates.set(coordinates);
    }//from w  w w.ja v a2  s.c o  m
}

From source file:com.wealdtech.jackson.modules.TriValBeanSerializerModifier.java

@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc,
        List<BeanPropertyWriter> beanProperties) {
    for (int i = 0; i < beanProperties.size(); ++i) {
        final BeanPropertyWriter writer = beanProperties.get(i);
        if (TriVal.class.isAssignableFrom(writer.getPropertyType())) {
            beanProperties.set(i, new TriValBeanPropertyWriter(writer));
        }/*from  w  w  w .j  a  va2  s .  c  o m*/
    }

    return beanProperties;
}

From source file:com.nttec.everychan.ui.tabs.TabsTrackerService.java

/**  ,   ?   ? ? (  ) */
public static void addSubscriptionNotification(String tabUrl, String postNumber, String tabTitle) {
    List<Triple<String, String, String>> list = subscriptionsData;
    if (list == null)
        list = new ArrayList<>();
    int index = findTab(list, tabUrl, tabTitle);
    if (index == -1) {
        String postUrl = tabUrl;//from  ww  w .j a  v  a 2 s . c  o m
        try {
            UrlPageModel pageModel = UrlHandler.getPageModel(tabUrl);
            if (pageModel != null) {
                pageModel.postNumber = postNumber;
                postUrl = MainApplication.getInstance().getChanModule(pageModel.chanName).buildUrl(pageModel);
            }
        } catch (Exception e) {
            Logger.e(TAG, e);
        }
        list.add(Triple.of(tabUrl, postUrl, tabTitle));
    } else {
        String postUrl = list.get(index).getMiddle();
        list.set(index, Triple.of(tabUrl, postUrl, tabTitle));
    }
    subscriptionsData = list;
    subscriptions = true;
}

From source file:com.wavemaker.runtime.server.json.JSONUtils.java

public static List<FieldDefinition> getParameterTypes(Method m, JSONArray params, TypeState typeState) {

    List<FieldDefinition> fieldDefinitions = new ArrayList<FieldDefinition>();
    for (Type type : m.getGenericParameterTypes()) {
        fieldDefinitions.add(ReflectTypeUtils.getFieldDefinition(type, typeState, false, null));
    }//from   w  w w  . j  a v  a 2  s  . c  om

    Annotation[][] paramAnnotations = m.getParameterAnnotations();

    for (int i = 0; i < paramAnnotations.length; i++) {
        for (Annotation ann : paramAnnotations[i]) {
            if (ann instanceof JSONParameterTypeField) {

                JSONParameterTypeField paramTypeField = (JSONParameterTypeField) ann;
                int pos = paramTypeField.typeParameter();
                String typeString = (String) params.get(pos);

                try {
                    Class<?> newType = org.springframework.util.ClassUtils.forName(typeString);

                    if (Collection.class.isAssignableFrom(newType)) {
                        throw new WMRuntimeException(MessageResource.JSONUTILS_PARAMTYPEGENERIC, i,
                                m.getName());
                    }

                    fieldDefinitions.set(i,
                            ReflectTypeUtils.getFieldDefinition(newType, typeState, false, null));
                } catch (ClassNotFoundException e) {
                    throw new WMRuntimeException(MessageResource.JSONPARAMETER_COULD_NOTLLOAD_TYPE, e,
                            typeString, m.getName(), i);
                } catch (LinkageError e) {
                    throw new WMRuntimeException(e);
                }
            }
        }
    }

    return fieldDefinitions;
}