removeAll retainAll performance fix in MassiveSet. Added isSynchronous convenience method.

This commit is contained in:
Olof Larsson 2015-08-22 13:31:48 +02:00
parent 42470b0a2c
commit 87be4f0914
2 changed files with 30 additions and 0 deletions

View File

@ -3,7 +3,9 @@ package com.massivecraft.massivecore.collections;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List;
/** /**
* This subclass adds better constructors. * This subclass adds better constructors.
@ -51,5 +53,24 @@ public class MassiveSet<E> extends LinkedHashSet<E>
{ {
this(Arrays.asList(elements)); 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);
}
} }

View File

@ -44,4 +44,13 @@ public abstract class EventMassiveCore extends Event implements Runnable, Cancel
super(isAsync); super(isAsync);
} }
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
public boolean isSynchronous()
{
return !this.isAsynchronous();
}
} }