<commit_before>package org.realityforge.replicant.client;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;

/**
 * A class that records the subscriptions to entity graphs.
 */
public class EntitySubscriptionManagerImpl
  implements EntitySubscriptionManager
{
  //Graph => InstanceID
  private final HashMap<Enum, Map<Object, GraphSubscriptionEntry>> _instanceSubscriptions =
    new HashMap<Enum, Map<Object, GraphSubscriptionEntry>>();

  //Graph => Type
  private final HashMap<Enum, GraphSubscriptionEntry> _typeSubscriptions = new HashMap<Enum, GraphSubscriptionEntry>();

  // Entity map: Type => ID
  private final HashMap<Class<?>, Map<Object, EntitySubscriptionEntry>> _entityMapping =
    new HashMap<Class<?>, Map<Object, EntitySubscriptionEntry>>();

  @Nonnull
  private final EntityRepository _repository;

  @Inject
  public EntitySubscriptionManagerImpl( @Nonnull final EntityRepository repository )
  {
    _repository = repository;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  @Nonnull
  public final GraphSubscriptionEntry subscribe( @Nonnull final Enum graph )
    throws IllegalStateException
  {
    GraphSubscriptionEntry typeMap = findSubscription( graph );
    if ( null == typeMap )
    {
      final GraphSubscriptionEntry entry = new GraphSubscriptionEntry( new GraphDescriptor( graph, null ) );
      _typeSubscriptions.put( graph, entry );
      return entry;
    }
    else
    {
      throw new IllegalStateException( "Graph already subscribed: " + graph );
    }
  }

  /**
   * {@inheritDoc}
   */
  @Override
  @Nonnull
  public final GraphSubscriptionEntry subscribe( @Nonnull final Enum graph, @Nonnull final Object id )
  {
    Map<Object, GraphSubscriptionEntry> instanceMap = _instanceSubscriptions.get( graph );
    if ( null == instanceMap )
    {
      instanceMap = new HashMap<Object, GraphSubscriptionEntry>();
      _instanceSubscriptions.put( graph, instanceMap );
    }
    if ( !instanceMap.containsKey( id ) )
    {
      final GraphSubscriptionEntry entry = new GraphSubscriptionEntry( new GraphDescriptor( graph, id ) );
      instanceMap.put( id, entry );
      return entry;
    }
    else
    {
      throw new IllegalStateException( "Graph already subscribed: " + graph + ":" + id );
    }
  }

  /**
   * {@inheritDoc}
   */
  @Override
  @Nullable
  public final GraphSubscriptionEntry findSubscription( @Nonnull final Enum graph )
  {
    return _typeSubscriptions.get( graph );
  }

  /**
   * {@inheritDoc}
   */
  @Override
  @Nullable
  public final GraphSubscriptionEntry findSubscription( @Nonnull final Enum graph, @Nonnull final Object id )
  {
    Map<Object, GraphSubscriptionEntry> instanceMap = _instanceSubscriptions.get( graph );
    if ( null == instanceMap )
    {
      return null;
    }
    else
    {
      return instanceMap.get( id );
    }
  }

  /**
   * {@inheritDoc}
   */
  @Nonnull
  @Override
  public GraphSubscriptionEntry getSubscription( @Nonnull final Enum graph )
    throws IllegalArgumentException
  {
    final GraphSubscriptionEntry subscription = findSubscription( graph );
    if ( null == subscription )
    {
      throw new IllegalStateException( "Graph not subscribed: " + graph );
    }
    return subscription;
  }

  /**
   * {@inheritDoc}
   */
  @Nonnull
  @Override
  public GraphSubscriptionEntry getSubscription( @Nonnull final Enum graph, @Nonnull final Object id )
    throws IllegalArgumentException
  {
    final GraphSubscriptionEntry subscription = findSubscription( graph, id );
    if ( null == subscription )
    {
      throw new IllegalStateException( "Graph not subscribed: " + graph + "/" + id );
    }
    return subscription;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  @Nonnull
  public final void unsubscribe( @Nonnull final Enum graph )
    throws IllegalStateException
  {
    final GraphSubscriptionEntry entry = _typeSubscriptions.remove( graph );
    if ( null == entry )
    {
      throw new IllegalStateException( "Graph not subscribed: " + graph );
    }
    deregisterUnOwnedEntities( entry );
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public final void unsubscribe( @Nonnull final Enum graph, @Nonnull final Object id )
    throws IllegalStateException
  {
    final Map<Object, GraphSubscriptionEntry> instanceMap = _instanceSubscriptions.get( graph );
    if ( null == instanceMap )<commit_msg>Remove nullability annotation on void method<commit_after>package org.realityforge.replicant.client;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;

/**
 * A class that records the subscriptions to entity graphs.
 */
public class EntitySubscriptionManagerImpl
  implements EntitySubscriptionManager
{
  //Graph => InstanceID
  private final HashMap<Enum, Map<Object, GraphSubscriptionEntry>> _instanceSubscriptions =
    new HashMap<Enum, Map<Object, GraphSubscriptionEntry>>();

  //Graph => Type
  private final HashMap<Enum, GraphSubscriptionEntry> _typeSubscriptions = new HashMap<Enum, GraphSubscriptionEntry>();

  // Entity map: Type => ID
  private final HashMap<Class<?>, Map<Object, EntitySubscriptionEntry>> _entityMapping =
    new HashMap<Class<?>, Map<Object, EntitySubscriptionEntry>>();

  @Nonnull
  private final EntityRepository _repository;

  @Inject
  public EntitySubscriptionManagerImpl( @Nonnull final EntityRepository repository )
  {
    _repository = repository;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  @Nonnull
  public final GraphSubscriptionEntry subscribe( @Nonnull final Enum graph )
    throws IllegalStateException
  {
    GraphSubscriptionEntry typeMap = findSubscription( graph );
    if ( null == typeMap )
    {
      final GraphSubscriptionEntry entry = new GraphSubscriptionEntry( new GraphDescriptor( graph, null ) );
      _typeSubscriptions.put( graph, entry );
      return entry;
    }
    else
    {
      throw new IllegalStateException( "Graph already subscribed: " + graph );
    }
  }

  /**
   * {@inheritDoc}
   */
  @Override
  @Nonnull
  public final GraphSubscriptionEntry subscribe( @Nonnull final Enum graph, @Nonnull final Object id )
  {
    Map<Object, GraphSubscriptionEntry> instanceMap = _instanceSubscriptions.get( graph );
    if ( null == instanceMap )
    {
      instanceMap = new HashMap<Object, GraphSubscriptionEntry>();
      _instanceSubscriptions.put( graph, instanceMap );
    }
    if ( !instanceMap.containsKey( id ) )
    {
      final GraphSubscriptionEntry entry = new GraphSubscriptionEntry( new GraphDescriptor( graph, id ) );
      instanceMap.put( id, entry );
      return entry;
    }
    else
    {
      throw new IllegalStateException( "Graph already subscribed: " + graph + ":" + id );
    }
  }

  /**
   * {@inheritDoc}
   */
  @Override
  @Nullable
  public final GraphSubscriptionEntry findSubscription( @Nonnull final Enum graph )
  {
    return _typeSubscriptions.get( graph );
  }

  /**
   * {@inheritDoc}
   */
  @Override
  @Nullable
  public final GraphSubscriptionEntry findSubscription( @Nonnull final Enum graph, @Nonnull final Object id )
  {
    Map<Object, GraphSubscriptionEntry> instanceMap = _instanceSubscriptions.get( graph );
    if ( null == instanceMap )
    {
      return null;
    }
    else
    {
      return instanceMap.get( id );
    }
  }

  /**
   * {@inheritDoc}
   */
  @Nonnull
  @Override
  public GraphSubscriptionEntry getSubscription( @Nonnull final Enum graph )
    throws IllegalArgumentException
  {
    final GraphSubscriptionEntry subscription = findSubscription( graph );
    if ( null == subscription )
    {
      throw new IllegalStateException( "Graph not subscribed: " + graph );
    }
    return subscription;
  }

  /**
   * {@inheritDoc}
   */
  @Nonnull
  @Override
  public GraphSubscriptionEntry getSubscription( @Nonnull final Enum graph, @Nonnull final Object id )
    throws IllegalArgumentException
  {
    final GraphSubscriptionEntry subscription = findSubscription( graph, id );
    if ( null == subscription )
    {
      throw new IllegalStateException( "Graph not subscribed: " + graph + "/" + id );
    }
    return subscription;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public final void unsubscribe( @Nonnull final Enum graph )
    throws IllegalStateException
  {
    final GraphSubscriptionEntry entry = _typeSubscriptions.remove( graph );
    if ( null == entry )
    {
      throw new IllegalStateException( "Graph not subscribed: " + graph );
    }
    deregisterUnOwnedEntities( entry );
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public final void unsubscribe( @Nonnull final Enum graph, @Nonnull final Object id )
    throws IllegalStateException
  {
    final Map<Object, GraphSubscriptionEntry> instanceMap = _instanceSubscriptions.get( graph );
    if ( null == instanceMap )
{'fraction_non_alphanumeric': 0.09612385832033861, 'fraction_numerical': 0.0, 'mean_word_length': 3.4166256763403835, 'pattern_counts': {'":': 2, '<': 35, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '379834', 'n_tokens_mistral': 2427, 'n_tokens_neox': 2473, 'n_words': 680}