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.netflix.astyanax.thrift.model.ThriftRowsListImpl.java

public ThriftRowsListImpl(Map<ByteBuffer, List<ColumnOrSuperColumn>> rows, Serializer<K> keySer,
        Serializer<C> colSer) {/*from www. ja  v  a  2  s.  co m*/
    this.rows = Lists.newArrayListWithCapacity(rows.size());
    this.lookup = Maps.newLinkedHashMap();

    for (Entry<ByteBuffer, List<ColumnOrSuperColumn>> row : rows.entrySet()) {
        Row<K, C> thriftRow = new ThriftRowImpl<K, C>(keySer.fromByteBuffer(row.getKey().duplicate()),
                row.getKey(), new ThriftColumnOrSuperColumnListImpl<C>(row.getValue(), colSer));

        this.rows.add(thriftRow);
        lookup.put(thriftRow.getKey(), thriftRow);
    }
}

From source file:org.artifactory.descriptor.repo.jaxb.RemoteRepositoriesMapAdapter.java

@Override
public Map<String, RemoteRepoDescriptor> unmarshal(Wrappper wrapper) throws Exception {
    Map<String, RemoteRepoDescriptor> remoteRepositoriesMap = Maps.newLinkedHashMap();
    for (RemoteRepoDescriptor repository : wrapper.getList()) {
        String key = repository.getKey();
        RemoteRepoDescriptor repo = remoteRepositoriesMap.put(key, repository);
        //Test for repositories with the same key
        if (repo != null) {
            //Throw an error since jaxb swallows exceptions
            throw new Error("Duplicate repository key in configuration: " + key + ".");
        }/*from w  w  w .  j  a  v a  2 s . co  m*/
    }
    return remoteRepositoriesMap;
}

From source file:com.google.caja.ancillary.opt.ConstantPooler.java

private static void optimizeWithin(FunctionConstructor fc) {
    final Map<LitVal, LitVal> uses = Maps.newLinkedHashMap();
    Block body = fc.getBody();/*from   w w  w  .jav  a2 s.  co m*/
    body.acceptPreOrder(new Visitor() {
        public boolean visit(AncestorChain<?> chain) {
            if (chain.node instanceof Literal && !(chain.node instanceof RegexpLiteral)) {
                AncestorChain<Literal> litAc = chain.cast(Literal.class);
                LitVal key = new LitVal(litAc);
                LitVal stored = uses.get(key);
                if (stored == null) {
                    uses.put(key, stored = key);
                }
                stored.uses.add(litAc);
            } else if (chain.node instanceof ObjectConstructor) {
                List<? extends ObjProperty> children = chain.cast(ObjectConstructor.class).node.children();
                for (ObjProperty prop : children) {
                    visit(chain.child(prop).child(prop.children().get(1)));
                }
                return false;
            }
            return true;
        }
    }, null);
    List<Declaration> decls = Lists.newArrayList();
    FilePosition pos = FilePosition.startOf(body.getFilePosition());
    for (LitVal v : uses.values()) {
        // Size now = canonLen * nUses.
        // Size after = "var aa=".length + canonLen + ";".length + "aa" * nUses
        // Switch if now > after;
        //           canonLen * nUses > 8 + canonLen + 2 * nUses
        int requiredSavings = 30; // TUNING PARAMETER
        int canonLen = v.canonForm().length();
        int nUses = v.uses.size();
        if (canonLen * nUses > 8 + canonLen + 2 * nUses + requiredSavings) {
            // TODO(mikesamuel): choose a guaranteed non-interfering name.
            String name = "$_$__litpool__" + decls.size() + "$_$";
            decls.add(new Declaration(pos, new Identifier(pos, name), v.uses.get(0).node));
            for (AncestorChain<Literal> use : v.uses) {
                Reference ref = new Reference(new Identifier(use.node.getFilePosition(), name));
                use.parent.cast(MutableParseTreeNode.class).node.replaceChild(ref, use.node);
            }
        }
    }
    if (!decls.isEmpty()) {
        Statement first = body.children().get(0);
        MultiDeclaration md;
        if (first instanceof MultiDeclaration) {
            md = (MultiDeclaration) first;
        } else if (first instanceof Declaration) {
            md = new MultiDeclaration(FilePosition.span(pos, first.getFilePosition()),
                    Collections.singletonList((Declaration) first));
            body.replaceChild(md, first);
        } else if (decls.size() == 1) {
            body.insertBefore(decls.get(0), first);
            return;
        } else {
            md = new MultiDeclaration(pos, Collections.<Declaration>emptyList());
            body.insertBefore(md, first);
        }
        MutableParseTreeNode.Mutation mut = md.createMutation();
        Declaration firstDecl = md.children().get(0);
        for (Declaration decl : decls) {
            mut = mut.insertBefore(decl, firstDecl);
        }
        mut.execute();
    }
}

