mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-11 09:42:54 +00:00
21
src/main/java/com/l2jserver/model/id/AccountID.java
Normal file
21
src/main/java/com/l2jserver/model/id/AccountID.java
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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> {
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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> {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user