Example usage for com.google.common.collect Maps newLinkedHashMap

List of usage examples for com.google.common.collect Maps newLinkedHashMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps newLinkedHashMap.

Prototype

public static <K, V> LinkedHashMap<K, V> newLinkedHashMap() 

Source Link

Document

Creates a mutable, empty, insertion-ordered LinkedHashMap instance.

Usage

From source file:cc.kave.commons.utils.TypeErasure.java

public static String of(String id) {
    int startIdx = id.indexOf('`');
    if (startIdx == -1) {
        return id;
    }//from   w  w w .  j a  v a  2s .  c o m

    Map<String, String> replacements = Maps.newLinkedHashMap();
    int tick = FindNext(id, 0, '`');

    while (tick != -1) {
        int open = FindNext(id, tick, '[');
        int length = open - tick - 1;
        String numStr = length > 0 ? id.substring(tick + 1, open).trim() : "0";

        if (length < 1) {
            // TODO fix name creation, this should not happen!
            System.out.printf("\nEE: cannot remove generic (no tick number): %s", id);
        }

        int numGenerics = 0;
        try {
            numGenerics = Integer.parseInt(numStr);
        } catch (NumberFormatException e) {
            // TODO fix name creation, this should not happen!
            System.out.printf("\nEE: cannot remove generic (invalid tick number between %d and %d): %s", tick,
                    open, id);
        }

        while (IsArray(id, open)) {
            open = FindNext(id, open + 1, '[');
        }

        for (int i = 0; i < numGenerics; i++) {
            open = FindNext(id, open + 1, '[');
            int close = FindCorrespondingCloseBracket(id, open);

            int arrowStart = FindNext(id, open, '-');
            if (arrowStart != -1 && arrowStart < close) {
                String param = id.substring(open, arrowStart).trim();
                String complete = id.substring(open, close);
                replacements.put(complete, param);
            }

            open = close + 1;
        }
        tick = FindNext(id, tick + 1, '`');
    }
    String res = id;
    for (String k : replacements.keySet()) {
        String with = replacements.get(k);
        res = res.replace(k, with);
    }
    return res;
}

From source file:cc.recommenders.datastructures.Map2D.java

public V getOrAdd(K1 k1, K2 k2, V vDefault) {
    Map<K2, V> m2 = vs.get(k1);
    if (m2 == null) {
        m2 = Maps.newLinkedHashMap();
        vs.put(k1, m2);//from   w ww  .ja  va  2  s.  c  o  m
    }
    V v = m2.get(k2);
    if (v == null) {
        v = vDefault;
        m2.put(k2, v);
    }
    return v;
}

From source file:org.jeo.cli.conv.MapConverter.java

@Override
public Map<String, String> convert(String value) {
    Map<String, String> map = Maps.newLinkedHashMap();
    String[] entries = value.split("; *");
    for (String e : entries) {
        String[] kv = e.split(" *= *");
        if (kv.length > 0) {
            map.put(kv[0], kv.length > 1 ? kv[1] : null);
        }//from  ww w. ja  va  2  s  .  c  o m
    }
    return map;
}

From source file:org.caleydo.core.internal.startup.StartupAddons.java

public static Map<String, IStartupAddon> findAll() {
    List<StartupAddonDesc> tmp = new ArrayList<>();
    try {/*  w ww.  j  av a 2  s .  c  o m*/
        for (IConfigurationElement elem : RegistryFactory.getRegistry()
                .getConfigurationElementsFor(EXTENSION_POINT)) {
            final Object o = elem.createExecutableExtension("class");
            if (o instanceof IStartupAddon) {
                String orderS = elem.getAttribute("order");
                int order = Strings.isNullOrEmpty(orderS) ? 10 : Integer.parseInt(orderS);
                tmp.add(new StartupAddonDesc(elem.getAttribute("name"), (IStartupAddon) o, order));
            }
        }
    } catch (CoreException e) {
        System.err.println("can't find implementations of " + EXTENSION_POINT + " : " + "name");
        e.printStackTrace();
    }

    // sort by order
    Collections.sort(tmp);
    Map<String, IStartupAddon> factories = Maps.newLinkedHashMap();
    for (StartupAddonDesc desc : tmp)
        factories.put(desc.label, desc.addon);
    return Collections.unmodifiableMap(factories);
}

From source file:org.jpmml.evaluator.CsvUtil.java

static public List<Map<FieldName, String>> load(InputStream is) throws IOException {
    List<Map<FieldName, String>> table = Lists.newArrayList();

    BufferedReader reader = new BufferedReader(new InputStreamReader(is, "US-ASCII"));

    try {//w w w.  j  ava2 s.  c om
        String headerLine = reader.readLine();
        if (headerLine == null) {
            throw new EOFException();
        }

        List<String> headerCells = parseLine(headerLine);

        while (true) {
            String bodyLine = reader.readLine();
            if (bodyLine == null) {
                break;
            }

            Map<FieldName, String> row = Maps.newLinkedHashMap();

            List<String> bodyCells = parseLine(bodyLine);

            // Must be of equal length
            if (headerCells.size() != bodyCells.size()) {
                throw new RuntimeException();
            }

            for (int i = 0; i < headerCells.size(); i++) {
                row.put(FieldName.create(headerCells.get(i)), bodyCells.get(i));
            }

            table.add(row);
        }
    } finally {
        reader.close();
    }

    return table;
}

