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:com.threerings.presents.tools.GeneratedSourceMerger.java

/**
 * Returns <code>previouslyGenerated</code> with marked sections updated from the same marked
 * sections in <code>newlyGenerated</code>. Everything outside these sections in
 * <code>previouslyGenerated</code> is returned as is. A marked section starts with <code>//
 * GENERATED {name} START</code> and ends with <code>// GENERATED {name} END</code><p>
 *
 * If <code>previouslyGenerated</code> has a generated section replaced with <code>//
 * GENERATED {name} DISABLED</code>, that section will no longer be updated.
 *//*w  w  w .j  a v  a  2s  .  com*/
public String merge(String newlyGenerated, String previouslyGenerated) throws Exception {
    // Extract the generated section names from the output and make sure they're all matched
    Map<String, Section> sections = Maps.newLinkedHashMap();
    Matcher m = _sectionDelimiter.matcher(newlyGenerated);
    while (m.find()) {
        Section section = extractGeneratedSection(m, newlyGenerated);
        Preconditions.checkArgument(!sections.containsKey(section.name), "Section '%s' used more than once",
                section.name);
        sections.put(section.name, section);
    }

    // Merge with the previously generated source
    StringBuilder merged = new StringBuilder();
    m = _sectionDelimiter.matcher(previouslyGenerated);
    int currentStart = 0;
    while (m.find()) {
        merged.append(previouslyGenerated.substring(currentStart, m.start()));
        Section existingSection = extractGeneratedSection(m, previouslyGenerated);
        Section newSection = sections.remove(existingSection.name);
        if (newSection == null) {
            // Allow generated sections to be dropped in the template, but warn in case
            // something odd's happening
            System.err.println("Dropping previously generated section '" + m.group(1)
                    + "' that's no longer generated by the template");
        } else if (existingSection.disabled) {
            // If the existing code disables this generation, add that disabled comment
            merged.append(existingSection.contents);
        } else {
            // Otherwise pop in the newly generated code in the place of what was there before
            merged.append(newSection.contents);
        }
        currentStart = m.end();
    }
    // Add generated sections that weren't present in the old output before the last
    // non-generated code.  It's a 50-50 shot, so warn when this happens
    for (Section newSection : sections.values()) {
        System.err.println("Adding previously missing generated section '" + newSection.name
                + "' before the last non-generated text");
        merged.append(newSection.contents);
    }
    // Add any text past the last previously generated section
    merged.append(previouslyGenerated.substring(currentStart));

    return merged.toString();
}

From source file:debug_list_likert_scale_questions.java

public static Map<LikertValue, Integer> getMapFor(String taskId) {
    if (answers.containsKey(taskId)) {
        return answers.get(taskId);
    }/*from  w w  w . java 2  s. co m*/
    Map<LikertValue, Integer> map = Maps.newLinkedHashMap();
    answers.put(taskId, map);
    return map;
}

From source file:exec.validate_evaluation.streaks.EditStreakGenerationRunner.java

public void run() {
    log.starting(filters);//from  w  w w. java2  s .com

    Set<String> zips = io.findCompletionEventZips();
    log.foundZips(zips);

    for (String zip : zips) {
        log.startingZip(zip);
        editStreaks = Maps.newLinkedHashMap();

        Set<ICompletionEvent> events = io.readCompletionEvents(zip);
        log.foundEvents(events);

        for (ICompletionEvent e : events) {
            log.processingEvent(e);
            extractEdits(e);
        }

        filterRemovals();

        Set<EditStreak> streaks = Sets.newLinkedHashSet();
        streaks.addAll(editStreaks.values());
        log.endZip(streaks);
        io.storeEditStreaks(streaks, zip);
    }

    log.finish();
}

From source file:com.clarkparsia.sbol.SBOLUtils.java

public static Map<Integer, DnaSequence> findUncoveredSequences(DnaComponent comp,
        List<SequenceAnnotation> annotations) {
    String sequence = SBOLUtils.getNucleotides(comp);
    if (sequence == null) {
        return ImmutableMap.of();
    }/*from  w  w w .j ava  2  s .c  om*/

    Map<Integer, DnaSequence> uncoveredSequences = Maps.newLinkedHashMap();
    int size = annotations.size();
    int location = 1;
    for (int i = 0; i < size; i++) {
        SequenceAnnotation ann = annotations.get(i);

        Integer start = ann.getBioStart();
        Integer end = ann.getBioEnd();
        if (start == null || end == null) {
            return null;
        }

        if (start > location) {
            DnaSequence seq = SBOLUtils.createDnaSequence(sequence.substring(location - 1, start - 1));
            uncoveredSequences.put(-i - 1, seq);
        }

        if (SBOLUtils.getNucleotides(ann.getSubComponent()) == null) {
            DnaSequence seq = SBOLUtils.createDnaSequence(sequence.substring(start - 1, end));
            uncoveredSequences.put(i, seq);
        }

        location = end + 1;
    }

    if (location < sequence.length()) {
        DnaSequence seq = SBOLUtils.createDnaSequence(sequence.substring(location - 1, sequence.length()));
        uncoveredSequences.put(-size - 1, seq);
    }

    return uncoveredSequences;
}

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

