Spot more modification

This commit is contained in:
BuildTools 2015-11-28 17:23:10 +01:00 committed by Olof Larsson
parent a0685d0b5b
commit c9466eb3c5
2 changed files with 77 additions and 74 deletions

View File

@ -528,6 +528,10 @@ public class Coll<E extends Entity<E>> extends CollAbstract<E>
// Then attach! // Then attach!
this.attach(entity, id, false); this.attach(entity, id, false);
// On creation it might be modified by addition or removal of new/old fields.
// So we must do a check for that.
entity.changed();
} }
entity.setLastRaw(raw); entity.setLastRaw(raw);
@ -782,7 +786,6 @@ public class Coll<E extends Entity<E>> extends CollAbstract<E>
@Override @Override
public void identifyModifications(Modification veto) public void identifyModifications(Modification veto)
{ {
// Get remote id2mtime snapshot // Get remote id2mtime snapshot
Map<String, Long> id2RemoteMtime = this.getDb().getId2mtime(this); Map<String, Long> id2RemoteMtime = this.getDb().getId2mtime(this);
@ -960,7 +963,7 @@ public class Coll<E extends Entity<E>> extends CollAbstract<E>
@Override @Override
public void init() public void init()
{ {
if (this.inited()) return; // TODO: Would throwing an exception make more sense? if (this.inited()) throw new IllegalStateException("Already initialised.");
if (this.supportsPusher()) if (this.supportsPusher())
{ {
@ -968,7 +971,7 @@ public class Coll<E extends Entity<E>> extends CollAbstract<E>
} }
this.initLoadAllFromRemote(); this.initLoadAllFromRemote();
// this.syncAll(); this.syncIdentified();
name2instance.put(this.getName(), this); name2instance.put(this.getName(), this);
} }
@ -976,7 +979,7 @@ public class Coll<E extends Entity<E>> extends CollAbstract<E>
@Override @Override
public void deinit() public void deinit()
{ {
if ( ! this.inited()) return; // TODO: Would throwing an exception make more sense? if ( ! this.inited()) throw new IllegalStateException("Not initialised.");
if (this.supportsPusher()) if (this.supportsPusher())
{ {

View File

@ -1,70 +1,70 @@
package com.massivecraft.massivecore.store; package com.massivecraft.massivecore.store;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class IndexUniqueField<F, O> public class IndexUniqueField<F, O>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private Map<F, O> f2o; private Map<F, O> f2o;
private Map<O, F> o2f; private Map<O, F> o2f;
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public IndexUniqueField(Map<F, O> map) public IndexUniqueField(Map<F, O> map)
{ {
this.f2o = map; this.f2o = map;
this.o2f = new HashMap<O, F>(); this.o2f = new HashMap<O, F>();
} }
// -------------------------------------------- // // -------------------------------------------- //
// STUFF // STUFF
// -------------------------------------------- // // -------------------------------------------- //
public void update(O object, F field) public void update(O object, F field)
{ {
if (object == null) return; if (object == null) return;
if (field == null) return; if (field == null) return;
this.f2o.put(field, object); this.f2o.put(field, object);
this.o2f.put(object, field); this.o2f.put(object, field);
} }
public O removeField(F field) public O removeField(F field)
{ {
if (field == null) return null; if (field == null) return null;
O object = this.f2o.remove(field); O object = this.f2o.remove(field);
if (object != null) this.o2f.remove(object); if (object != null) this.o2f.remove(object);
return object; return object;
} }
public F removeObject(O object) public F removeObject(O object)
{ {
if (object == null) return null; if (object == null) return null;
F field = this.o2f.remove(object); F field = this.o2f.remove(object);
if (field != null) this.f2o.remove(object); if (field != null) this.f2o.remove(object);
return field; return field;
} }
public O getObject(F field) public O getObject(F field)
{ {
if (field == null) return null; if (field == null) return null;
return this.f2o.get(field); return this.f2o.get(field);
} }
public F getField(O object) public F getField(O object)
{ {
if (object == null) return null; if (object == null) return null;
return this.o2f.get(object); return this.o2f.get(object);
} }
} }