From source file:jflowmap.data.XmlRegionsReader.java

/**
 * Returns a Map: CountryCode -> FullRegion,
 * where FullRegion is e.g. "Africa|Eastern Africa" or "Oceania|Australia and New Zealand"
 *//*from w  w  w. j a v  a 2s  .  c o m*/
public static Map<String, String> readFrom(String location) throws XMLStreamException, IOException {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    LineNumberReader lineNumberReader = new LineNumberReader(
            new InputStreamReader(IOLib.streamFromString(location)));
    XMLStreamReader reader = inputFactory.createXMLStreamReader(lineNumberReader);
    Stack<String> regionStack = new Stack<String>();

    Map<String, String> regions = Maps.newLinkedHashMap();

    while (reader.hasNext()) {
        reader.next();
        String tag;
        switch (reader.getEventType()) {
        case XMLEvent.START_ELEMENT:
            tag = reader.getName().getLocalPart();
            if (tag.equals("country")) {
                String name = reader.getAttributeValue(null, "name");
                if (name == null) {
                    error(lineNumberReader, "Attr 'country' is missing");
                }
                String isoCode = reader.getAttributeValue(null, "iso-code");
                if (isoCode == null) {
                    error(lineNumberReader, "Attr 'iso-code' is missing");
                }

                regions.put(isoCode, StringUtils.join(regionStack, REGION_SEPARATOR));
            }
            if (tag.equals("region")) {
                String name = reader.getAttributeValue(null, "name");
                if (name == null) {
                    error(lineNumberReader, "Attr 'country' is missing");
                }
                regionStack.add(name);
            }
            break;

        case XMLEvent.END_ELEMENT:
            tag = reader.getName().getLocalPart();
            if (tag.equals("region")) {
                regionStack.pop();
            }
            break;
        }
    }
    return regions;
}

From source file:org.eclipse.xtext.validation.ConfigurableIssueCodesProvider.java

public ConfigurableIssueCodesProvider() {
    final Map<String, PreferenceKey> map = Maps.newLinkedHashMap();
    initialize(new IAcceptor<PreferenceKey>() {

        @Override//from   w  w w .  ja  v a2  s  . c o m
        public void accept(PreferenceKey prefKey) {
            map.put(prefKey.getId(), prefKey);
        }
    });
    this.issueCodes = ImmutableMap.copyOf(map);
}

From source file:cc.recommenders.evaluation.distribution.calc.MinComparisonProvider.java

@Override
protected Map<String, String> getOptions() {
    Map<String, String> options = Maps.newLinkedHashMap();
    for (int min = 0; min < 60; min += 2) {
        options.put("PBN25-" + min, pbn(25).c(false).d(true).p(false).useFloat().ignore(false).min(min).get());
    }//from w w  w  .j av a  2  s .  co m
    return options;
}

From source file:com.indeed.lsmtree.core.tools.StoreCat.java

public static <K, V> void cat(final Store<K, V> store, final K start, boolean startInclusive, final K end,
        final boolean endInclusive, Stringifier<K> keyStringifier, Stringifier<V> valueStringifier)
        throws IOException {
    Iterator<Store.Entry<K, V>> it = store.iterator(start, startInclusive);
    Iterator<Store.Entry<K, V>> iterator = end == null ? it : ItUtil.span(new F<Store.Entry<K, V>, Boolean>() {
        public Boolean f(final Store.Entry<K, V> kvEntry) {
            final int cmp = store.getComparator().compare(kvEntry.getKey(), end);
            return cmp < 0 || cmp == 0 && endInclusive;
        }//  ww  w . j a  v  a 2s .  co m
    }, it)._1();
    Map<String, Object> map = Maps.newLinkedHashMap();
    ObjectMapper mapper = new ObjectMapper();
    while (iterator.hasNext()) {
        Store.Entry<K, V> next = iterator.next();
        map.clear();
        map.put("key", keyStringifier.toString(next.getKey()));
        map.put("value", valueStringifier.toString(next.getValue()));
        System.out.println(mapper.writeValueAsString(map));
    }
}

From source file:cc.recommenders.datastructures.Map3D.java

public V getOrAdd(K1 k1, K2 k2, K3 k3, V vDefault) {
    Map2D<K2, K3, V> m2 = vs.get(k1);
    if (m2 == null) {
        m2 = Map2D.create();/*from www . j  av a2s .  c om*/
        vs.put(k1, m2);
    }
    Map<K3, V> m3 = m2.get(k2);
    if (m3 == null) {
        m3 = Maps.newLinkedHashMap();
        m2.put(k2, m3);
    }
    V v = m3.get(k2);
    if (v == null) {
        v = vDefault;
        m3.put(k3, v);
    }
    return v;

}