From source file:com.tinspx.util.example.Collect.java

/**
 * {@link Listenable} examples/*  w w w  . j a  v  a  2s. c o  m*/
 */
@SuppressWarnings("unchecked")
public static void listenable() {
    //wrap and observe changes made to a List
    List<Object> list = Lists.newArrayList();
    list = Listenable.list(list, new Listenable.Modification() {
        @Override
        public void onModify(Object src, Listenable.Event type) {
            System.out.println(type + " " + src);
        }
    });

    //prints INSERT [1, two, 3.0]
    list.addAll(Arrays.asList(1, "two", 3d));

    //prints REMOVE [1, 3.0]
    list.remove("two");

    //prints UPDATE [one, 3.0]
    list.set(0, "one");

    //wrap and observe changes made to a Map
    Map<String, String> map = Maps.newLinkedHashMap();
    map = Listenable.map(map, new Listenable.Modification() {
        @Override
        public void onModify(Object src, Listenable.Event type) {
            System.out.println(type + " " + src);
        }
    });

    //prints INSERT {a=x}
    map.put("a", "x");

    //prints UPDATE {a=b, c=d, e=f}
    map.putAll(ImmutableMap.of("a", "b", "c", "d", "e", "f"));

    //prints REMOVE {a=b, c=d}
    map.remove("e");

    //mofifying Map.Entry is also supported by default, but can be
    //disabled if not needed (which will provide better performance)
    //prints UPDATE {a=z, c=d}
    map.entrySet().iterator().next().setValue("z");
}

From source file:cc.recommenders.evaluation.evaluators.NMF1Evaluator.java

@Override
protected void startProcessingOfNewUsage(Usage usage) {
    intermediateResults = Maps.newLinkedHashMap();
}

From source file:com.baidu.rigel.biplatform.ma.report.model.TimerAreaLogicModel.java

/**
 * 
 * 
 * TimerAreaLogicModel
 */
public TimerAreaLogicModel() {
    this.timeDimensions = Maps.newLinkedHashMap();
}

From source file:org.onos.yangtools.yang.data.operations.MapNodeModification.java

