Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,29 @@
public class HistoryVariable
{
private Object value;
public HistoryVariable(Object v)
{
value = v;
}
public void update(Object v)
{
value = v;
}
public Object undo()
{
return value;
}
@Override
public String toString()
{
return value.toString();
}
public void dispose()
{
}
}

View file

@ -0,0 +1,43 @@
import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
public privileged aspect HistoryHandling
{
before() : execution(HistoryVariable.new(..))
{
history.put((HistoryVariable) thisJoinPoint.getTarget(), new LinkedList<>());
}
after() : execution(void HistoryVariable.dispose())
{
history.remove(thisJoinPoint.getTarget());
}
before(Object v) : execution(void HistoryVariable.update(Object)) && args(v)
{
final HistoryVariable hv = (HistoryVariable) thisJoinPoint.getThis();
history.get(hv).add(hv.value);
}
after() : execution(Object HistoryVariable.undo())
{
final HistoryVariable hv = (HistoryVariable) thisJoinPoint.getThis();
final Deque<Object> q = history.get(hv);
if (!q.isEmpty())
hv.value = q.pollLast();
}
String around() : this(HistoryVariable) && execution(String toString())
{
final HistoryVariable hv = (HistoryVariable) thisJoinPoint.getThis();
final Deque<Object> q = history.get(hv);
if (q == null)
return "<disposed>";
else
return "current: "+ hv.value + ", previous: " + q.toString();
}
private Map<HistoryVariable, Deque<Object>> history = new HashMap<>();
}

View file

@ -0,0 +1,17 @@
public final class Main
{
public static void main(final String[] args)
{
HistoryVariable hv = new HistoryVariable("a");
hv.update(90);
hv.update(12.1D);
System.out.println(hv.toString());
System.out.println(hv.undo());
System.out.println(hv.undo());
System.out.println(hv.undo());
System.out.println(hv.undo());
System.out.println(hv.toString());
hv.dispose();
System.out.println(hv.toString());
}
}