// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/data/Terms.java
// public static TermVar newVar(final String name) {
//   return new TermVar(name);
// }
// 
// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/exceptions/ProlInstantiationErrorException.java
// public class ProlInstantiationErrorException extends ProlAbstractCatcheableException {
// 
//   private static final long serialVersionUID = -5157739502740121566L;
// 
//   private static final Term TERM_ERROR = newAtom("instantiation_error");
// 
//   public ProlInstantiationErrorException(final Term culprit, final Throwable cause) {
//     super(culprit, cause);
//   }
// 
//   public ProlInstantiationErrorException(final String message, final Term culprit,
//                                          final Throwable cause) {
//     super(message, culprit, cause);
//   }
// 
//   public ProlInstantiationErrorException(final String message, final Term culprit) {
//     super(message, culprit);
//   }
// 
//   public ProlInstantiationErrorException(final Term culprit) {
//     super(culprit);
//   }
// 
// 
//   @Override
//   public Term getErrorTerm() {
//     return TERM_ERROR;
//   }
// 
//   @Override
//   public TermStruct getAsStruct() {
//     return this.makeErrorStruct(TERM_ERROR, this.getCulprit());
//   }
// }


import static com.igormaznitsa.jprol.data.TermType.VAR;
import static com.igormaznitsa.jprol.data.Terms.newVar;
import com.igormaznitsa.jprol.exceptions.ProlInstantiationErrorException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
/*
 * Copyright 2014 Igor Maznitsa (http://www.igormaznitsa.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.igormaznitsa.jprol.data;




public final class TermVar extends Term {

  private static final AtomicInteger ANONYM_GENERATOR = new AtomicInteger(0);
  private static final AtomicInteger UID_GENERATOR = new AtomicInteger(0);
  private final int uid;
  private final boolean anonymous;
  private volatile Term value;

  private TermVar(final String name, final boolean anonymous) {
    super(name);
    this.uid = UID_GENERATOR.incrementAndGet();
    this.anonymous = anonymous;
  }

  TermVar(final String name) {
    this(name, false);
  }

  TermVar() {
    this("_$" + Long.toHexString(ANONYM_GENERATOR.incrementAndGet()), true);
  }

  public final int getVarUid() {
    return this.uid;
  }

  @Override
  public TermType getTermType() {
    return VAR;
  }

  @Override
  public Term makeClone() {
    final Term value = this.getThisValue();
// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/data/Terms.java
// public static TermVar newVar(final String name) {
//   return new TermVar(name);
// }
// 
// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/exceptions/ProlInstantiationErrorException.java
// public class ProlInstantiationErrorException extends ProlAbstractCatcheableException {
// 
//   private static final long serialVersionUID = -5157739502740121566L;
// 
//   private static final Term TERM_ERROR = newAtom("instantiation_error");
// 
//   public ProlInstantiationErrorException(final Term culprit, final Throwable cause) {
//     super(culprit, cause);
//   }
// 
//   public ProlInstantiationErrorException(final String message, final Term culprit,
//                                          final Throwable cause) {
//     super(message, culprit, cause);
//   }
// 
//   public ProlInstantiationErrorException(final String message, final Term culprit) {
//     super(message, culprit);
//   }
// 
//   public ProlInstantiationErrorException(final Term culprit) {
//     super(culprit);
//   }
// 
// 
//   @Override
//   public Term getErrorTerm() {
//     return TERM_ERROR;
//   }
// 
//   @Override
//   public TermStruct getAsStruct() {
//     return this.makeErrorStruct(TERM_ERROR, this.getCulprit());
//   }
// }


// Path: engine/jprol-core/src/main/java/com/igormaznitsa/jprol/data/TermVar.java
import static com.igormaznitsa.jprol.data.TermType.VAR;
import static com.igormaznitsa.jprol.data.Terms.newVar;
import com.igormaznitsa.jprol.exceptions.ProlInstantiationErrorException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

/*
 * Copyright 2014 Igor Maznitsa (http://www.igormaznitsa.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.igormaznitsa.jprol.data;




public final class TermVar extends Term {

  private static final AtomicInteger ANONYM_GENERATOR = new AtomicInteger(0);
  private static final AtomicInteger UID_GENERATOR = new AtomicInteger(0);
  private final int uid;
  private final boolean anonymous;
  private volatile Term value;

  private TermVar(final String name, final boolean anonymous) {
    super(name);
    this.uid = UID_GENERATOR.incrementAndGet();
    this.anonymous = anonymous;
  }

  TermVar(final String name) {
    this(name, false);
  }

  TermVar() {
    this("_$" + Long.toHexString(ANONYM_GENERATOR.incrementAndGet()), true);
  }

  public final int getVarUid() {
    return this.uid;
  }

  @Override
  public TermType getTermType() {
    return VAR;
  }

  @Override
  public Term makeClone() {
    final Term value = this.getThisValue();
    TermVar result = this.isAnonymous() ? newVar() : newVar(this.getText());