@Override
public Optional<MapNode> modify(ListSchemaNode schema, Optional<MapNode> actual, Optional<MapNode> modification,
        OperationStack operationStack) throws DataModificationException {

    // Merge or None operation on parent, leaving actual if modification not present
    if (!modification.isPresent()) {
        return actual;
    }// www  .  j  ava2s  .c  om

    Map<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> resultNodes = Maps
            .newLinkedHashMap();
    if (actual.isPresent()) {
        resultNodes.putAll(mapEntries(actual.get()));
    }

    // TODO implement ordering for modification nodes

    for (MapEntryNode mapEntryModification : modification.get().getValue()) {

        operationStack.enteringNode(mapEntryModification);

        YangInstanceIdentifier.NodeIdentifierWithPredicates entryKey = mapEntryModification.getIdentifier();

        switch (operationStack.getCurrentOperation()) {
        case NONE:
            DataModificationException.DataMissingException.check(schema.getQName(), actual,
                    mapEntryModification);
        case MERGE: {
            MapEntryNode mergedListNode;
            if (resultNodes.containsKey(entryKey)) {
                MapEntryNode actualEntry = resultNodes.get(entryKey);
                mergedListNode = MAP_ENTRY_NODE_MODIFICATION.modify(schema, Optional.of(actualEntry),
                        Optional.of(mapEntryModification), operationStack).get();
            } else {
                mergedListNode = mapEntryModification;
            }

            resultNodes.put(mergedListNode.getIdentifier(), mergedListNode);
            break;
        }
        case CREATE: {
            DataModificationException.DataExistsException.check(schema.getQName(), actual,
                    mapEntryModification);
        }
        case REPLACE: {
            resultNodes.put(entryKey, mapEntryModification);
            break;
        }
        case DELETE: {
            DataModificationException.DataMissingException.check(schema.getQName(), actual,
                    mapEntryModification);
        }
        case REMOVE: {
            if (resultNodes.containsKey(entryKey)) {
                resultNodes.remove(entryKey);
            }
            break;
        }
        default:
            throw new UnsupportedOperationException(
                    String.format("Unable to perform operation: %s on: %s, unknown",
                            operationStack.getCurrentOperation(), schema));
        }

        operationStack.exitingNode(mapEntryModification);
    }
    return build(schema, resultNodes);
}

From source file:com.ppcxy.cyfm.showcase.demos.utilities.xml.HouseMapAdapter.java

@Override
public Map<String, String> unmarshal(HouseMap houseMap) throws Exception {
    Map<String, String> map = Maps.newLinkedHashMap();
    for (HouseMap.HouseEntry e : houseMap.entries) {
        map.put(e.key, e.value);// w  ww  . j  a v  a  2  s .com
    }
    return map;
}

From source file:org.esupportail.publisher.service.bean.AuthoritiesDefinition.java

@Override
public Map<String, IEvaluation> getAppRoles() {
    Map<String, IEvaluation> accessRoles = Maps.newLinkedHashMap();
    accessRoles.put(AuthoritiesConstants.ADMIN, admins);
    accessRoles.put(AuthoritiesConstants.USER, users);
    if (log.isDebugEnabled()) {
        log.debug("App Roles defined : {}", accessRoles.toString());
    }/*from  w w  w. j  a  va  2  s  .  com*/
    return accessRoles;
}

From source file:com.google.devtools.j2objc.translate.TypeSorter.java

public static void sortTypes(CompilationUnit unit) {
    List<AbstractTypeDeclaration> typeNodes = unit.getTypes();
    Map<String, AbstractTypeDeclaration> nodeMap = Maps.newHashMap();
    LinkedHashMap<String, ITypeBinding> bindingMap = Maps.newLinkedHashMap();
    for (AbstractTypeDeclaration node : typeNodes) {
        ITypeBinding typeBinding = node.getTypeBinding();
        String key = typeBinding.getKey();
        nodeMap.put(key, node);//from  w w  w. jav a  2  s .  co  m
        bindingMap.put(key, typeBinding);
    }
    Multimap<String, String> superTypes = findSuperTypes(bindingMap);

    ArrayList<String> rootTypes = Lists.newArrayListWithCapacity(typeNodes.size());
    for (String type : bindingMap.keySet()) {
        if (!superTypes.containsValue(type)) {
            rootTypes.add(type);
        }
    }

    typeNodes.clear();
    while (!rootTypes.isEmpty()) {
        String nextType = rootTypes.remove(rootTypes.size() - 1);
        typeNodes.add(0, nodeMap.get(nextType));
        for (String superType : superTypes.removeAll(nextType)) {
            if (!superTypes.containsValue(superType)) {
                rootTypes.add(superType);
            }
        }
    }
}