Example usage for java.util Map.Entry values

List of usage examples for java.util Map.Entry values

Introduction

In this page you can find the example usage for java.util Map.Entry values.

Prototype

Collection<V> values();

Source Link

Document

Returns a Collection view of the values contained in this map.

Usage

From source file:com.msopentech.odatajclient.testservice.utils.AbstractUtilities.java

protected String getDefaultEntryKey(final String entitySetName, final InputStream entity, final Accept accept)
        throws IOException {
    try {//from   w  w  w  . j ava 2 s  .  co m
        String res;

        if ("Message".equals(entitySetName)) {
            try {
                final List<String> propertyNames = new ArrayList<String>();
                propertyNames.add("MessageId");
                propertyNames.add("FromUsername");

                final StringBuilder keyBuilder = new StringBuilder();
                for (Map.Entry<String, InputStream> value : getPropertyValues(entity, propertyNames, accept)
                        .entrySet()) {

                    if (keyBuilder.length() > 0) {
                        keyBuilder.append(",");
                    }

                    keyBuilder.append(value.getKey()).append("=").append(IOUtils.toString(value.getValue()));
                }
                res = keyBuilder.toString();
            } catch (Exception e) {
                int messageId = sequence.get(entitySetName) + 1;
                if (sequence.containsKey(entitySetName)) {
                    res = "MessageId=" + String.valueOf(messageId) + ",FromUsername=1";
                } else {
                    throw new Exception(
                            String.format("Unable to retrieve entity key value for %s", entitySetName));
                }
                sequence.put(entitySetName, Integer.valueOf(messageId));
            }
        } else if ("Order".equals(entitySetName)) {
            try {
                final Map<String, InputStream> value = getPropertyValues(entity,
                        Collections.<String>singletonList("OrderId"), accept);
                res = value.isEmpty() ? null : IOUtils.toString(value.values().iterator().next());
            } catch (Exception e) {
                if (sequence.containsKey(entitySetName)) {
                    res = String.valueOf(sequence.get(entitySetName) + 1);
                } else {
                    throw new Exception(
                            String.format("Unable to retrieve entity key value for %s", entitySetName));
                }
            }
            sequence.put(entitySetName, Integer.valueOf(res));
        } else if ("Customer".equals(entitySetName)) {
            try {
                final Map<String, InputStream> value = getPropertyValues(entity,
                        Collections.<String>singletonList("CustomerId"), accept);
                res = value.isEmpty() ? null : IOUtils.toString(value.values().iterator().next());
            } catch (Exception e) {
                if (sequence.containsKey(entitySetName)) {
                    res = String.valueOf(sequence.get(entitySetName) + 1);
                } else {
                    throw new Exception(
                            String.format("Unable to retrieve entity key value for %s", entitySetName));
                }
            }
            sequence.put(entitySetName, Integer.valueOf(res));
        } else if ("ComputerDetail".equals(entitySetName)) {
            try {
                final Map<String, InputStream> value = getPropertyValues(entity,
                        Collections.<String>singletonList("ComputerDetailId"), accept);
                res = value.isEmpty() ? null : IOUtils.toString(value.values().iterator().next());
            } catch (Exception e) {
                if (sequence.containsKey(entitySetName)) {
                    res = String.valueOf(sequence.get(entitySetName) + 1);
                } else {
                    throw new Exception(
                            String.format("Unable to retrieve entity key value for %s", entitySetName));
                }
            }
            sequence.put(entitySetName, Integer.valueOf(res));
        } else if ("AllGeoTypesSet".equals(entitySetName)) {
            try {
                final Map<String, InputStream> value = getPropertyValues(entity,
                        Collections.<String>singletonList("Id"), accept);
                res = value.isEmpty() ? null : IOUtils.toString(value.values().iterator().next());
            } catch (Exception e) {
                if (sequence.containsKey(entitySetName)) {
                    res = String.valueOf(sequence.get(entitySetName) + 1);
                } else {
                    throw new Exception(
                            String.format("Unable to retrieve entity key value for %s", entitySetName));
                }
            }
            sequence.put(entitySetName, Integer.valueOf(res));
        } else if ("CustomerInfo".equals(entitySetName)) {
            try {
                final Map<String, InputStream> value = getPropertyValues(entity,
                        Collections.<String>singletonList("CustomerInfoId"), accept);
                res = value.isEmpty() ? null : IOUtils.toString(value.values().iterator().next());
            } catch (Exception e) {
                if (sequence.containsKey(entitySetName)) {
                    res = String.valueOf(sequence.get(entitySetName) + 1);
                } else {
                    throw new Exception(
                            String.format("Unable to retrieve entity key value for %s", entitySetName));
                }
            }
            sequence.put(entitySetName, Integer.valueOf(res));
        } else {
            throw new Exception(String.format("EntitySet '%s' not found", entitySetName));
        }

        return res;
    } catch (Exception e) {
        throw new NotFoundException(e);
    } finally {
        IOUtils.closeQuietly(entity);
    }
}

From source file:com.replaymod.replaystudio.filter.SquashFilter.java

