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:io.atomix.core.tree.impl.DefaultDocumentTreeNode.java

public DefaultDocumentTreeNode(DocumentPath key, V value, long version, Ordering ordering,
        DocumentTreeNode<V> parent) {
    this.key = checkNotNull(key);
    this.value = new Versioned<>(value, version);
    this.ordering = ordering;
    this.parent = parent;

    switch (ordering) {
    case INSERTION:
        children = Maps.newLinkedHashMap();
        break;/*from ww w. j a  v  a  2s .  c o m*/
    case NATURAL:
    default:
        children = Maps.newTreeMap();
        break;
    }
}

From source file:org.sakaiproject.nakamura.resource.lite.servlet.post.AbstractGetAclServlet.java

protected void outputAcl(Map<String, Object> acl, ServletResponse response) throws JSONException, IOException {
    Map<String, Map<String, Set<String>>> aclMap = Maps.newLinkedHashMap();
    for (Entry<String, Object> ace : acl.entrySet()) {
        String principalKey = ace.getKey();
        String principal = AclModification.getPrincipal(principalKey);
        if (principal != null) {
            String type = AclModification.isGrant(principalKey) ? "granted" : "denied";
            Set<String> s = createSet(createMap(aclMap, principal), type);

            try {
                // Add permissions for all valid integer inputs. If string is invalid (not an
                // integer or value is too large) then skip
                for (Permission p : AclModification.listPermissions(StorageClientUtils.toInt(ace.getValue()))) {
                    s.add(p.getName());/*from  w w  w . j  a  v  a  2s . c o  m*/
                }
            } catch (NumberFormatException e) {
            }
        }
    }

    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");

    List<JSONObject> aclList = new ArrayList<JSONObject>();
    for (Entry<String, Map<String, Set<String>>> entry : aclMap.entrySet()) {
        String principalName = entry.getKey();
        Map<String, Set<String>> value = entry.getValue();

        JSONObject aceObject = new JSONObject();
        aceObject.put("principal", principalName);

        Set<String> grantedSet = value.get("granted");
        if (grantedSet != null) {
            aceObject.put("granted", grantedSet);
        }

        Set<String> deniedSet = value.get("denied");
        if (deniedSet != null) {
            aceObject.put("denied", deniedSet);
        }
        aclList.add(aceObject);
    }
    JSONObject jsonAclMap = new JSONObject(aclMap);
    for (JSONObject jsonObj : aclList) {
        jsonAclMap.put(jsonObj.getString("principal"), jsonObj);
    }
    jsonAclMap.write(response.getWriter());
}

From source file:io.druid.cli.convert.DatabasePropertiesConverter.java

@Override
public Map<String, String> convert(Properties properties) {
    if (!ran.getAndSet(true)) {
        String tablePrefix = properties.getProperty("druid.database.segmentTable");

        if (tablePrefix == null) {
            tablePrefix = "druid";
        } else {/*  www  .j av  a  2 s  . c  o  m*/
            tablePrefix = tablePrefix.split("_")[0];
        }

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

        retVal.put("druid.db.tables.base", tablePrefix);

        addIfNotDefault(properties, tablePrefix, retVal, "druid.database.segmentTable", "segments");
        addIfNotDefault(properties, tablePrefix, retVal, "druid.database.configTable", "config");
        addIfNotDefault(properties, tablePrefix, retVal, "druid.database.ruleTable", "rules");
        addIfNotDefault(properties, tablePrefix, retVal, "druid.database.taskTable", "tasks");
        addIfNotDefault(properties, tablePrefix, retVal, "druid.database.taskLockTable", "taskLock");
        addIfNotDefault(properties, tablePrefix, retVal, "druid.database.taskLogTable", "taskLog");

        return retVal;
    }
    return ImmutableMap.of();
}

From source file:me.boomboompower.deathwalls.maker.SimpleScoreboard.java

public SimpleScoreboard(String title) {
    this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
    this.title = Logging.colored(title);
    this.scores = Maps.newLinkedHashMap();
    this.teams = Lists.newArrayList();
}

From source file:javastory.game.quest.QuestStatus.java

public QuestStatus(final int questId, final byte status) {
    this.questId = questId;
    this.state = status;
    this.completionTime = System.currentTimeMillis();
    if (status == 1) {
        if (this.getQuestInfo().getRelevantMobs().size() > 0) {
            this.killedMobs = Maps.newLinkedHashMap();
            this.registerMobs();
        }/*  w  w  w.jav  a2  s  .c  o  m*/
    }
}

