1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-08 08:23:11 +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> {
}

View File

@@ -2,6 +2,7 @@ package com.l2jserver.model.world;
import java.sql.Date;
import com.l2jserver.model.id.AccountID;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.ClanID;
import com.l2jserver.model.id.object.PetID;
@@ -19,6 +20,10 @@ import com.l2jserver.model.world.character.CharacterInventory;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class L2Character extends Player {
/**
* The account id
*/
private AccountID accountID;
/**
* The clan id
*/
@@ -76,9 +81,19 @@ public class L2Character extends Player {
this.attributes = new CharacterCalculatedAttributes(this);
}
@Override
public CharacterID getID() {
return (CharacterID) super.getID();
/**
* @return the account ID
*/
public AccountID getAccountID() {
return accountID;
}
/**
* @param accountID
* the account ID to set
*/
public void setAccountID(AccountID accountID) {
this.accountID = accountID;
}
/**
@@ -223,4 +238,9 @@ public class L2Character extends Player {
public CharacterFriendList getFriendList() {
return friendList;
}
@Override
public CharacterID getID() {
return (CharacterID) super.getID();
}
}

View File

@@ -1,6 +1,6 @@
package com.l2jserver.model.world.filter.impl;
import com.l2jserver.model.id.ID;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.capability.Positionable;
import com.l2jserver.model.world.filter.WorldObjectFilter;
@@ -13,7 +13,7 @@ public class IDFilter implements WorldObjectFilter<Positionable> {
/**
* The object id
*/
private final ID id;
private final ObjectID<?> id;
/**
* Creates a new instance
@@ -21,7 +21,7 @@ public class IDFilter implements WorldObjectFilter<Positionable> {
* @param id
* the desired object ID
*/
public IDFilter(final ID id) {
public IDFilter(final ObjectID<?> id) {
this.id = id;
}