@Override
public void onEnd(PacketStream stream, long timestamp) {
    List<PacketData> result = new ArrayList<>();

    result.addAll(unhandled);//from w w w.j  ava2 s.com
    result.addAll(currentWorld);
    result.addAll(currentWindow);
    result.addAll(closeWindows);
    result.addAll(mainInventoryChanges.values());

    if (mainInventory != null) {
        result.add(mainInventory);
    }

    if (joinGame != null) {
        ServerJoinGamePacket org = (ServerJoinGamePacket) joinGame.getPacket();
        Packet packet = new ServerJoinGamePacket(org.getEntityId(), org.getHardcore(), gameMode, dimension,
                difficulty, org.getMaxPlayers(), worldType, reducedDebugInfo);
        result.add(new PacketData(joinGame.getTime(), packet));
    } else if (respawn != null) {
        Packet packet = new ServerRespawnPacket(dimension, difficulty, gameMode, worldType);
        result.add(new PacketData(respawn.getTime(), packet));
    } else {
        if (difficulty != null) {
            result.add(new PacketData(lastTimestamp, new ServerDifficultyPacket(difficulty)));
        }
        if (gameMode != null) {
            Packet packet = new ServerNotifyClientPacket(ClientNotification.CHANGE_GAMEMODE, gameMode);
            result.add(new PacketData(lastTimestamp, packet));
        }
    }

    if (experience != null) {
        result.add(new PacketData(lastTimestamp, experience));
    }
    if (abilities != null) {
        result.add(new PacketData(lastTimestamp, abilities));
    }

    for (Map.Entry<Integer, Entity> e : entities.entrySet()) {
        Entity entity = e.getValue();

        FOR_PACKETS: for (PacketData data : entity.packets) {
            Packet packet = data.getPacket();
            Integer id = PacketUtils.getEntityId(packet);
            if (id == -1) { // Multiple entities
                List<Integer> allIds = PacketUtils.getEntityIds(packet);
                for (int i : allIds) {
                    if (!entities.containsKey(i)) { // Other entity doesn't exist
                        continue FOR_PACKETS;
                    }
                }
            }
            result.add(data);
        }

        if (entity.loc != null) {
            result.add(new PacketData(entity.lastTimestamp,
                    entity.loc.toServerEntityTeleportPacket(e.getKey(), entity.onGround)));
        }
        while (entity.dx != 0 && entity.dy != 0 && entity.dz != 0) {
            long mx = within(entity.dx, POS_MIN, POS_MAX);
            long my = within(entity.dy, POS_MIN, POS_MAX);
            long mz = within(entity.dz, POS_MIN, POS_MAX);
            entity.dx -= mx;
            entity.dy -= my;
            entity.dz -= mz;
            ServerEntityPositionPacket p = new ServerEntityPositionPacket(e.getKey(), mx / 32d, my / 32d,
                    mz / 32d, entity.onGround);
            result.add(new PacketData(entity.lastTimestamp, p));
        }
        if (entity.yaw != null && entity.pitch != null) {
            ServerEntityRotationPacket p = new ServerEntityRotationPacket(e.getKey(), entity.yaw, entity.pitch,
                    entity.onGround);
            result.add(new PacketData(entity.lastTimestamp, p));
        }
    }

    for (Map.Entry<Long, Long> e : unloadedChunks.entrySet()) {
        int x = ChunkData.longToX(e.getKey());
        int z = ChunkData.longToZ(e.getKey());
        result.add(new PacketData(e.getValue(), new ServerChunkDataPacket(x, z)));
    }

    for (ChunkData chunk : chunks.values()) {
        Packet packet = new ServerChunkDataPacket(chunk.x, chunk.z, chunk.changes, chunk.biomeData);
        result.add(new PacketData(chunk.firstAppearance, packet));
        for (Map<Short, MutablePair<Long, BlockChangeRecord>> e : chunk.blockChanges) {
            if (e != null) {
                for (MutablePair<Long, BlockChangeRecord> pair : e.values()) {
                    result.add(new PacketData(pair.getLeft(), new ServerBlockChangePacket(pair.getRight())));
                }
            }
        }
    }

    Collections.sort(result, (e1, e2) -> Long.compare(e1.getTime(), e2.getTime()));
    for (PacketData data : result) {
        add(stream, timestamp, data.getPacket());
    }

    for (Team team : teams.values()) {
        String[] added = team.added.toArray(new String[team.added.size()]);
        String[] removed = team.added.toArray(new String[team.removed.size()]);
        if (team.status == Team.Status.CREATED) {
            add(stream, timestamp,
                    new ServerTeamPacket(team.name, team.displayName, team.prefix, team.suffix,
                            team.friendlyFire, team.seeingFriendlyInvisibles, team.nameTagVisibility,
                            team.color, added));
        } else if (team.status == Team.Status.UPDATED) {
            if (team.color != null) {
                add(stream, timestamp,
                        new ServerTeamPacket(team.name, team.displayName, team.prefix, team.suffix,
                                team.friendlyFire, team.seeingFriendlyInvisibles, team.nameTagVisibility,
                                team.color));
            }
            if (added.length > 0) {
                add(stream, timestamp, new ServerTeamPacket(team.name, TeamAction.ADD_PLAYER, added));
            }
            if (removed.length > 0) {
                add(stream, timestamp, new ServerTeamPacket(team.name, TeamAction.REMOVE_PLAYER, removed));
            }
        } else if (team.status == Team.Status.REMOVED) {
            add(stream, timestamp, new ServerTeamPacket(team.name));
        }
    }

    for (ServerMapDataPacket packet : maps.values()) {
        add(stream, timestamp, packet);
    }
}