Java Json Get getIntegerArrayListSansDoublons( JsonArray array)

Here you can find the source of getIntegerArrayListSansDoublons( JsonArray array)

Description

get Integer Array List Sans Doublons

License

Apache License

Declaration

public static ArrayList<Integer> getIntegerArrayListSansDoublons(
        JsonArray array) throws ClassCastException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import java.util.HashSet;

import javax.json.JsonArray;

import javax.json.JsonNumber;

import javax.json.JsonValue;

public class Main {

    public static ArrayList<Integer> getIntegerArrayListSansDoublons(
            JsonArray array) throws ClassCastException {
        ArrayList<Integer> resDoublons = getIntegerArrayList(array);

        HashSet<Integer> set = new HashSet<Integer>(resDoublons.size());
        set.addAll(resDoublons);/*from  w  w  w. j  a v a2  s  . c  o m*/

        return new ArrayList<Integer>(set);
    }

    public static ArrayList<Integer> getIntegerArrayList(JsonArray array)
            throws ClassCastException {
        ArrayList<Integer> res = new ArrayList<Integer>(array.size());

        for (JsonValue v : array) {
            res.add(((JsonNumber) v).intValue());
        }

        return res;
    }
}

Related

  1. getBooleanValue(JsonValue value)
  2. getBuilderFactory()
  3. getInt(JsonObject json, String name)
  4. getIntArray(JsonObject object, String name)
  5. getIntegerArrayList(JsonArray array)
  6. getJsonArray(JsonObject object, String name)
  7. getJsonIntArray(Iterable integers)
  8. getJsonNumberOrNull(JsonObject object, String key)
  9. getJsonObject(JsonObject object, String name)