Example usage for com.google.common.collect LinkedListMultimap get

List of usage examples for com.google.common.collect LinkedListMultimap get

Introduction

In this page you can find the example usage for com.google.common.collect LinkedListMultimap get.

Prototype

@Override
public List<V> get(final @Nullable K key) 

Source Link

Document

If the multimap is modified while an iteration over the list is in progress (except through the iterator's own add , set or remove operations) the results of the iteration are undefined.

Usage

From source file:net.tridentsdk.server.bench.Benchmarks.java

public static void chart(LinkedListMultimap<String, Double> data, String what) {
    String[] keys = asString(data.asMap().keySet().toArray());
    double[] base = asDouble(data.get("control").toArray());

    StringBuilder builder = new StringBuilder("http://chart.googleapis.com/chart?").append("cht=lxy") // Chart type: Line/xy
            .append("&chtt=Benchmark+Results:+") // Chart title: Benchmark Results:
            .append(what) // specified
            .append(" (ns/op)").append("&chs=900x300") // Chart size: 900x300
            .append("&chxt=x,x,y,y") // Chart x/y: visible
            .append("&chxl=1:|CPU+Backoff|3:|Nanoseconds") // Axis labels
            .append("&chds=a").append("&chxl=1:|CPU+Backoff|3:|Nanoseconds") // Axis labels
            .append("&chxs=0,000000,12,0,lt") // Chart axis data
            .append("|").append("1,000000,12,1,lt");

    StringBuilder dataBuilder = new StringBuilder("&chd=t:");
    for (int i = 0; i < keys.length; i++) {
        for (int j = 0; j < TOK_LEN; j++) {
            dataBuilder.append(TOKENS[j]);
            if (j != TOK_LEN - 1)
                dataBuilder.append(",");
        }/*  w ww .j av a 2 s.co m*/

        dataBuilder.append("|");

        String label = keys[i];
        List<Double> doubles = Lists.newArrayList(data.get(label));
        for (int j = 0; j < doubles.size(); j++) {
            dataBuilder.append(roundTo3(doubles.get(j) - base[j]));
            if (j != doubles.size() - 1)
                dataBuilder.append(",");
        }

        if (i != keys.length - 1)
            dataBuilder.append("|");
    }
    builder.append(dataBuilder.toString()); // Chart data: specified

    builder.append("&chdl="); // Chart keys: specified
    for (int i = 0; i < keys.length; i++) {
        builder.append(keys[i]);
        if (i != keys.length - 1)
            builder.append("|");
    }

    StringBuilder colors = new StringBuilder("&chco="); // Chart colors: randomized
    for (int i = 0; i < keys.length; i++) {
        String rand = randomColor();
        colors.append(rand);
        if (rand.length() != 6) { // This happens for no reason sometimes
            for (int j = 0; j < 6 - rand.length(); j++) {
                colors.append(randomChar());
            }
        }

        if (i != keys.length - 1)
            colors.append(",");
    }
    builder.append(colors.toString());

    System.out.println(builder.toString());
}

From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java

@SuppressWarnings("ConstantConditions")
public static void updateSubscriptionIdAt(final Context context, final String id, final int position) {
    final LinkedListMultimap<String, String> subscriptions = getSubscriptions(context);

    final String title = getSubscriptionTitleAt(context, position);
    final List<String> values = subscriptions.get(title);

    values.set(1, id);/*from w ww .j a  v  a 2 s. c o  m*/
    subscriptions.replaceValues(title, values);

    saveSubscriptions(context, subscriptions);
}

From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java

@SuppressWarnings("ConstantConditions")
public static void updateSubscriptionCategoryTitleAt(final Context context, final String category,
        final String newTitle, final int position) {
    final LinkedListMultimap<String, String> subscriptions = getSubscriptions(context);
    final String title = getSubscriptionTitleAt(context, position);

    final List<String> values = subscriptions.get(title);
    final boolean newCategory = !values.get(0).equals(category);

    if (newCategory || !newTitle.equals(title)) {
        if (newCategory) {
            final List<String> newValues = new ArrayList<>(subscriptions.removeAll(title));
            newValues.set(0, category);//from  w  w  w  .j a va  2  s.  c  o  m

            subscriptions.putAll(newTitle, newValues);
        } else {
            subscriptions.putAll(newTitle, subscriptions.removeAll(title));
        }

        saveSubscriptions(context, subscriptions);

        updateCurrentFeedPosition(context, newTitle);
    }
}

From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java

@SuppressWarnings("ConstantConditions")
public static void updateSubscriptionUrl(final Context context, final String feedUrl) {
    final LinkedListMultimap<String, String> subscriptions = getSubscriptions(context);

    final int position = getCurrentFeedPosition(context);
    final String title = getSubscriptionTitleAt(context, position);

    final List<String> values = subscriptions.get(title);

    values.set(2, feedUrl);/*from   w  ww .  j  a va 2s .c o  m*/
    subscriptions.replaceValues(title, values);

    saveSubscriptions(context, subscriptions);
}

From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java

public static List<List<Object>> getSubscriptionsFor(final Context context, final String newCategory) {
    if (sSubscriptionList == null) {
        final LinkedListMultimap<String, String> subscriptions = getSubscriptions(context);
        final boolean queryEmpty = TextUtils.isEmpty(newCategory);

        sSubscriptionList = new ArrayList<>(subscriptions.size());

        int i = 0;

        for (final String title : subscriptions.asMap().keySet()) {
            final String category = subscriptions.get(title).get(0);

            if (queryEmpty || newCategory.equals(category)) {
                if (queryEmpty) {
                    sSubscriptionList.add(Arrays.<Object>asList(title, category));
                } else {
                    sSubscriptionList.add(Arrays.<Object>asList(title, category, i));
                }//from ww  w . ja v a 2s .c  om
            }

            i++;
        }
    }

    return sSubscriptionList;
}

From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java

static List<Object> getSubscriptionsAsOutlines(final Context context, final boolean retainCategories) {
    final LinkedListMultimap<String, String> subscriptions = getSubscriptions(context);

    final List<Object> outlines = new ArrayList<>(subscriptions.size());
    final LinkedListMultimap<String, Outline> outlineGroups = LinkedListMultimap.create();

    for (final String title : subscriptions.asMap().keySet()) {
        final String category = subscriptions.get(title).get(0);
        final String xmlUrl = subscriptions.get(title).get(2);

        final Outline outline = new Outline.Builder().setText(title).setTitle(title).setXmlUrl(xmlUrl).build();

        if (retainCategories) {
            outlineGroups.put(category, outline);
        } else {/*from w  w  w  .  jav a  2s .  com*/
            outlines.add(outline);
        }
    }

    if (retainCategories) {
        for (final String category : outlineGroups.asMap().keySet()) {
            outlines.add(new OutlineGroup.Builder().setText(category).setTitle(category)
                    .addSubOutlines(outlineGroups.get(category)).build());
        }
    }

    return outlines;
}

From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java

public static String[] getSubscriptionCategories(final Context context, final boolean edit) {
    final LinkedListMultimap<String, String> subscriptions = getSubscriptions(context);
    final Set<String> categories = new TreeSet<>();

    if (!edit) {//from w  ww  .j  a  v a2s. co  m
        categories.add(context.getString(R.string.all_categories));
    } else {
        categories.add(context.getString(R.string.clear_category));
    }

    for (final String title : subscriptions.asMap().keySet()) {
        categories.add(subscriptions.get(title).get(0));
    }

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

From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java

private static void saveSubscriptions(final Context context,
        final LinkedListMultimap<String, String> subscriptions) {
    if (subscriptions != null) {
        final JSONObject JSON = new JSONObject();
        final JSONArray titlesJSON = new JSONArray();
        final JSONArray categoriesJSON = new JSONArray();
        final JSONArray idsJSON = new JSONArray();
        final JSONArray urlsJSON = new JSONArray();

        final List<String> titles = new ArrayList<>(subscriptions.asMap().keySet());

        Collections.sort(titles);

        for (final String title : titles) {
            final Iterator<String> iter = subscriptions.get(title).iterator();

            titlesJSON.put(title);// ww  w.java 2  s . c o m
            categoriesJSON.put(iter.next());
            idsJSON.put(iter.next());
            urlsJSON.put(iter.next());
        }

        try {
            JSON.put(KEY_SUBSCRIPTION_TITLES, titlesJSON);
            JSON.put(KEY_SUBSCRIPTION_CATEGORIES, categoriesJSON);
            JSON.put(KEY_SUBSCRIPTION_IDS, idsJSON);
            JSON.put(KEY_SUBSCRIPTION_URLS, urlsJSON);

            put(context, KEY_SUBSCRIPTIONS, JSON.toString());
        } catch (final JSONException e) {
            LogUtils.logError(e);
        }
    } else {
        put(context, KEY_SUBSCRIPTIONS, null);
    }

    sSubscriptions = null;
    sSubscriptionList = null;
}

From source file:net.joinedminds.masserr.util.RoleFormFunctions.java

public static String setRoleAttributes(Role role, JSONObject formObject, ManipulationDB manipulationDB) {
    role.setPhysical(ifNull(formObject.optInt("physical"), 0));
    role.setSocial(ifNull(formObject.optInt("social"), 0));
    role.setMental(ifNull(formObject.optInt("mental"), 0));

    LinkedListMultimap<Ability.Type, DottedNotedType<Ability>> multiMap = LinkedListMultimap.create();
    JSONArray abilities = formObject.optJSONArray("ability");
    if (abilities != null) {
        for (int i = 0; i < abilities.size(); i++) {
            JSONObject a = abilities.getJSONObject(i);
            int dots = a.optInt("dots");
            String type = a.optString("type");
            String notes = a.optString("notes");
            String id = a.optString("id");
            if (ifNull(dots, 0) > 0 && !isEmpty(type) && !isEmpty(id)) {
                DottedNotedType<Ability> ability = new DottedNotedType<>(Ability.idRef(id), dots,
                        ifNull(notes, ""));
                multiMap.put(Ability.Type.valueOf(type), ability);
            }//from w w w  .j  a  v  a  2  s  .  co  m
        }
    }
    role.setPhysicalAbilities(multiMap.get(Ability.Type.Physical));
    role.setSocialAbilities(multiMap.get(Ability.Type.Social));
    role.setMentalAbilities(multiMap.get(Ability.Type.Mental));

    return null;
}

From source file:io.fd.maintainer.plugin.util.MaintainersIndex.java

private int mostSpecificPathLengthFromComponent(final MatchLevel maximumMatchLevel,
        final LinkedListMultimap<MatchLevel, ComponentPath> byMatchIndex) {
    return byMatchIndex.get(maximumMatchLevel).stream().map(ComponentPath::getPath)
            .map(MaintainersIndex::getPathLength).max(Comparator.comparingInt(integer -> integer)).orElse(0);
}