@Override
protected Map<String, String> getOptions() {
    Map<String, String> options = Maps.newLinkedHashMap();
    options.put("BMN", bmn().c(false).d(false).p(false).useFloat().qNM().ignore(false).min(30).get());
    options.put("BMN+DEF", bmn().c(false).d(true).p(false).useFloat().qNM().ignore(false).min(30).get());
    options.put("BMN+ALL", bmn().c(true).d(true).p(true).useFloat().qNM().ignore(false).min(30).get());
    // for (int n : new int[] { 15}){
    for (int n : new int[] { 0, 15, 25, 30, 40, 60 }) {
        String pbn = "PBN" + n;
        options.put(pbn, pbn(n).c(false).d(false).p(false).useFloat().qNM().ignore(false).min(30).get());
        options.put(pbn + "+DEF",
                pbn(n).c(false).d(true).p(false).useFloat().qNM().ignore(false).min(30).get());
        options.put(pbn + "+ALL", pbn(n).c(true).d(true).p(true).useFloat().qNM().ignore(false).min(30).get());
    }//from w  w w. ja  v  a2  s  .  c om
    return options;
}

From source file:org.sonatype.nexus.rest.PathProtectionDescriptorBuilder.java

public PathProtectionDescriptorBuilder filter(final String name, final String config) {
    checkNotNull(name);//from   w w w .  j a  v  a  2s  . co  m
    if (filters == null) {
        filters = Maps.newLinkedHashMap();
    }
    filters.put(name, config);
    return this;
}

From source file:com.huawei.streaming.application.OperatorMng.java

/**
 * <>//from   w ww  .  j  av  a  2  s .c om
 */
public OperatorMng() {
    this.inputs = Maps.newLinkedHashMap();
    this.outputs = Maps.newLinkedHashMap();
    this.functions = Maps.newLinkedHashMap();
    this.sortedFunctions = Lists.newArrayList();
}

From source file:com.github.autermann.yaml.nodes.YamlPairsNode.java

/**
 * Creates a new {@link YamlPairsNode}./*  ww w.  j a  va  2s.  c o m*/
 *
 * @param factory the factory to create children with
 */
public YamlPairsNode(YamlNodeFactory factory) {
    super(factory);
    LinkedHashMap<YamlNode, Collection<YamlNode>> map = Maps.newLinkedHashMap();
    Supplier<List<YamlNode>> supplier = LinkedListSupplier.instance();
    this.multiMap = Multimaps.newListMultimap(map, supplier);
    this.value = Lists.newLinkedList();
}

From source file:org.sakaiproject.kernel.model.FriendsBean.java

@Inject
public FriendsBean(JCRNodeFactoryService jcrNodeFactoryService, UserFactoryService userFactoryService,
        BeanConverter beanConverter, @Named(KernelConstants.PRIVATE_PATH_BASE) String privatePathBase) {
    friends = Maps.newLinkedHashMap();
    this.jcrNodeFactoryService = jcrNodeFactoryService;
    this.beanConverter = beanConverter;
    this.userFactoryService = userFactoryService;
    this.privatePathBase = privatePathBase;
}

From source file:com.aerofs.baseline.ConstraintViolationExceptionMapper.java

@Override
protected void addErrorFields(ConstraintViolationException throwable, Map<String, Object> errorFields) {
    List<Map<String, String>> violations = Lists.newArrayList();

    for (Object object : throwable.getConstraintViolations()) {
        ConstraintViolation<?> constraintViolation = ((ConstraintViolation) object);

        LinkedHashMap<String, String> violationProperties = Maps.newLinkedHashMap();
        violationProperties.put("class", constraintViolation.getRootBeanClass().getSimpleName());
        violationProperties.put("property", constraintViolation.getPropertyPath().toString());
        violationProperties.put("cause", constraintViolation.getMessage());

        violations.add(violationProperties);
    }/*w  w w .j  a v  a2  s.  c  o m*/

    errorFields.put("violations", violations);
}