removeAll retainAll performance fix in MassiveSet. Added isSynchronous convenience method.
This commit is contained in:
parent
42470b0a2c
commit
87be4f0914
@ -3,7 +3,9 @@ package com.massivecraft.massivecore.collections;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This subclass adds better constructors.
|
||||
@ -52,4 +54,23 @@ public class MassiveSet<E> extends LinkedHashSet<E>
|
||||
this(Arrays.asList(elements));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OPTIMIZE: REMOVE ALL & RETAIN ALL
|
||||
// -------------------------------------------- //
|
||||
// This will greatly reduce the complexity in cases with big sizes.
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c)
|
||||
{
|
||||
if (c instanceof List) c = new HashSet<Object>(c);
|
||||
return super.removeAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c)
|
||||
{
|
||||
if (c instanceof List) c = new HashSet<Object>(c);
|
||||
return super.retainAll(c);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,4 +44,13 @@ public abstract class EventMassiveCore extends Event implements Runnable, Cancel
|
||||
super(isAsync);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean isSynchronous()
|
||||
{
|
||||
return !this.isAsynchronous();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user