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:org.apache.isis.viewer.wicket.viewer.services.HintStoreUsingWicketSession.java

protected Map<String, String> hintsFor(final Bookmark bookmark) {
    final String sessionAttribute = sessionAttributeFor(bookmark);
    LinkedHashMap<String, String> hints = (LinkedHashMap<String, String>) Session.get()
            .getAttribute(sessionAttribute);
    if (hints == null) {
        hints = Maps.newLinkedHashMap();
        Session.get().setAttribute(sessionAttribute, hints);
    }/*from www  . j  a  v a  2s .  c  o m*/
    return hints;
}

From source file:org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.java

public SortedSet<OWLIndividual> getNegativeExamples(OWLClass classToDescribe,
        Set<OWLIndividual> positiveExamples, Collection<Strategy> strategies, int limit) {
    Map<Strategy, Double> strategiesWithWeight = Maps.newLinkedHashMap();
    double weight = 1d / strategies.size();
    for (Strategy strategy : strategies) {
        strategiesWithWeight.put(strategy, weight);
    }/*from w  ww.j a va 2 s.c  o  m*/
    return getNegativeExamples(classToDescribe, positiveExamples, strategiesWithWeight, limit);
}

From source file:net.hydromatic.quidem.Launcher.java

/** Parses the command line arguments, and returns a {@link Quidem} instance.
 *
 * @throws ParseException if command line arguments were invalid or usage
 * was requested/*from  w  w w.  j  a v a  2  s. c  om*/
 */
public Quidem parse() throws ParseException {
    final List<Quidem.ConnectionFactory> factories = Lists.newArrayList();
    final Map<String, String> envMap = Maps.newLinkedHashMap();
    int i;
    for (i = 0; i < args.size();) {
        String arg = args.get(i);
        if (arg.equals("--help")) {
            usage();
            throw new ParseException(0);
        }
        if (arg.equals("--db")) {
            if (i + 4 >= args.size()) {
                throw error("Insufficient arguments for --db");
            }
            final String name = args.get(i + 1);
            final String url = args.get(i + 2);
            final String user = args.get(i + 3);
            final String password = args.get(i + 4);
            factories.add(new SimpleConnectionFactory(name, url, user, password));
            i += 5;
            continue;
        }
        if (arg.equals("--var")) {
            if (i + 3 >= args.size()) {
                throw error("Insufficient arguments for --var");
            }
            final String name = args.get(i + 1);
            final String value = args.get(i + 2);
            envMap.put(name, value);
            i += 3;
            continue;
        }
        if (arg.equals("--factory")) {
            if (i + 1 >= args.size()) {
                throw error("Insufficient arguments for --factory");
            }
            final String className = args.get(i + 1);
            final Class<?> factoryClass;
            try {
                factoryClass = Class.forName(className);
            } catch (ClassNotFoundException e) {
                throw error("Factory class " + className + " not found");
            }
            Quidem.ConnectionFactory factory;
            try {
                factory = (Quidem.ConnectionFactory) factoryClass.newInstance();
            } catch (InstantiationException e) {
                throw error("Error instantiating factory class " + className);
            } catch (IllegalAccessException e) {
                throw error("Error instantiating factory class " + className);
            } catch (ClassCastException e) {
                throw error("Error instantiating factory class " + className);
            }
            factories.add(factory);
            i += 2;
            continue;
        }
        break;
    }
    if (i + 2 > args.size()) {
        throw error("Insufficient arguments: need inFile and outFile");
    }
    final File inFile = new File(args.get(i));
    final File outFile = new File(args.get(i + 1));
    final Reader reader;
    try {
        reader = new LineNumberReader(new FileReader(inFile));
    } catch (FileNotFoundException e) {
        throw new RuntimeException("Error opening input " + inFile, e);
    }
    final Writer writer;
    try {
        writer = new FileWriter(outFile);
    } catch (IOException e) {
        throw new RuntimeException("Error opening output " + outFile, e);
    }

    factories.add(new UnsupportedConnectionFactory());
    final ChainingConnectionFactory connectionFactory = new ChainingConnectionFactory(factories);

    final Function<String, Object> env = new Function<String, Object>() {
        public Object apply(String input) {
            return envMap.get(input);
        }
    };
    return new Quidem(reader, writer, env, connectionFactory);
}

From source file:com.google.jenkins.plugins.health.lib.DerivedPageZone.java

/**
 * @return results of {@link DerivedPageComponent}s.
 *//*  w  ww.ja v a 2 s.  c  o m*/
@Exported
public Map<String, Report> getReports() {
    Map<String, Report> results = Maps.newLinkedHashMap();
    for (Component component : getComponents()) {
        results.put(namePageComponent(component), derivePageComponent(component));
    }
    return results;
}

