1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-08 08:23:11 +00:00

Event dispatcher changes and packet implementations

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-19 13:08:32 -03:00
parent 2c4af6d91d
commit 2d1181483a
77 changed files with 796 additions and 519 deletions

View File

@@ -33,7 +33,7 @@ public class Calculator implements Function<Double> {
* List of operations in this calculator
*/
private final List<FunctionContainer> functions = CollectionFactory
.newList(null);
.newList();
/**
* Creates a new empty calculator. Functions can be add using

View File

@@ -16,10 +16,7 @@
*/
package com.l2jserver.util.factory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
@@ -27,6 +24,10 @@ import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import javolution.util.FastList;
import javolution.util.FastMap;
import javolution.util.FastSet;
/**
* Factory class to create {@link Collection} instances.
*
@@ -38,12 +39,10 @@ public class CollectionFactory {
*
* @param <T>
* the type
* @param type
* the type
* @return the created list
*/
public static final <T> List<T> newList(Class<T> type) {
return new ArrayList<T>();
public static final <T> List<T> newList() {
return new FastList<T>();
}
/**
@@ -55,8 +54,8 @@ public class CollectionFactory {
* the type
* @return the created set
*/
public static final <T> Set<T> newSet(Class<T> type) {
return new HashSet<T>();
public static final <T> Set<T> newSet() {
return new FastSet<T>();
}
/**
@@ -64,11 +63,9 @@ public class CollectionFactory {
*
* @param <T>
* the type
* @param type
* the type
* @return the created queue
*/
public static final <T> Queue<T> newConcurrentQueue(Class<T> type) {
public static final <T> Queue<T> newConcurrentQueue() {
return new ConcurrentLinkedQueue<T>();
}
@@ -79,14 +76,10 @@ public class CollectionFactory {
* the key type
* @param <V>
* the value type
* @param key
* the key type class
* @param value
* the value type class
* @return the new map
*/
public static final <K, V> Map<K, V> newMap(Class<K> key, Class<V> value) {
return new HashMap<K, V>();
public static final <K, V> Map<K, V> newMap() {
return new FastMap<K, V>();
}
/**
@@ -96,13 +89,9 @@ public class CollectionFactory {
* the key type
* @param <V>
* the value type
* @param key
* the key type class
* @param value
* the value type class
* @return the new map
*/
public static final <K, V> Map<K, V> newWeakMap(Class<K> key, Class<V> value) {
public static final <K, V> Map<K, V> newWeakMap() {
return new WeakHashMap<K, V>();
}
}

View File

@@ -1,59 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.oldcalculator;
import java.util.List;
import com.l2jserver.util.factory.CollectionFactory;
import com.l2jserver.util.oldcalculator.operation.AddOperation;
import com.l2jserver.util.oldcalculator.operation.CalculatorOperation;
import com.l2jserver.util.oldcalculator.operation.SetOperation;
import com.l2jserver.util.oldcalculator.operation.SubtractOperation;
/**
* The formula object does an sequence of steps into calculating something.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Formula {
private List<CalculatorOperation<Integer>> operations = CollectionFactory
.newList(null);
public void addOperation(int order, CalculatorOperation<Integer> operation) {
operations.set(order, operation);
}
public void add(int order, int value) {
addOperation(order, new AddOperation(value));
}
public void subtract(int order, int value) {
addOperation(order, new SubtractOperation(value));
}
public void set(int order, int value) {
addOperation(order, new SetOperation(value));
}
public int calculate() {
int value = 0;
for (CalculatorOperation<Integer> operation : operations) {
value = operation.calculate(value);
}
return value;
}
}

View File

@@ -1,30 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.oldcalculator.operation;
public class AddOperation implements CalculatorOperation<Integer> {
private Integer value;
public AddOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return value + this.value;
}
}

View File

@@ -1,21 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.oldcalculator.operation;
public interface CalculatorOperation<T extends Number> {
T calculate(T value);
}

View File

@@ -1,30 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.oldcalculator.operation;
public class MultiplyOperation implements CalculatorOperation<Integer> {
private Integer value;
public MultiplyOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return value * this.value;
}
}

View File

@@ -1,30 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.oldcalculator.operation;
public class SetOperation implements CalculatorOperation<Integer> {
private Integer value;
public SetOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return this.value;
}
}

View File

@@ -1,30 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.oldcalculator.operation;
public class SubtractOperation implements CalculatorOperation<Integer> {
private Integer value;
public SubtractOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return value - this.value;
}
}