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.pinterest.deployservice.buildtags.BuildTagsManagerImpl.java

public static List<BuildTagBean> sortAndDedupTags(List<BuildTagBean> buildTagBeanList) throws Exception {
    //Sort by commit date for later search
    Collections.sort(buildTagBeanList, new Comparator<BuildTagBean>() {
        @Override/*from  www . j  av a 2 s  . co  m*/
        public int compare(BuildTagBean o1, BuildTagBean o2) {
            if (!o1.getBuild().getCommit_date().equals(o2.getBuild().getCommit_date())) {
                return o1.getBuild().getCommit_date().compareTo(o2.getBuild().getCommit_date());
            } else {
                //Same commit. sort by created date
                return o1.getTag().getCreated_date().compareTo(o2.getTag().getCreated_date());
            }

        }
    });

    //In some cases, one commit can have multiple tags applied. Let's only use the latest created
    List<BuildTagBean> dedup = new ArrayList<>(buildTagBeanList.size());
    BuildTagBean prev = null;
    for (BuildTagBean buildTagBean : buildTagBeanList) {
        if (prev == null || !StringUtils.equals(prev.getBuild().getScm_commit(),
                buildTagBean.getBuild().getScm_commit())) {
            dedup.add(buildTagBean);
        } else {
            //Overwrite as we already sort by commit and tag created date above
            dedup.set(dedup.size() - 1, buildTagBean);
        }
        prev = buildTagBean;
    }
    return dedup;
}

From source file:com.easemob.dataexport.utils.JsonUtils.java

public static Object normalizeJsonTree(Object obj) {
    if (obj instanceof Map) {
        @SuppressWarnings("unchecked")
        Map<Object, Object> m = (Map<Object, Object>) obj;
        Object o;/*from  www. j  a  v a 2 s  .  c  om*/
        UUID uuid;
        for (Object k : m.keySet()) {
            if (k instanceof String && ((String) k).equalsIgnoreCase("name")) {
                continue;
            }

            o = m.get(k);
            uuid = tryConvertToUUID(o);
            if (uuid != null) {
                m.put(k, uuid);
            } else if (o instanceof Integer) {
                m.put(k, ((Integer) o).longValue());
            } else if (o instanceof BigInteger) {
                m.put(k, ((BigInteger) o).longValue());
            }
        }
    } else if (obj instanceof List) {
        @SuppressWarnings("unchecked")
        List<Object> l = (List<Object>) obj;
        Object o;
        UUID uuid;
        for (int i = 0; i < l.size(); i++) {
            o = l.get(i);
            uuid = tryConvertToUUID(o);
            if (uuid != null) {
                l.set(i, uuid);
            } else if ((o instanceof Map) || (o instanceof List)) {
                normalizeJsonTree(o);
            } else if (o instanceof Integer) {
                l.set(i, ((Integer) o).longValue());
            } else if (o instanceof BigInteger) {
                l.set(i, ((BigInteger) o).longValue());
            }
        }
    } else if (obj instanceof String) {
        UUID uuid = tryConvertToUUID(obj);
        if (uuid != null) {
            return uuid;
        }
    } else if (obj instanceof Integer) {
        return ((Integer) obj).longValue();
    } else if (obj instanceof BigInteger) {
        return ((BigInteger) obj).longValue();
    } else if (obj instanceof JsonNode) {
        return mapper.convertValue(obj, Object.class);
    }
    return obj;
}

From source file:com.twosigma.beakerx.table.serializer.TableDisplayDeSerializer.java

@NotNull
private static Object handleIndex(JsonNode n, ObjectMapper mapper, List<List<?>> values, List<String> columns,
        List<String> classes) throws IOException {
    List<String> indexName = (List<String>) mapper.readValue(n.get(INDEX_NAME).toString(), List.class);
    boolean standardIndex = indexName.size() == 1 && indexName.get(0).equals(INDEX);
    if (standardIndex) {
        columns.remove(0);/*from   w ww.ja v a  2 s .  co m*/
        classes.remove(0);
        for (List<?> v : values) {
            v.remove(0);
        }
    } else {
        columns.set(0, join(", ", indexName.stream().map(TableDisplayDeSerializer::convertNullToIndexName)
                .collect(Collectors.toList())));
    }
    TableDisplay td = new TableDisplay(values, columns, classes);
    if (!standardIndex) {
        td.setHasIndex("true");
    }
    return td;
}

From source file:com.dungnv.vfw5.base.utils.StringUtils.java

