// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.component;

import javax.annotation.Nullable;
import com.hypixel.hytale.component.dependency.Dependency;
import java.util.Set;
import javax.annotation.Nonnull;

public class SystemGroup<ECS_TYPE> implements Comparable<SystemGroup<ECS_TYPE>>
{
    @Nonnull
    private final ComponentRegistry<ECS_TYPE> registry;
    private final int index;
    @Nonnull
    private final Set<Dependency<ECS_TYPE>> dependencies;
    private boolean invalidated;
    
    SystemGroup(@Nonnull final ComponentRegistry<ECS_TYPE> registry, final int index, @Nonnull final Set<Dependency<ECS_TYPE>> dependencies) {
        this.registry = registry;
        this.index = index;
        this.dependencies = dependencies;
    }
    
    @Nonnull
    public ComponentRegistry<ECS_TYPE> getRegistry() {
        return this.registry;
    }
    
    @Nonnull
    public Set<Dependency<ECS_TYPE>> getDependencies() {
        return this.dependencies;
    }
    
    public int getIndex() {
        return this.index;
    }
    
    public void validateRegistry(@Nonnull final ComponentRegistry<ECS_TYPE> registry) {
        if (!this.registry.equals(registry)) {
            throw new IllegalArgumentException("SystemGroup is for a different registry! " + String.valueOf(this));
        }
    }
    
    public void validate() {
        if (this.invalidated) {
            throw new IllegalStateException("SystemGroup is invalid!");
        }
    }
    
    void invalidate() {
        this.invalidated = true;
    }
    
    boolean isValid() {
        return !this.invalidated;
    }
    
    @Override
    public int compareTo(@Nonnull final SystemGroup<ECS_TYPE> o) {
        return Integer.compare(this.index, o.getIndex());
    }
    
    @Override
    public boolean equals(@Nullable final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final SystemGroup<?> that = (SystemGroup<?>)o;
        return this.index == that.index && this.registry.equals(that.registry);
    }
    
    @Override
    public int hashCode() {
        int result = this.registry.hashCode();
        result = 31 * result + this.index;
        return result;
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "SystemGroup{registry=" + String.valueOf(this.registry.getClass()) + "@" + this.registry.hashCode() + ", index=" + this.index;
    }
}
