2014-10-21 21:59:00 +02:00
package com.pahimar.ee3.array ;
import com.google.common.collect.ImmutableSortedSet ;
2015-05-07 19:45:06 +02:00
import com.pahimar.ee3.api.array.AlchemyArray ;
2015-05-07 21:11:23 +02:00
import com.pahimar.ee3.util.LoaderHelper ;
import com.pahimar.ee3.util.LogHelper ;
import cpw.mods.fml.common.Loader ;
2015-11-19 21:24:40 +01:00
import org.apache.logging.log4j.Marker ;
import org.apache.logging.log4j.MarkerManager ;
2014-10-21 21:59:00 +02:00
import java.util.SortedSet ;
import java.util.TreeSet ;
public class AlchemyArrayRegistry
{
2015-11-19 21:24:40 +01:00
public static final Marker ALCHEMY_ARRAY_MARKER = MarkerManager . getMarker ( " EE3_ALCHEMY_ARRAY " , LogHelper . MOD_MARKER ) ;
2014-10-21 21:59:00 +02:00
private static AlchemyArrayRegistry alchemyArrayRegistry = null ;
private SortedSet < AlchemyArray > registeredAlchemyArrays ;
private AlchemyArrayRegistry ( )
{
}
public static AlchemyArrayRegistry getInstance ( )
{
if ( alchemyArrayRegistry = = null )
{
alchemyArrayRegistry = new AlchemyArrayRegistry ( ) ;
alchemyArrayRegistry . init ( ) ;
}
return alchemyArrayRegistry ;
}
private void init ( )
{
registeredAlchemyArrays = new TreeSet < AlchemyArray > ( ) ;
}
2015-02-25 06:03:59 +01:00
public AlchemyArray getAlchemyArray ( int index )
{
if ( registeredAlchemyArrays ! = null )
{
AlchemyArray [ ] alchemyArrays = new AlchemyArray [ 0 ] ;
alchemyArrays = registeredAlchemyArrays . toArray ( alchemyArrays ) ;
if ( index < alchemyArrays . length )
{
return alchemyArrays [ index ] ;
}
}
return null ;
}
2014-10-21 21:59:00 +02:00
public SortedSet < AlchemyArray > getRegisteredAlchemyArrays ( )
{
return ImmutableSortedSet . copyOf ( registeredAlchemyArrays ) ;
}
public boolean registerAlchemyArray ( AlchemyArray alchemyArray )
{
if ( ! registeredAlchemyArrays . contains ( alchemyArray ) )
{
2015-11-19 21:24:40 +01:00
LogHelper . trace ( ALCHEMY_ARRAY_MARKER , " [{}]: Mod with ID '{}' added alchemy array {} " , LoaderHelper . getLoaderState ( ) , Loader . instance ( ) . activeModContainer ( ) . getModId ( ) , alchemyArray ) ;
2014-10-21 21:59:00 +02:00
return registeredAlchemyArrays . add ( alchemyArray ) ;
}
return false ;
}
}