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.terasology.world.generation.facets.base.SparseObjectFacet3D.java

/**
 * @return a <b>new</b> map with world-based position entries
 *//*from   w w w  .ja va2  s.c  om*/
public Map<BaseVector3i, T> getWorldEntries() {

    Map<BaseVector3i, T> result = Maps.newLinkedHashMap();

    for (Entry<BaseVector3i, T> entry : relData.entrySet()) {
        BaseVector3i relPos = entry.getKey();
        BaseVector3i worldPos = relativeToWorld(relPos.x(), relPos.y(), relPos.z());

        result.put(worldPos, entry.getValue());
    }

    return result;
}

From source file:com.opengamma.financial.analytics.model.irfutureoption.IRFutureOptionSABRDefaults.java

/**
 * @param defaultsPerCurrency The default values per currency, not null. Must contain elements in the order: currency, curve calculation configuration name, surface name
 * and fitting method name./*www  .jav  a  2  s .  co  m*/
 */
public IRFutureOptionSABRDefaults(final String... defaultsPerCurrency) {
    super(ComputationTargetType.TRADE, true);
    ArgumentChecker.notNull(defaultsPerCurrency, "defaults per currency");
    ArgumentChecker.isTrue(defaultsPerCurrency.length % 4 == 0,
            "Must have one curve configuration name, surface name and fitting method name per currency");
    _curveConfigPerCurrency = Maps.newLinkedHashMap();
    _surfacePerCurrency = Maps.newLinkedHashMap();
    _fittingMethodPerCurrency = Maps.newLinkedHashMap();
    for (int i = 0; i < defaultsPerCurrency.length; i += 4) {
        final String currency = defaultsPerCurrency[i];
        _curveConfigPerCurrency.put(currency, defaultsPerCurrency[i + 1]);
        _surfacePerCurrency.put(currency, defaultsPerCurrency[i + 2]);
        _fittingMethodPerCurrency.put(currency, defaultsPerCurrency[i + 3]);
    }
}

From source file:org.napile.compiler.lang.resolve.calls.inference.DebugConstraintResolutionListener.java

@Override
public void constraintsForKnownType(NapileType type, BoundsOwner typeValue) {
    if (!ResolutionDebugInfo.isResolutionDebugEnabled())
        return;/*from   www .  j  a  v  a  2  s.  c om*/
    Map<NapileType, BoundsOwner> map = debugInfo.getByKey(BOUNDS_FOR_KNOWNS, candidateCall);
    if (map == null) {
        map = Maps.newLinkedHashMap();
        debugInfo.putByKey(BOUNDS_FOR_KNOWNS, candidateCall, map);
    }
    map.put(type, typeValue);
}

From source file:com.metamx.druid.index.v1.MMappedIndexAdapter.java

