<commit_before>package org.aikodi.chameleon.core.declaration;

import org.aikodi.chameleon.core.event.name.NameChanged;
import org.aikodi.chameleon.exception.ChameleonProgrammerException;

/**
 * A class that provides default implementations for declarations.
 * 
 * @author <NAME>
 */
public abstract class BasicDeclaration extends DeclarationImpl {

   public BasicDeclaration(String name) {
      setName(name);
   }

   private String _name;

   @Override
   public String name() {
      return _name;
   }

   private SimpleNameSignature _signature;

   @Override
   public void setName(String name) {
  	 if(name == null) {
  		 throw new IllegalArgumentException("The name of a declaration cannot be null. Only the signature can be null.");
  	 }
      if (_signature != null) {
        _name = name;
         _signature.setName(name);
         // In this case, the signature will send the event.
      } else {
        String old = _name;
        _name = name;
        if(changeNotificationEnabled()) {
          notify(new NameChanged(old, name));
        }
      }
   }

   @Override
   public void setSignature(Signature signature) {
      if (signature instanceof SimpleNameSignature) {
         setName(signature.name());
      } else {
         throw new ChameleonProgrammerException();
      }
   }

   @Override
   public SimpleNameSignature signature() {
      if (_signature == null) {
         synchronized (this) {
            if (_signature == null) {
               _signature = new SimpleNameSignature(_name) {
                  @Override
                  public void setName(String name) {
                     super.setName(name);
                     BasicDeclaration.this._name = name;
                  }
               };
            }
            _signature.setUniParent(this);
         }
      }
      return _signature;
   }

}<commit_msg>Use a Single for the signature!<commit_after>package org.aikodi.chameleon.core.declaration;

import org.aikodi.chameleon.exception.ChameleonProgrammerException;
import org.aikodi.chameleon.util.association.Single;

/**
 * A class that provides default implementations for declarations.
 * 
 * @author <NAME>
 */
public abstract class BasicDeclaration extends DeclarationImpl {

   public BasicDeclaration(String name) {
      setSignature(new SimpleNameSignature(name));
   }
   
   protected BasicDeclaration() {
     
   }

//   private String _name;

//   @Override
//   public String name() {
//      return _name;
//   }

   private Single<Signature> _signature = new Single<>(this);

//   @Override
//   public void setName(String name) {
//  	 if(name == null) {
//  		 throw new IllegalArgumentException("The name of a declaration cannot be null. Only the signature can be null.");
//  	 }
//      if (_signature != null) {
//        _name = name;
//         _signature.setName(name);
//         // In this case, the signature will send the event.
//      } else {
//        String old = _name;
//        _name = name;
//        if(changeNotificationEnabled()) {
//          notify(new NameChanged(old, name));
//        }
//      }
//   }

   @Override
   public void setSignature(Signature signature) {
      set(_signature, signature);
   }
   
   @Override
  public Signature signature() {
    return _signature.getOtherEnd();
  }

//   @Override
//   public SimpleNameSignature signature() {
//      if (_signature.getOtherEnd() == null) {
//         synchronized (this) {
//            if (_signature == null) {
//               set(_signature,new SimpleNameSignature(_name) {
//                  @Override
//                  public void setName(String name) {
//                     super.setName(name);
//                     BasicDeclaration.this._name = name;
//                  }
//               });
//            }
//            _signature.setUniParent(this);
//         }
//      }
//      return _signature;
//   }

}
{'fraction_non_alphanumeric': 0.10935104752171691, 'fraction_numerical': 0.0, 'mean_word_length': 1.9885496183206106, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7320345', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1053, 'n_words': 262}