From source file:org.terasology.persistence.typeHandling.coreTypes.StringMapTypeHandler.java

@Override
public Map<String, T> deserialize(PersistedData data, DeserializationContext context) {
    Map<String, T> result = Maps.newLinkedHashMap();
    if (data.isValueMap()) {
        for (Map.Entry<String, PersistedData> item : data.getAsValueMap().entrySet()) {
            result.put(item.getKey(), contentsHandler.deserialize(item.getValue(), context));
        }//from   w w w  .java  2s.  com
    }
    return result;
}

From source file:test.ExtensionsViewer.java

/**
 * @throws java.io.IOException//from  w w w.j a  v  a2s . c  om
 */
@SuppressWarnings("UseOfSystemOutOrSystemErr")
@Test
public void test() throws IOException {
    Process process = new ProcessBuilder()
            .command("git", "ls-files", "-z", "--", ":(glob,top,exclude).gitattributes")
            .redirectErrorStream(true).start();
    Map<String, List<Path>> map = Maps.newLinkedHashMap();
    try (InputStream is = process.getInputStream();
            InputStreamReader ir = new InputStreamReader(is, StandardCharsets.UTF_8);
            BufferedReader br = new BufferedReader(ir)) {
        for (StringBuilder sb = new StringBuilder(20);;) {
            int x = br.read();
            if (x == -1) {
                break;
            }
            if (x != 0) {
                sb.append((char) x);
                continue;
            }
            Path path = Paths.get(sb.toString());
            String extension = getExtension(path);
            if (extension.isEmpty()) {
                continue;
            }
            map.computeIfAbsent(extension, __ -> Lists.newArrayList()).add(path);
            sb.setLength(0);
        }
    }

    String gitRoot = new String(IOUtils.toByteArray(
            new ProcessBuilder().command("git", "rev-parse", "--show-toplevel").start().getInputStream()),
            StandardCharsets.UTF_8).trim();

    map.keySet()
            .removeIf(Files.lines(Paths.get(gitRoot, ".gitattributes")).map(String::trim)
                    .filter(str -> str.startsWith("*.")).map(str -> str.replaceAll("^\\*\\.|\\s.+$", ""))
                    .collect(Collectors.toSet())::contains);
    System.out.println(map);
}

From source file:org.auraframework.impl.adapter.JsonSerializerAdapterImpl.java

@Override
public Map<String, JsonSerializer<?>> lookupSerializers() {
    Map<String, JsonSerializer<?>> m = Maps.newLinkedHashMap();
    m.putAll(JsonSerializers.MAPPY_FASTY);
    m.put(AuraContextImpl.class.getName(), AuraContextImpl.FULL_SERIALIZER);
    m.put(JavaAction.class.getName(), Action.SERIALIZER);
    m.put(ActionWithKeyOverride.class.getName(), Action.SERIALIZER);
    m.put(BigDecimal.class.getName(), JsonSerializers.BIGDECIMAL);
    return m;//from   ww w.j a v a 2  s.c  o  m
}

From source file:org.ldp4j.application.kernel.persistence.jpa.AttachmentCollection.java

AttachmentCollection() {
    this.indexByAttachmentId = Maps.newLinkedHashMap();
    this.indexByResourceId = Maps.newLinkedHashMap();
}

From source file:org.gradle.api.internal.tasks.compile.incremental.classpath.ClasspathSnapshotFactory.java

ClasspathSnapshot createSnapshot(final Iterable<File> entries) {
    final Set<CreateSnapshot> snapshotOperations = snapshotAll(entries);

    final LinkedHashMap<File, ClasspathEntrySnapshot> snapshots = Maps.newLinkedHashMap();
    final LinkedHashMap<File, HashCode> hashes = Maps.newLinkedHashMap();
    final Set<String> allClasses = Sets.newHashSet();
    final Set<String> duplicateClasses = Sets.newHashSet();

    for (CreateSnapshot operation : snapshotOperations) {
        File entry = operation.entry;
        ClasspathEntrySnapshot snapshot = operation.snapshot;
        if (snapshot != null) {
            snapshots.put(entry, snapshot);
            hashes.put(entry, snapshot.getHash());
            for (String c : snapshot.getClasses()) {
                if (!allClasses.add(c)) {
                    duplicateClasses.add(c);
                }/*w w  w  . ja va  2  s  .  c o  m*/
            }
        }
    }

    ClasspathSnapshotData classpathSnapshotData = new ClasspathSnapshotData(hashes, duplicateClasses);
    return new ClasspathSnapshot(snapshots, classpathSnapshotData);
}