@Override
public Iterable<Rowboat> getRows() {
    return new Iterable<Rowboat>() {
        @Override//from  w  w  w  .  j a v a2  s.  c o  m
        public Iterator<Rowboat> iterator() {
            return new Iterator<Rowboat>() {
                final IndexedLongs timestamps = index.getReadOnlyTimestamps();
                final MetricHolder[] metrics;
                final IndexedFloats[] floatMetrics;
                final Map<String, Indexed<? extends IndexedInts>> dimensions;

                final int numMetrics = index.getAvailableMetrics().size();

                int currRow = 0;
                boolean done = false;

                {
                    dimensions = Maps.newLinkedHashMap();
                    for (String dim : index.getAvailableDimensions()) {
                        dimensions.put(dim, index.getDimColumn(dim));
                    }

                    final Indexed<String> availableMetrics = index.getAvailableMetrics();
                    metrics = new MetricHolder[availableMetrics.size()];
                    floatMetrics = new IndexedFloats[availableMetrics.size()];
                    for (int i = 0; i < metrics.length; ++i) {
                        metrics[i] = index.getMetricHolder(availableMetrics.get(i));
                        if (metrics[i].getType() == MetricHolder.MetricType.FLOAT) {
                            floatMetrics[i] = metrics[i].getFloatType();
                        }
                    }
                }

                @Override
                public boolean hasNext() {
                    final boolean hasNext = currRow < numRows;
                    if (!hasNext && !done) {
                        Closeables.closeQuietly(timestamps);
                        for (IndexedFloats floatMetric : floatMetrics) {
                            Closeables.closeQuietly(floatMetric);
                        }
                        done = true;
                    }
                    return hasNext;
                }

                @Override
                public Rowboat next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }

                    int[][] dims = new int[dimensions.size()][];
                    int dimIndex = 0;
                    for (String dim : dimensions.keySet()) {
                        IndexedInts dimVals = dimensions.get(dim).get(currRow);

                        int[] theVals = new int[dimVals.size()];
                        for (int j = 0; j < theVals.length; ++j) {
                            theVals[j] = dimVals.get(j);
                        }

                        dims[dimIndex++] = theVals;
                    }

                    Object[] metricArray = new Object[numMetrics];
                    for (int i = 0; i < metricArray.length; ++i) {
                        switch (metrics[i].getType()) {
                        case FLOAT:
                            metricArray[i] = floatMetrics[i].get(currRow);
                            break;
                        case COMPLEX:
                            metricArray[i] = metrics[i].getComplexType().get(currRow);
                        }
                    }

                    Map<String, String> descriptions = Maps.newHashMap();
                    for (String spatialDim : index.getSpatialIndexes().keySet()) {
                        descriptions.put(spatialDim, "spatial");
                    }
                    final Rowboat retVal = new Rowboat(timestamps.get(currRow), dims, metricArray, currRow,
                            descriptions);

                    ++currRow;

                    return retVal;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}

From source file:io.druid.segment.MMappedIndexAdapter.java

@Override
public Iterable<Rowboat> getRows() {
    return new Iterable<Rowboat>() {
        @Override//from  w w w  .j  a  va2  s  .co  m
        public Iterator<Rowboat> iterator() {
            return new Iterator<Rowboat>() {
                final IndexedLongs timestamps = index.getReadOnlyTimestamps();
                final MetricHolder[] metrics;
                final IndexedFloats[] floatMetrics;
                final Map<String, Indexed<? extends IndexedInts>> dimensions;

                final int numMetrics = index.getAvailableMetrics().size();

                int currRow = 0;
                boolean done = false;

                {
                    dimensions = Maps.newLinkedHashMap();
                    for (String dim : index.getAvailableDimensions()) {
                        dimensions.put(dim, index.getDimColumn(dim));
                    }

                    final Indexed<String> availableMetrics = index.getAvailableMetrics();
                    metrics = new MetricHolder[availableMetrics.size()];
                    floatMetrics = new IndexedFloats[availableMetrics.size()];
                    for (int i = 0; i < metrics.length; ++i) {
                        metrics[i] = index.getMetricHolder(availableMetrics.get(i));
                        if (metrics[i].getType() == MetricHolder.MetricType.FLOAT) {
                            floatMetrics[i] = metrics[i].getFloatType();
                        }
                    }
                }

                @Override
                public boolean hasNext() {
                    final boolean hasNext = currRow < numRows;
                    if (!hasNext && !done) {
                        CloseQuietly.close(timestamps);
                        for (IndexedFloats floatMetric : floatMetrics) {
                            CloseQuietly.close(floatMetric);
                        }
                        done = true;
                    }
                    return hasNext;
                }

                @Override
                public Rowboat next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }

                    int[][] dims = new int[dimensions.size()][];
                    int dimIndex = 0;
                    for (String dim : dimensions.keySet()) {
                        IndexedInts dimVals = dimensions.get(dim).get(currRow);

                        int[] theVals = new int[dimVals.size()];
                        for (int j = 0; j < theVals.length; ++j) {
                            theVals[j] = dimVals.get(j);
                        }

                        dims[dimIndex++] = theVals;
                    }

                    Object[] metricArray = new Object[numMetrics];
                    for (int i = 0; i < metricArray.length; ++i) {
                        switch (metrics[i].getType()) {
                        case FLOAT:
                            metricArray[i] = floatMetrics[i].get(currRow);
                            break;
                        case COMPLEX:
                            metricArray[i] = metrics[i].getComplexType().get(currRow);
                        }
                    }

                    Map<String, String> descriptions = Maps.newHashMap();
                    for (String spatialDim : index.getSpatialIndexes().keySet()) {
                        descriptions.put(spatialDim, "spatial");
                    }
                    final Rowboat retVal = new Rowboat(timestamps.get(currRow), dims, metricArray, currRow,
                            descriptions);

                    ++currRow;

                    return retVal;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}

From source file:org.jclouds.googlecloudstorage.domain.templates.ObjectTemplate.java

public ObjectTemplate customMetadata(Map<String, String> metadata) {
    if (this.metadata == null) {
        this.metadata = Maps.newLinkedHashMap();
    }/*from w w w  .  ja  v  a 2 s.  c om*/
    this.metadata.putAll(metadata);
    return this;
}

From source file:com.google.inject.internal.PrivateElementsImpl.java

public Set<Key<?>> getExposedKeys() {
    if (exposedKeysToSources == null) {
        Map<Key<?>, Object> exposedKeysToSourcesMutable = Maps.newLinkedHashMap();
        for (ExposureBuilder<?> exposureBuilder : exposureBuilders) {
            exposedKeysToSourcesMutable.put(exposureBuilder.getKey(), exposureBuilder.getSource());
        }/*from w ww.j  a va2 s.c  o  m*/
        exposedKeysToSources = ImmutableMap.copyOf(exposedKeysToSourcesMutable);
        exposureBuilders = null;
    }

    return exposedKeysToSources.keySet();
}

From source file:org.carrot2.util.attribute.BindableDescriptorBuilder.java

/**
 * Builds descriptors for direct attributes.
 *//* ww  w  .j  av  a 2s  . c  om*/
private static Map<String, AttributeDescriptor> buildAttributeDescriptors(Object initializedInstance,
        BindableMetadata bindableMetadata) {
    final Class<?> clazz = initializedInstance.getClass();

    final Map<String, AttributeDescriptor> result = Maps.newLinkedHashMap();
    final Collection<Field> fieldsFromBindableHierarchy = BindableUtils.getFieldsFromBindableHierarchy(clazz);

    for (final Field field : fieldsFromBindableHierarchy) {
        if (field.getAnnotation(Attribute.class) != null) {
            result.put(BindableUtils.getKey(field),
                    buildAttributeDescriptor(initializedInstance, field, bindableMetadata));
        }
    }

    return result;
}

From source file:com.intellij.lang.jsgraphql.parser.JSGraphQLParser.java

@NotNull
@Override//from  ww w. j a v  a2s .c  om
public ASTNode parse(@NotNull IElementType root, @NotNull PsiBuilder builder) {

    if (!(builder instanceof PsiBuilderImpl)) {
        throw new IllegalArgumentException("Unable to get lexer from builder implementation " + builder);
    }

    final JSGraphQLLexer lexer = (JSGraphQLLexer) ((PsiBuilderImpl) builder).getLexer();
    final List<JSGraphQLToken> tokens = lexer.getTokens();

    final Ref<Integer> tokenIndex = new Ref<>(0);
    builder.setWhitespaceSkippedCallback((type, start, end) -> tokenIndex.set(tokenIndex.get() + 1));

    final PsiBuilder.Marker rootMarker = builder.mark();

    final List<PropertyScope> propertyScopes = getPropertyScopes(tokens);
    final Map<JSGraphQLToken, PropertyScope> tokenToPropertyScope = Maps.newLinkedHashMap();
    for (PropertyScope propertyScope : propertyScopes) {
        tokenToPropertyScope.put(propertyScope.propertyOrOperation, propertyScope);
        if (propertyScope.lbrace != null && propertyScope.rbrace != null) {
            tokenToPropertyScope.put(propertyScope.lbrace, propertyScope);
            tokenToPropertyScope.put(propertyScope.rbrace, propertyScope);
        }
    }

    final Stack<MarkerScope> scopes = new Stack<>();
    while (!builder.eof()) {

        JSGraphQLToken currentToken = tokens.get(tokenIndex.get());

        // ---- property scopes ----

        final PropertyScope propertyScope = tokenToPropertyScope.get(currentToken);
        if (propertyScope != null) {

            if (scopes.isEmpty()) {
                if (currentToken.tokenType == JSGraphQLTokenTypes.RBRACE
                        || currentToken.tokenType == JSGraphQLTokenTypes.RBRACKET
                        || currentToken.tokenType == JSGraphQLTokenTypes.RPAREN) {
                    // closing scope without an open scope, so skip ahead to continue parsing
                    builder.advanceLexer();
                    tokenIndex.set(tokenIndex.get() + 1);
                    continue;
                }
            }

            if (currentToken.tokenType == JSGraphQLTokenTypes.PROPERTY
                    || currentToken.tokenType == JSGraphQLTokenTypes.KEYWORD/* query etc.*/) {
                if (propertyScope.lbrace != null) {
                    // Field property token with selection set is considered a scope
                    startScope(builder, scopes, currentToken, true);
                }
                if (currentToken.tokenType == JSGraphQLTokenTypes.PROPERTY) {
                    markCurrentToken(builder, tokenIndex, JSGraphQLElementType.PROPERTY_KIND);
                    continue;
                }
            } else if (currentToken.tokenType == JSGraphQLTokenTypes.LBRACE) {
                if (propertyScope.lbrace != null) {
                    startScope(builder, scopes, currentToken, false);
                }
            } else if (currentToken.tokenType == JSGraphQLTokenTypes.RBRACE) {
                if (JSGraphQLElementType.OBJECT_VALUE_KIND.equals(propertyScope.lbrace.sourceToken.getKind())) {
                    // close object value
                    endScope(builder, tokenIndex, scopes, true);
                    if (propertyScope.parentToClose != null) {
                        endScope(builder, tokenIndex, scopes, false);
                    }
                    continue;
                } else {
                    // close selection set
                    endScope(builder, tokenIndex, scopes, true);
                    // '}' in selection sets also closes the parent field it belongs to without advancing:
                    endScope(builder, tokenIndex, scopes, false);
                    continue;
                }
            } else if (currentToken.tokenType == JSGraphQLTokenTypes.LPAREN) {
                if (propertyScope.lbrace != null) {
                    startScope(builder, scopes, currentToken, false);
                }
            } else if (currentToken.tokenType == JSGraphQLTokenTypes.RPAREN) {
                endScope(builder, tokenIndex, scopes, true);
                continue;
            } else if (currentToken.tokenType == JSGraphQLTokenTypes.LBRACKET) {
                if (propertyScope.lbrace != null) {
                    startScope(builder, scopes, currentToken, false);
                }
            } else if (currentToken.tokenType == JSGraphQLTokenTypes.RBRACKET) {
                endScope(builder, tokenIndex, scopes, true);
                if (propertyScope.parentToClose != null) {
                    endScope(builder, tokenIndex, scopes, false);
                }
                continue;
            } else if (currentToken.tokenType == JSGraphQLTokenTypes.ATTRIBUTE) {
                // atribute with list/object value, so it's a scope for indentation, folding etc.
                startScope(builder, scopes, currentToken, false);
                markCurrentToken(builder, tokenIndex, JSGraphQLElementType.ATTRIBUTE_KIND);
                continue;
            }
        } else if (currentToken.tokenType == JSGraphQLTokenTypes.PROPERTY) {
            markCurrentToken(builder, tokenIndex, JSGraphQLElementType.PROPERTY_KIND);
            continue;
        } else if (currentToken.tokenType == JSGraphQLTokenTypes.ATOM) {
            markCurrentToken(builder, tokenIndex, JSGraphQLElementType.ATOM_KIND);
            continue;
        } else if (currentToken.tokenType == JSGraphQLTokenTypes.DEF) {
            markCurrentToken(builder, tokenIndex, JSGraphQLElementType.DEFINITION_KIND);
            continue;
        } else if (currentToken.tokenType == JSGraphQLTokenTypes.ATTRIBUTE) {
            // attribute with literal value (not a scope)
            markCurrentToken(builder, tokenIndex, JSGraphQLElementType.ATTRIBUTE_KIND);
            continue;
        }

        // ---- template fragment ----

        if (currentToken.tokenType == JSGraphQLTokenTypes.TEMPLATE_FRAGMENT) {
            markCurrentToken(builder, tokenIndex, JSGraphQLElementType.TEMPLATE_FRAGMENT_KIND);
            continue;
        }

        // ---- next token ----

        builder.advanceLexer();
        tokenIndex.set(tokenIndex.get() + 1);

    }

    // close up leftover scopes from missing '}' etc.
    while (!scopes.isEmpty()) {
        MarkerScope markerScope = scopes.pop();
        markerScope.marker.done(markerScope.tokenType);
    }

    rootMarker.done(root);

    return builder.getTreeBuilt();

}

From source file:org.eclipse.buildship.ui.view.task.ReloadTaskViewJob.java

private Map<String, IProject> allGradleWorkspaceProjects() {
    Map<String, IProject> result = Maps.newLinkedHashMap();
    for (IProject project : CorePlugin.workspaceOperations().getAllProjects()) {
        if (GradleProjectNature.isPresentOn(project)) {
            result.put(project.getName(), project);
        }/*w w  w.  ja  v  a 2 s .c om*/
    }
    return result;
}