Addition of synchronized addIfAbsent method.

This commit is contained in:
MobiusDevelopment 2020-09-05 10:14:45 +00:00
parent 0ec7e382dd
commit fd163e46c4
38 changed files with 361 additions and 95 deletions

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -41,7 +41,7 @@ public class WorldRegion
{
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
private WorldRegion[] _surroundingRegions;
private final int _regionX;
private final int _regionY;
@ -313,10 +313,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -41,7 +41,7 @@ public class WorldRegion
{
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
private WorldRegion[] _surroundingRegions;
private final int _regionX;
private final int _regionY;
@ -313,10 +313,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).

View File

@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.util.UnboundArrayList;
public class WorldRegion
{
/** List containing visible objects in this world region. */
private final List<WorldObject> _visibleObjects = new UnboundArrayList<>();
private final UnboundArrayList<WorldObject> _visibleObjects = new UnboundArrayList<>();
/** Array containing nearby regions forming this world region's effective area. */
private WorldRegion[] _surroundingRegions;
private final int _regionX;
@ -228,10 +228,7 @@ public class WorldRegion
return;
}
if (!_visibleObjects.contains(object))
{
_visibleObjects.add(object);
}
_visibleObjects.addIfAbsent(object);
// If this is the first player to enter the region, activate self and neighbors.
if (object.isPlayable() && !_active && !Config.GRIDS_ALWAYS_ON)

View File

@ -123,6 +123,23 @@ public class UnboundArrayList<E>extends ArrayList<E>
}
}
/**
* Appends the specified element to the end of this list if this list does not contain the specified element.
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
public boolean addIfAbsent(E e)
{
synchronized (this)
{
if (!contains(e))
{
return super.add(e);
}
return false;
}
}
/**
* Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that {@code Objects.equals(o, get(i))} (if such an element exists).
* Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).