/** * Assigns sequential identifiers to the provided <code>clusters</code> (and their sub-clusters). * If a cluster already has an identifier, the identifier will not be changed. * * @param clusters Clusters to assign identifiers to. * @throws IllegalArgumentException if the provided clusters contain non-unique identifiers */ public static void assignClusterIds(Collection<Cluster> clusters) { final ArrayList<Cluster> flattened = Lists.newArrayListWithExpectedSize(clusters.size()); flatten(flattened, clusters); synchronized (clusters) { final HashSet<Integer> ids = Sets.newHashSet(); // First, find the start value for the id and check uniqueness of the ids // already provided. int maxId = Integer.MIN_VALUE; for (final Cluster cluster : flattened) { if (cluster.id != null) { if (!ids.add(cluster.id)) { throw new IllegalArgumentException("Non-unique cluster id found: " + cluster.id); } maxId = Math.max(maxId, cluster.id); } } // We'd rather start with 0 maxId = Math.max(maxId, -1); // Assign missing ids for (final Cluster c : flattened) { if (c.id == null) { c.id = ++maxId; } } } }
public static TileEntity getTileEntity(IBlockAccess blockaccess, int x, int y, int z) { HashSet<ChunkCoordinates> visited = Sets.newHashSet(); Block block = blockaccess.getBlock(x, y, z); while (block != NailedBlocks.portalController) { if (isValidLinkPortalBlock(block) == 0) { return null; } ChunkCoordinates pos = new ChunkCoordinates(x, y, z); if (!visited.add(pos)) { return null; } int meta = blockaccess.getBlockMetadata(x, y, z); if (meta == 0) { return null; } if (meta == 1) { y--; } else if (meta == 2) { y++; } else if (meta == 3) { z--; } else if (meta == 4) { z++; } else if (meta == 5) { x--; } else if (meta == 6) { x++; } else { return null; } block = blockaccess.getBlock(x, y, z); } return blockaccess.getTileEntity(x, y, z); }
Set<Object> getPartitions(List<Document> documents) { final HashSet<Object> partitions = Sets.newHashSet(); for (Document document : documents) { final Collection<Object> documentPartitions = document.<Collection<Object>>getField(partitionIdFieldName); if (documentPartitions != null) { partitions.addAll(documentPartitions); } } return partitions; }