import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
import java.nio.file.Path;
import java.text.*;
import java.text.NumberFormat;
import java.nio.charset.Charset;
import java.util.TimeZone;
import java.text.SimpleDateFormat;
class main {
static void test_replaceConceptAndUpdateRefs() {
Concepts cc = new Concepts();
Concept a = cnew(cc, "A");
Concept b = cnew(cc, "B");
Concept a2 = unlisted("A");
cset(b, "a", a);
print("a", a);
print("b", b);
long id = a.id;
replaceConceptAndUpdateRefs(a, a2);
print("a2", a2);
print("b", b);
assertSame(cc, a2.concepts());
assertEquals(id, a2.id);
assertEquals(allBackRefs(a2), ll(b));
}
static Concept cnew(String name, Object... values) {
return cnew(db_mainConcepts(), name, values);
}
static Concept cnew(Concepts concepts, String name, Object... values) {
Class extends Concept> cc = findClass(name);
concepts_unlisted.set(true);
Concept c;
try {
c = cc != null ? nuObject(cc) : new Concept(name);
} finally {
concepts_unlisted.set(null);
}
concepts.register(c);
csetAll(c, values);
return c;
}
static A cnew(Class cc, Object... values) {
return cnew(db_mainConcepts(), cc, values);
}
static A cnew(Concepts concepts, Class cc, Object... values) {
concepts_unlisted.set(true);
A c;
try {
c = nuObject(cc);
} finally {
concepts_unlisted.set(null);
}
concepts.register(c);
csetAll(c, values);
return c;
}
// make concept instance that is not connected to DB
static A unlisted(Class c, Object... args) {
concepts_unlisted.set(true);
try {
return nuObject(c, args);
} finally {
concepts_unlisted.set(null);
}
}
static Concept unlisted(String name, Object... args) {
Class extends Concept> cc = findClass(name);
concepts_unlisted.set(true);
try {
return cc != null ? nuObject(cc) : new Concept(name);
} finally {
concepts_unlisted.set(null);
}
}
// returns number of changes
static int cset(Concept c, Object... values) { try {
if (c == null) return 0;
warnIfOddCount(values = expandParams(c.getClass(), values));
int changes = 0;
for (int i = 0; i+1 < l(values); i += 2)
if (_csetField(c, (String) values[i], values[i+1])) ++changes;
return changes;
} catch (Exception __e) { throw rethrow(__e); } }
static int cset(Iterable extends Concept> l, Object... values) {
int changes = 0;
for (Concept c : unnull(l))
changes += cset(c, values);
return changes;
}
static int cset(Concept.Ref c, Object... values) {
return cset(getVar(c), values);
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal