1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-11 09:42:54 +00:00

Implemented AccountID object

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-14 14:35:18 -03:00
parent fddc6fbfbb
commit d8d561688b
27 changed files with 200 additions and 54 deletions

View File

@@ -0,0 +1,21 @@
package com.l2jserver.model.id;
import com.google.inject.assistedinject.Assisted;
/**
* Each account is identified by its {@link ID}. This {@link ID} is equal to the
* account username or login.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class AccountID extends ID<String> {
/**
* Creates a new instance
*
* @param login
* the login
*/
public AccountID(@Assisted String login) {
super(login);
}
}

View File

@@ -1,30 +1,27 @@
package com.l2jserver.model.id;
import com.google.inject.Inject;
import com.l2jserver.model.template.Template;
import com.l2jserver.model.world.WorldObject;
/**
* The ID interface. Each {@link WorldObject} or {@link Template} must be
* represented by an unique ID.
* The ID interface. Each object must be represented by an unique ID.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class ID {
public abstract class ID<T> {
/**
* The id itself
*/
protected final int id;
protected final T id;
@Inject
protected ID(int id) {
protected ID(T id) {
this.id = id;
}
/**
* @return the id
*/
public int getID() {
public T getID() {
return id;
}
@@ -37,7 +34,7 @@ public abstract class ID {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id + this.getClass().hashCode();
result = prime * result + id.hashCode() + this.getClass().hashCode();
return result;
}
@@ -49,9 +46,14 @@ public abstract class ID {
return false;
if (getClass() != obj.getClass())
return false;
@SuppressWarnings("rawtypes")
ID other = (ID) obj;
if (id != other.id)
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}

View File

@@ -14,7 +14,7 @@ import com.l2jserver.model.world.WorldObject;
* @param <T>
* the {@link WorldObject} type
*/
public abstract class ObjectID<T extends WorldObject> extends ID {
public abstract class ObjectID<T extends WorldObject> extends ID<Integer> {
/**
* Creates a new instance
*

View File

@@ -8,7 +8,7 @@ import com.l2jserver.model.template.Template;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class TemplateID<T extends Template<?>> extends ID {
public abstract class TemplateID<T extends Template<?>> extends ID<Integer> {
/**
* Creates a new instance
*

View File

@@ -0,0 +1,11 @@
package com.l2jserver.model.id.factory;
import com.l2jserver.model.id.AccountID;
/**
* Creates a new {@link AccountID}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface AccountIDFactory extends IDFactory<String, AccountID> {
}

View File

@@ -8,12 +8,12 @@ import com.l2jserver.model.id.ID;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface IDFactory<T extends ID> {
public interface IDFactory<I, T extends ID<?>> {
/**
* Creates the ID object for an <b>EXISTING</b> ID.
*
* @param id
* @return
*/
T createID(int id);
T createID(I id);
}

View File

@@ -25,6 +25,9 @@ public class IDFactoryModule extends AbstractModule {
bind(IDAllocator.class).to(BitSetIDAllocator.class)
.in(Scopes.SINGLETON);
// ACCOUNT ID
install(new FactoryModuleBuilder().build(AccountIDFactory.class));
// OBJECT IDS
bind(CharacterIDFactory.class).in(Scopes.SINGLETON);
install(new FactoryModuleBuilder().build(CharacterIDGuiceFactory.class));

View File

@@ -35,7 +35,7 @@ public class CharacterIDFactory implements ObjectIDFactory<CharacterID> {
}
@Override
public CharacterID createID(int id) {
public CharacterID createID(Integer id) {
return factory.create(id);
}

View File

@@ -34,7 +34,7 @@ public class ClanIDFactory implements ObjectIDFactory<ClanID> {
}
@Override
public ClanID createID(int id) {
public ClanID createID(Integer id) {
return factory.create(id);
}

View File

@@ -34,7 +34,7 @@ public class ItemIDFactory implements ObjectIDFactory<ItemID> {
}
@Override
public ItemID createID(int id) {
public ItemID createID(Integer id) {
return factory.create(id);
}

View File

@@ -3,7 +3,8 @@ package com.l2jserver.model.id.object.factory;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.id.factory.IDFactory;
public interface ObjectIDFactory<T extends ObjectID<?>> extends IDFactory<T> {
public interface ObjectIDFactory<T extends ObjectID<?>> extends
IDFactory<Integer, T> {
/**
* Generates a new ID
*

View File

@@ -34,7 +34,7 @@ public class PetIDFactory implements ObjectIDFactory<PetID> {
}
@Override
public PetID createID(int id) {
public PetID createID(Integer id) {
return factory.create(id);
}

View File

@@ -12,5 +12,5 @@ import com.l2jserver.model.id.factory.IDFactory;
* the subclass of {@link TemplateID} that will be createdF
*/
public interface TemplateIDFactory<T extends TemplateID<?>> extends
IDFactory<T> {
IDFactory<Integer, T> {
}