public static void trimString(Object obj, boolean isLower) {
    String oldData = "";
    String newData = "";
    try {// www . ja  va  2  s . c o m
        if (obj != null) {
            Class escapeClass = obj.getClass();
            Field fields[] = escapeClass.getDeclaredFields();
            Field superFields[] = escapeClass.getSuperclass().getDeclaredFields();
            Field allField[] = new Field[fields.length + superFields.length];
            System.arraycopy(fields, 0, allField, 0, fields.length);
            System.arraycopy(superFields, 0, allField, fields.length, superFields.length);
            for (Field f : allField) {
                f.setAccessible(true);
                if (f.getType().equals(java.lang.String.class) && !Modifier.isFinal(f.getModifiers())) {
                    if (f.get(obj) != null) {
                        oldData = f.get(obj).toString();
                        newData = isLower ? oldData.trim().toLowerCase() : oldData.trim();
                        f.set(obj, newData);
                    }
                } else if (f.getType().isArray()) {
                    if (f.getType().getComponentType().equals(java.lang.String.class)) {
                        String[] tmpArr = (String[]) f.get(obj);
                        if (tmpArr != null) {
                            for (int i = 0; i < tmpArr.length; i++) {
                                tmpArr[i] = isLower ? tmpArr[i].trim().toLowerCase() : tmpArr[i].trim();
                            }
                            f.set(obj, tmpArr);
                        }
                    }
                } else if (f.get(obj) instanceof List) {
                    List<Object> tmpList = (List<Object>) f.get(obj);
                    for (int i = 0; i < tmpList.size(); i++) {
                        if (tmpList.get(i) instanceof java.lang.String) {
                            tmpList.set(i, isLower ? tmpList.get(i).toString().trim().toLowerCase()
                                    : tmpList.get(i).toString().trim());
                        }
                    }
                    f.set(obj, tmpList);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.dungnv.vfw5.base.utils.StringUtils.java

public static void escapeHTMLString(Object escapeObject) {
    String oldData = "";
    String newData = "";
    try {//from ww w. j av  a2 s.  com
        if (escapeObject != null) {
            Class escapeClass = escapeObject.getClass();
            Field fields[] = escapeClass.getDeclaredFields();
            Field superFields[] = escapeClass.getSuperclass().getDeclaredFields();
            Field allField[] = new Field[fields.length + superFields.length];
            System.arraycopy(fields, 0, allField, 0, fields.length);
            System.arraycopy(superFields, 0, allField, fields.length, superFields.length);
            for (Field f : allField) {
                f.setAccessible(true);
                if (f.getType().equals(java.lang.String.class) && !Modifier.isFinal(f.getModifiers())) {
                    if (f.get(escapeObject) != null) {
                        oldData = f.get(escapeObject).toString();
                        newData = StringEscapeUtils.escapeSql(oldData);
                        f.set(escapeObject, newData);
                    }
                } else if (f.getType().isArray()) {
                    if (f.getType().getComponentType().equals(java.lang.String.class)) {
                        String[] tmpArr = (String[]) f.get(escapeObject);
                        if (tmpArr != null) {
                            for (int i = 0; i < tmpArr.length; i++) {
                                tmpArr[i] = StringEscapeUtils.escapeSql(tmpArr[i]);
                            }
                            f.set(escapeObject, tmpArr);
                        }
                    }
                } else if (f.get(escapeObject) instanceof List) {
                    List<Object> tmpList = (List<Object>) f.get(escapeObject);
                    for (int i = 0; i < tmpList.size(); i++) {
                        if (tmpList.get(i) instanceof java.lang.String) {
                            tmpList.set(i, StringEscapeUtils.escapeSql(tmpList.get(i).toString()));
                        }
                    }
                    f.set(escapeObject, tmpList);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:tsapalos.bill.play4share.UrlUtils.java

public static List<String> exportVideoUrl(String pageSource) throws NullPointerException {
    final String youtube = "YouTube", dailymotion = "Dailymotion", liveleak = "LiveLeak", vimeo = "Vimeo",
            gag9 = "9gag.tv";
    Map<String, List<String>> indices = new HashMap<String, List<String>>(3);
    final String[] start = new String[] { "data-videoid=\"", ".youtube.com/embed/", ".youtube.com/watch?v=",
            ".youtube.com/v/", ".dailymotion.com/video/", //4
            "liveleak.com/ll_embed?f=", //5
            "player.vimeo.com/video/", //6
            "data-first-video=\"", //7
            "img.youtube.com/vi/", //8
            "data-external-id=\"" //9

    };/*  w w  w .  j av  a 2 s.  c o m*/
    final int[] start_advance = new int[] { 14, 19, 21, 15, 23, //4
            24, //5
            23, //6
            18, //7
            19, //8
            18 //9
    };
    final String[] end = new String[] { "\"", "\'", "/" //8

    };
    String videoUrl = null, videoId = null, server = null;
    boolean found = false;

    for (int i = 0; i < start.length; i++) {
        for (int j = 0; j < end.length; j++) {
            if (pageSource.contains(start[i])) {
                // find all occurrences of the specific string
                int index = pageSource.indexOf(start[i]);
                while (index >= 0) {
                    // sniff the possible start of the url of the
                    // video
                    videoUrl = pageSource.substring(index + start_advance[i]);
                    // use this check to avoid StringIndexOutOfBoundsException if string does not exist
                    // then sniff the possible end of the url of the video
                    if (videoUrl.contains(end[j])) {
                        videoUrl = videoUrl.substring(0, videoUrl.indexOf(end[j]));
                    } else {
                        break;
                    }
                    videoId = retrieveVideoId(videoUrl);
                    // store every video id found
                    if (videoId != null) {
                        switch (i) {
                        case 4:
                            server = dailymotion;
                            break;
                        case 5:
                            server = liveleak;
                            break;
                        case 6:
                            server = vimeo;
                            break;
                        default:
                            server = youtube;
                            break;
                        }
                        List<String> currentValue = indices.get(server);
                        if (currentValue == null) {
                            currentValue = new ArrayList<String>();
                            indices.put(server, currentValue);
                        }
                        if (!currentValue.contains(videoId)) {
                            currentValue.add(videoId);
                        }
                    }
                    index = pageSource.indexOf(start[i], index + 1);
                }
            }
        }
    }
    // create the list with all videos' urls
    List<String> videosUrls = new ArrayList<String>(3);
    // convert every video id to appropriate url
    for (Map.Entry<String, List<String>> entry : indices.entrySet()) {
        if (entry != null) {
            List<String> videosIds = entry.getValue();
            found = true;
            // create the video URL according to the server
            if (entry.getKey().equals(dailymotion)) {
                for (int j = 0; j < videosIds.size(); j++) {
                    videoId = videosIds.get(j);
                    videosIds.set(j, "http://www.dailymotion.com/video/" + videoId);
                    // Log.e("DAILYMOTION-" + j, videosIds.get(j));
                    // add the url to the total list
                    videosUrls.add(videosIds.get(j));
                }
            } else if (entry.getKey().equals(liveleak)) {
                for (int j = 0; j < videosIds.size(); j++) {
                    videoId = videosIds.get(j);
                    videosIds.set(j, "http://www.liveleak.com/ll_embed?f=" + videoId);
                    // Log.e("LIVELEAK-" + j, videosIds.get(j));
                    // add the url to the total list
                    videosUrls.add(videosIds.get(j));
                }
            } else if (entry.getKey().equals(vimeo)) {
                for (int j = 0; j < videosIds.size(); j++) {
                    videoId = videosIds.get(j);
                    videosIds.set(j, "http://player.vimeo.com/video/" + videoId);
                    // Log.e("VIMEO-" + j, videosIds.get(j));
                    // add the url to the total list
                    videosUrls.add(videosIds.get(j));
                }
            } else {
                for (int j = 0; j < videosIds.size(); j++) {
                    videoId = videosIds.get(j);
                    videosIds.set(j, "http://www.youtube.com/watch?v=" + videoId);
                    // Log.e("YOUTUBE-" + j, videosIds.get(j));
                    // add the url to the total list
                    videosUrls.add(videosIds.get(j));
                }
            }
        }
    }
    // throw exception if no video found
    if (!found)

    {
        throw new NullPointerException("No videos found");
    }

    return videosUrls;
}

From source file:com.tinyhydra.botd.BotdServerOperations.java

private static void SortShopList(List<JavaShop> shopList, int left, int right) {
    int i = left, j = right;
    JavaShop tmp;/*from w w  w. ja  v  a 2 s .  c  om*/
    JavaShop pivot = shopList.get((left + right) / 2);

    while (i <= j) {
        while (shopList.get(i).getVotes() > pivot.getVotes())
            i++;
        while (shopList.get(j).getVotes() < pivot.getVotes())
            j--;
        if (i <= j) {
            tmp = shopList.get(i);
            shopList.set(i, shopList.get(j));
            shopList.set(j, tmp);
            i++;
            j--;
        }
    }

    if (left < i - 1)
        SortShopList(shopList, left, i - 1);
    if (i < right)
        SortShopList(shopList, i, right);
}

From source file:Lists.java

public static <T> List<T> set(List<T> list, int index, T e) {
    switch (list.size()) {
    case 0:/*from   ww w  .j  a v a 2 s  .  c  o  m*/
        // Empty
        throw newIndexOutOfBounds(list, index);
    case 1:
        // Singleton
        if (index == 0) {
            return Collections.singletonList(e);
        } else {
            throw newIndexOutOfBounds(list, index);
        }
    default:
        // ArrayList
        list.set(index, e);
        return list;
    }
}

From source file:bboss.org.apache.velocity.util.StringUtils.java

/**
 * Trim all strings in a List.  Changes the strings in the existing list.
 * @param list/* ww  w .j  av a 2s  .  c  om*/
 * @return List of trimmed strings.
 * @since 1.5
 */
public static List trimStrings(List list) {
    if (list == null)
        return null;

    int sz = list.size();
    for (int i = 0; i < sz; i++)
        list.set(i, nullTrim((String) list.get(i)));
    return list;
}

From source file:com.turt2live.xmail.mail.attachment.ItemAttachment.java

@SuppressWarnings("unchecked")
public static ItemAttachment deserializeFromJson(String content) {
    JSONParser parser = new JSONParser();
    ContainerFactory containerFactory = new ContainerFactory() {
        @Override/*w w  w.  j  av a  2 s .c o  m*/
        public List<Object> creatArrayContainer() {
            return new LinkedList<Object>();
        }

        @Override
        public Map<String, Object> createObjectContainer() {
            return new LinkedHashMap<String, Object>();
        }

    };

    Map<String, Object> keys = new HashMap<String, Object>();

    try {
        Map<?, ?> json = (Map<?, ?>) parser.parse(content, containerFactory);
        Iterator<?> iter = json.entrySet().iterator();

        // Type check
        while (iter.hasNext()) {
            Entry<?, ?> entry = (Entry<?, ?>) iter.next();
            if (!(entry.getKey() instanceof String)) {
                throw new IllegalArgumentException("Not in <String, Object> format");
            }
        }

        keys = (Map<String, Object>) json;
    } catch (ParseException e) {
        e.printStackTrace();
        return new ItemAttachment(new ItemStack(Material.GRASS, 1));
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        return new ItemAttachment(new ItemStack(Material.GRASS, 1));
    }

    // Repair Gson thinking int == double
    if (keys.get("amount") != null) {
        Double d = (Double) keys.get("amount");
        Integer i = d.intValue();
        keys.put("amount", i);
    }

    ItemStack item = null;
    try {
        item = ItemStack.deserialize(keys);
    } catch (Exception e) {
        return null;
    }

    // Handle item meta
    if (keys.containsKey("meta")) {
        Map<String, Object> itemmeta = (Map<String, Object>) keys.get("meta");
        // Convert doubles -> ints
        itemmeta = recursiveDoubleToInteger(itemmeta);

        // Deserilize everything
        itemmeta = recursiveDeserialization(itemmeta);

        // Create the Item Meta
        ItemMeta meta = (ItemMeta) ConfigurationSerialization.deserializeObject(itemmeta,
                ConfigurationSerialization.getClassByAlias("ItemMeta"));

        // Colorize everything
        if (meta.hasDisplayName()) {
            meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', meta.getDisplayName()));
        }
        if (meta.hasLore()) {
            List<String> lore = meta.getLore();
            for (int i = 0; i < lore.size(); i++) {
                String line = lore.get(i);
                line = ChatColor.translateAlternateColorCodes('?', line);
                line = ChatColor.translateAlternateColorCodes('&', line);
                lore.set(i, line);
            }
            meta.setLore(lore);
        }
        if (meta instanceof BookMeta) {
            BookMeta book = (BookMeta) meta;
            if (book.hasAuthor()) {
                book.setAuthor(ChatColor.translateAlternateColorCodes('&', book.getAuthor()));
            }
            if (book.hasTitle()) {
                book.setTitle(ChatColor.translateAlternateColorCodes('&', book.getTitle()));
            }
            if (book.hasPages()) {
                List<String> pages = new ArrayList<String>();
                pages.addAll(book.getPages());
                for (int i = 0; i < pages.size(); i++) {
                    String line = pages.get(i);
                    line = ChatColor.translateAlternateColorCodes('&', line);
                    pages.set(i, line);
                }
                book.setPages(pages);
            }
        }

        // Assign the item meta
        item.setItemMeta(meta);
    }
    return new ItemAttachment(item);
}