From source file:org.apache.brooklyn.core.sensor.AttributeMap.java

public Map<String, Object> asMap() {
    Map<String, Object> result = Maps.newLinkedHashMap();
    synchronized (values) {
        for (Map.Entry<Collection<String>, Object> entry : values.entrySet()) {
            String sensorName = Joiner.on('.').join(entry.getKey());
            Object val = (isNull(entry.getValue())) ? null : entry.getValue();
            result.put(sensorName, val);
        }//from  w ww  .java 2 s.c  om
    }
    return result;
}

From source file:com.kolich.blog.components.cache.EntryCache.java

@Injectable
public EntryCache(@Required final GitRepository repo, @Required final BlogEventBus eventBus) {
    cache_ = Maps.newLinkedHashMap(); // Preserves insertion order, important
    unsortedEntries_ = Sets.newLinkedHashSet();
    canonicalEntriesDir_ = repo.getFileRelativeToContentRoot(entriesDir__).getAbsolutePath();
    eventBus_ = eventBus;//  w  ww  . java  2  s.  c o m
    eventBus_.register(this);
}

From source file:org.jpmml.pig.PMMLUtil.java

static private Map<FieldName, FieldValue> loadPrimitiveList(Evaluator evaluator, Tuple tuple)
        throws ExecException {
    Map<FieldName, FieldValue> result = Maps.newLinkedHashMap();

    List<FieldName> activeFields = evaluator.getActiveFields();
    if (activeFields.size() != tuple.size()) {
        throw new ExecException();
    }//from  w ww  .j  ava 2  s .co m

    int i = 0;

    for (FieldName activeField : activeFields) {
        Object object = tuple.get(i);

        FieldValue value = EvaluatorUtil.prepare(evaluator, activeField, object);

        result.put(activeField, value);

        i++;
    }

    return result;
}

From source file:io.smartspaces.master.ui.internal.web.WebSupport.java

/**
 * Get a map of live activity names keyed by IDs.
 *
 * @param activities/*from  w  w w .  jav a 2  s . c  om*/
 *          the live activities
 *
 * @return selections ordered by name
 */
public static Map<String, String> getLiveActivitySelections(List<LiveActivity> activities) {
    List<LiveActivity> toBeSorted = Lists.newArrayList(activities);
    Collections.sort(toBeSorted, MasterApiUtilities.LIVE_ACTIVITY_BY_NAME_COMPARATOR);

    Map<String, String> items = Maps.newLinkedHashMap();
    for (LiveActivity activity : toBeSorted) {
        items.put(activity.getId(), activity.getName());
    }

    return items;
}

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

/**
 * Evaluates the {@link Targets} element for {@link MiningFunctionType#CLASSIFICATION classification} models.
 *//*from  www. j a  va2  s  . c  o  m*/
static public Map<FieldName, ? extends ClassificationMap<?>> evaluateClassification(
        Map<FieldName, ? extends ClassificationMap<?>> predictions, ModelEvaluationContext context) {
    ModelEvaluator<?> modelEvaluator = context.getModelEvaluator();

    Targets targets = modelEvaluator.getTargets();
    if (targets == null || Iterables.isEmpty(targets)) {
        return predictions;
    }

    Map<FieldName, ClassificationMap<?>> result = Maps.newLinkedHashMap();

    Collection<? extends Map.Entry<FieldName, ? extends ClassificationMap<?>>> entries = predictions.entrySet();
    for (Map.Entry<FieldName, ? extends ClassificationMap<?>> entry : entries) {
        FieldName key = entry.getKey();
        ClassificationMap<?> value = entry.getValue();

        Target target = modelEvaluator.getTarget(key);
        if (target != null) {

            if (value == null) {
                value = getPriorProbabilities(target);
            }
        }

        result.put(key, value);
    }

    return result;
}

From source file:org.cinchapi.concourse.util.TLinkedTableMap.java

/**
 * Insert {@code value} under {@code column} in {@code row}.
 * /*from   w  w  w  .  ja  v  a  2s  . c o  m*/
 * @param row
 * @param column
 * @param value
 * @return the previous value located at the intersection of {@code row} and
 *         {@code column} or {@code null} if one did not previously exist.
 */
public V put(R row, C column, V value) {
    Map<C, V> rowdata = super.get(row);
    if (rowdata == null) {
        rowdata = Maps.newLinkedHashMap();
        super.put(row, rowdata);
    }
    rowLength = Math.max(row.toString().length(), rowLength);
    int current = columns.containsKey(column) ? columns.get(column) : 0;
    columns.put(column, Math.max(current, Math.max(column.toString().length(), value.toString().length())));
    return rowdata.put(column, value);
}