title: hashmap custom class key && object saving/loading
body: <p>Been working on a project for a while now and I've come across a few different complications and solutions that don't seem to pan out together.</p>
  
  <pre><code>final public class place implements Serializable {
      private static final long serialVersionUID = -8851896330953573877L;
      String world;
      Double X;
      Double Y;
      Double Z;
  }
  HashMap&lt;place, Long&gt; blockmap = new HashMap&lt;place, Long&gt;(); // does not work
  HashMap&lt;Location, Long&gt; blockmap = new HashMap&lt;Location, Long&gt;(); //works
  </code></pre>
  
  <p>First, my hashmap is a hashmap containing the time an item was placed (or added) to the world. place is a 'class place {}' containing String world, double x, double y, double z; The problem i've had with this, is that it doesn't work with hashmaps. I can store a new hash key using it, but i cant call to get its value. Using Location instead fixes this problem (hashmap) and works flawlessly.</p>
  
  <pre><code>public void SetBlock(Block block) {
      Location loc = new Location(null, block.getLocation().getX(),block.getLocation().getY(),block.getLocation().getZ());
      //...
      Long time = (long) (System.currentTimeMillis() / 60000);
      //...
      if (blockmap.containsKey(loc)) {
              blockmap.remove(loc);
              blockmap.put(loc, time);
              //System.out.println("MyLeveler: Block Existed, Updated");
      } else {
              blockmap.put(loc, time);
              //System.out.println("MyLeveler: Block added to " + loc.getX() + ", " + loc.getY() + ", " + loc.getZ());
              //System.out.println("MyLeveler: total blocks saved: " + blockmap.size());
      }
  }
  </code></pre>
  
  <p>This works without error. Now, for the purpose, this data has to be saved and reloaded when the plugin is disabled, and enabled. To do this, i created a new java class file with a save/load feature. </p>
  
  <pre><code>import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  
  public class SLAPI {
      public static void save(Object obj,String path) throws Exception
      {
          ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path));
          oos.writeObject(obj);
          oos.flush();
          oos.close();
      }
      public static Object load(String path) throws Exception
      {
          ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path));
          Object result = ois.readObject();
          ois.close();
          return result;
      }
  }
  </code></pre>
  
  <p>I typically get "notserializable" errors. Using 'implements Serializable' and ois.defaultReadObject() or oos.defaultWriteObject() which checks the serial on the file results in a clean save/load only when the object is EMPTY! When it contains data, i constantly get "java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException"</p>
  
  <p>This is clearly a problem! One of the recommendations here: <a href="https://stackoverflow.com/questions/6775478/arraylist-custom-class-as-hashmap-key">ArrayList custom class as HashMap key</a> failed to produce any better results. In fact, creating a custom class was my first issue to begin with >.></p>
  
  <p>So i guess the questions are:</p>
  
  <p>1) What would i have to alter to use the custom class as a key (and work properly)</p>
  
  <p>2) Why doesn't it recognize that i'm setting it as a serializable class/function/java class</p>
  
  <p>3) Why does it work with an empty hashmap, but not with a filled hashmap?</p>