package com.rwtema.funkylocomotion.movers;

import com.google.common.collect.Lists;
import com.rwtema.funkylocomotion.blocks.TileMovingServer;

import java.util.Iterator;
import java.util.List;
import java.util.WeakHashMap;

public class MovingTileRegistry {
    private static final Object BLANK_ENTRY = new Object();
    public static final WeakHashMap<TileMovingServer, Object> map = new WeakHashMap<TileMovingServer, Object>();

    public static void register(TileMovingServer moving) {
        map.put(moving, BLANK_ENTRY);
    }

    public static void deregister(TileMovingServer moving) {
        map.remove(moving);
    }

    public static List<TileMovingServer> getTilesFinishedMoving() {
        List<TileMovingServer> list = Lists.newArrayList();

        Iterator<TileMovingServer> iterator = map.keySet().iterator();
        while (iterator.hasNext()) {
            TileMovingServer tile = iterator.next();
            if (tile.isInvalid())
                iterator.remove();
            else if (tile.hasWorldObj() && tile.time >= tile.maxTime
                    && tile.getWorldObj().blockExists(tile.xCoord, tile.yCoord, tile.zCoord) // ensure the tile isn't in mid-chunk-load
                    )
                list.add(tile);
        }

        return list;
    }
}

@@ -136,17 +136,66 @@
 Server;%0A
+import com.rwtema.funkylocomotion.helper.WeakSet;
 %0A
-
 import j
@@ -239,38 +239,8 @@
 ist;
-%0Aimport java.util.WeakHashMap;
 %0A%0Apu
@@ -275,67 +275,8 @@
 y %7B%0A
-    private static final Object BLANK_ENTRY = new Object();
 %0A   
@@ -296,31 +296,27 @@
 c final Weak
-HashMap
+Set
 %3CTileMovingS
@@ -324,21 +324,24 @@
 rver
-, Object%3E map
+%3E movingTilesSet
  = n
@@ -351,15 +351,11 @@
 Weak
-HashMap
+Set
 %3CTil
@@ -371,16 +371,8 @@
 rver
-, Object
 %3E();
@@ -445,34 +445,32 @@
    m
-ap.put(moving, BLANK_ENTRY
+ovingTilesSet.add(moving
 );%0A 
@@ -545,18 +545,29 @@
        m
-ap
+ovingTilesSet
 .remove(
@@ -762,19 +762,21 @@
  = m
-ap.key
+ovingTiles
 Set
-()
 .ite

Change MovingTileRegistry to use WeakSet (simple refactor)