org.chocosolver.memory.IState_E_.template Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of choco-solver Show documentation
Show all versions of choco-solver Show documentation
Open-source constraint solver.
/**
* This file is part of choco-solver, http://choco-solver.org/
*
* Copyright (c) 2019, IMT Atlantique. All rights reserved.
*
* Licensed under the BSD 4-clause license.
*
* See LICENSE file in the project root for full license information.
*/
package org.chocosolver.memory;
/**
* An abstract class for backtrackable #e#.
*
*
* @author Charles Prud'homme
* @since 29/04/13
*/
public abstract class IState#E# {
protected final IEnvironment environment;
protected #e# currentValue;
protected int timeStamp;
public IState#E#(IEnvironment env, #e# i) {
environment = env;
currentValue = i;
timeStamp = environment.getWorldIndex();
}
/**
* Returns the current value.
*/
public final #e# get() {
return currentValue;
}
/**
* Modifies the value and stores if needed the former value on the
* trailing stack.
*/
public abstract void set(#e# y);
/**
* modifying a StoredInt by an increment
*
* @param delta increment value
* @return the new value
*/
public final #e# add(#e# delta) {
#e# res = currentValue + delta;
set(res);
return res;
}
/**
* Modifies the value without storing the former value on the trailing stack.
*
* @param y the new value
* @param wstamp the stamp of the world in which the update is performed
*/
public void _set(final #e# y, final int wstamp) {
currentValue = y;
timeStamp = wstamp;
}
/**
* Make a deep copy of this.
*
* @return a #e#
*/
public final #e# deepCopy() {
return currentValue;
}
public int getTimeStamp() {
return timeStamp;
}
public void overrideTimeStamp(int aTimeStamp) {
this.timeStamp = aTimeStamp;
}
/**
* Retrieving the environment
*/
public IEnvironment getEnvironment() {
return environment;
}
@Override
public String toString() {
return String.valueOf(currentValue);
}
}