All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.core.Blank Maven / Gradle / Ivy


package org.snapscript.core;

import java.util.concurrent.atomic.AtomicReference;

public class Blank extends Value {
   
   private final AtomicReference reference;
   private final Type type;
   private final int modifiers;
   
   public Blank(Object value, Type type, int modifiers) {
      this.reference = new AtomicReference(value);
      this.modifiers = modifiers;
      this.type = type;
   }
   
   @Override
   public boolean isProperty() {
      return modifiers != -1;
   }
   
   @Override
   public int getModifiers() {
      return modifiers;
   }
   
   @Override
   public Type getConstraint() {
      return type;
   }
   
   @Override
   public  T getValue() {
      return (T)reference.get();
   }
   
   @Override
   public void setValue(Object value){
      if(!reference.compareAndSet(null, value)) {
         throw new InternalStateException("Illegal modification of constant");
      }
   } 
   
   @Override
   public String toString() {
      return String.valueOf(reference);
   }
}