id
stringlengths 36
36
| text
stringlengths 1
1.25M
|
---|---|
fe2aefab-e14b-4070-a4c2-77b591cb31fe
|
@Override
protected EntityManager getEntityManager() {
return em;
}
|
0966b42d-9a1e-45e7-a19f-589c3cd0c6d9
|
public OrganizationFacade() {
super(Organization.class);
}
|
7ca9eb19-b899-418c-85e4-988498fe8f7d
|
public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}
|
76c99975-86a7-4c31-9b89-d0da8859beb5
|
protected abstract EntityManager getEntityManager();
|
e3e1647a-bd6a-45cf-99ab-dbfa6ea7c876
|
public void create(T entity) {
getEntityManager().persist(entity);
}
|
2ae951d6-aca9-40c7-bece-47c0225c605b
|
public void edit(T entity) {
getEntityManager().merge(entity);
}
|
2357ea9a-bd56-4c20-9d6f-fbdfdf48c52c
|
public void remove(T entity) {
getEntityManager().remove(getEntityManager().merge(entity));
}
|
cac12167-11a5-4700-a795-2a7e7eb324f0
|
public T find(Object id) {
return getEntityManager().find(entityClass, id);
}
|
70142295-8c9d-4538-a147-6494c0becc0b
|
public List<T> findAll() {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
}
|
62713c2c-08a1-4b6c-9447-e10b42efa98c
|
public List<T> findRange(int[] range) {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(entityClass));
javax.persistence.Query q = getEntityManager().createQuery(cq);
q.setMaxResults(range[1] - range[0]);
q.setFirstResult(range[0]);
return q.getResultList();
}
|
21831c80-2fe0-4800-bbc6-44e537a77358
|
public int count() {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
cq.select(getEntityManager().getCriteriaBuilder().count(rt));
javax.persistence.Query q = getEntityManager().createQuery(cq);
return ((Long) q.getSingleResult()).intValue();
}
|
2b215a2d-4fa1-4adc-b2a3-7286fad89f26
|
public static int powInt(int base,int expo) {
assert base > 0 && expo >= 0;
int result = 1;
for(;expo>0;expo--)
result *= base;
return result;
}
|
4b6c78a8-14c9-4d0d-b908-c38b8fc3f2b9
|
public static int reverseDigit(int size,int base,int number) {
assert number <= powInt(base,size);
int result = 0;
for(;size>0;size--) {
result = result*base + number%base;
number /= base;
}
return result;
}
|
d5494fd7-f591-4523-8b73-09f2d2424778
|
public static int numVarInPattern(int size,int pattern) {
int n = 0;
for(;size>0;size--,pattern/=3)
if(pattern%3 != 2)
n++;
return n;
}
|
61d3413b-0a34-4a32-b8ca-fd0f51b441a6
|
protected static void updateLabel(int numVar,int pattern,int prefix,int update) {
if(numVar == 0) {
numLayer[reverseDigit(totalVar,2,prefix)] += update;
return;
}
if(pattern%3 == 0 || pattern%3 == 2)
updateLabel(numVar-1,pattern/3,prefix*2+0,update);
if(pattern%3 == 1 || pattern%3 == 2)
updateLabel(numVar-1,pattern/3,prefix*2+1,update);
}
|
2b951648-b6d0-40c8-8e85-dd17077c9174
|
protected static boolean groupable(int numVar,int pattern,int prefix) {
if(numVar == 0) {
switch(kmap[reverseDigit(totalVar,2,prefix)]) {
case F: return !isMinterm;
case T: return isMinterm;
case X: return true;
}
}
switch(pattern%3) {
case 0: return groupable(numVar-1,pattern/3,prefix*2+0);
case 1: return groupable(numVar-1,pattern/3,prefix*2+1);
default:if(!groupable(numVar-1,pattern/3,prefix*2+0))
return false;
return groupable(numVar-1,pattern/3,prefix*2+1);
}
}
|
9b2f4d6b-5cad-49be-959b-12d03828268d
|
protected static boolean deletable(int numVar,int pattern,int prefix) {
if(numVar == 0) {
int curPosition = reverseDigit(totalVar,2,prefix);
if(kmap[curPosition] == boolx.X)
return numLayer[curPosition] > 0;
return numLayer[curPosition] > 1;
}
switch(pattern%3) {
case 0: return deletable(numVar-1,pattern/3,prefix*2+0);
case 1: return deletable(numVar-1,pattern/3,prefix*2+1);
default:if(!deletable(numVar-1,pattern/3,prefix*2+0))
return false;
return deletable(numVar-1,pattern/3,prefix*2+1);
}
}
|
666a98af-d007-452b-a71b-44d52feb2acd
|
public static int grade(int totalVar,boolx[] kmap,boolean isMinterm) {
assert kmap.length == powInt(2,totalVar);
int cost = 0;
boolean[] groupAbility = new boolean[powInt(3,totalVar)];
KarnaughMapGrader.totalVar = totalVar;
KarnaughMapGrader.kmap = kmap;
KarnaughMapGrader.isMinterm = isMinterm;
numLayer = new int[kmap.length];
for(int pattern=0;pattern<powInt(3,totalVar);pattern++)
if(groupAbility[pattern] = groupable(totalVar,pattern,0))
updateLabel(totalVar,pattern,0,1);
for(int numVar=totalVar;numVar>=0;numVar--)
for(int pattern=0;pattern<powInt(3,totalVar);pattern++) {
if(!groupAbility[pattern]);
else if(numVarInPattern(totalVar,pattern) != numVar);
else if(deletable(totalVar,pattern,0))
updateLabel(totalVar,pattern,0,-1);
else
cost += numVar;
}
return cost;
}
|
2947800e-8d30-49d3-9618-257f68e57955
|
protected int numberOfPermutation(int n, int r) {
int result = 1;
for (int i = 0; i < r; i++)
result *= n - i;
return result;
}
|
aa8289e3-88de-4f8c-97d3-a2e19b929f53
|
public Permutation(int n, int r) {
assert 0 < r && r <= n : "cannot find nPr.";
this.n = n;
this.r = r;
this.total = numberOfPermutation(n, r);
this.pattern = new int[r];
free = new boolean[n];
reset();
}
|
6ad82a7d-76c2-4f24-89f4-d80c18c3ca5e
|
protected void reset() {
for (int i = 0; i < r; i++)
pattern[i] = i;
for (int i = 0; i < n; i++)
free[i] = i >= r;
}
|
bb762632-d734-4156-ad68-6a0bf34c3ef6
|
protected void next() {
int p = r - 1; // pointer to current the current index of patten.
free[pattern[p]] = true;
int i = pattern[p] + 1;
while (p < r) {
for (; i < n; i++)
if (free[i])
break;
if (i < n) {
pattern[p] = i;
free[i] = false;
p++;
i = 0;
} else {
free[pattern[p]] = true;
p--;
if (p == -1) {
reset();
return;
}
free[pattern[p]] = true;
i = pattern[p] + 1;
}
}
}
|
6a36b94a-96cd-4fef-bb57-fc335bfc99d8
|
public int log2(int n) {
int i;
for(i=0;(1<<i)<n;i++);
return i;
}
|
fdef36b8-a8a5-4a19-9971-d06fe22b0954
|
public StateToKarnaughMap(int[][] idealStateDiagram,
int argSize,int kmapsSize,int[] h){
// Pre: argSize and idealStateDiagram.length must be multiple of two
assert argSize == h.length;
for(int i=0;i<idealStateDiagram.length;i++)
assert idealStateDiagram[i].length == argSize;
this.h = h.clone();
stateDiagram = new int[idealStateDiagram.length][];
for(int i=0;i<idealStateDiagram.length;i++) {
if(h[i] == -1)
continue;
stateDiagram[h[i]] = new int[idealStateDiagram[i].length];
for(int j=0;j<idealStateDiagram[i].length;j++)
stateDiagram[h[i]][j] = h[idealStateDiagram[i][j]];
}
score = 0;
isMinterm = new boolean[kmapsSize];
kmaps = new boolx[kmapsSize][];
int numVar = log2(argSize*stateDiagram.length);
int[][] sd = new int[stateDiagram.length][];
for(int i=0;i<sd.length;i++)
if(stateDiagram[i] != null)
sd[i] = stateDiagram[i].clone();
for(int k=0;k<kmapsSize;k++) {
kmaps[k] = new boolx[argSize*sd.length];
for(int j=0;j<argSize;j++)
for(int i=0;i<sd.length;i++) {
if(sd[i] == null) {
kmaps[k][j*sd.length+i] = boolx.X;
continue;
}
if(sd[i][j]%2 == 1)
kmaps[k][j*sd.length+i] = boolx.T;
else
kmaps[k][j*sd.length+i] = boolx.F;
sd[i][j] >>= 1;
}
int maxterm = KarnaughMapGrader.grade(numVar, kmaps[k], false);
int minterm = KarnaughMapGrader.grade(numVar, kmaps[k], true);
isMinterm[k] = minterm <= maxterm;
if(minterm <= maxterm)
score += minterm;
else
score += maxterm;
}
}
|
7f6dcd0a-1787-4aee-a231-6600f6af8966
|
public int compareTo(StateToKarnaughMap compState) {
return this.score - compState.score;
}
|
9f8261e8-b928-4b2d-aedf-2bc4ad78a1b9
|
public static void main(String[] args) throws IOException {
/*boolx[] kmap = { boolx.F,boolx.F,boolx.T,boolx.F
, boolx.T,boolx.T,boolx.T,boolx.F
, boolx.F,boolx.T,boolx.T,boolx.T
, boolx.F,boolx.T,boolx.F,boolx.F
};
Utility.rep4varKmap(kmap);
System.out.println(KarnaughMapGrader.grade(4, kmap, true));
if(true)
return;*/
BufferedReader br = new BufferedReader (
new InputStreamReader(System.in));
System.out.print("Type your id number : ");
int idNum = Integer.parseInt(br.readLine())%30+1;
System.out.print("How many kmap do you want to see (-1 for just the best(s) ) : ");
int numShowedState = Integer.parseInt(br.readLine());
Permutation perm = new Permutation(8,7);
assert perm.total >= numShowedState
: "numShowedState exceed perm.total";
// hareware coursework II ideal state diagram no. 25
int[][] hwcw2isd = new int[8][2];
for(int i=4;i>=0;i--) {
if(idNum%2 == 1) {
hwcw2isd[i][0] = 7;
hwcw2isd[i][1] = (i==4) ? 6 : i+1;
} else {
hwcw2isd[i][0] = (i==4) ? 6 : i+1;
hwcw2isd[i][1] = 7;
}
idNum >>= 1;
}
/*hwcw2isd25[0][0] = 7; hwcw2isd25[0][1] = 1; // reset
hwcw2isd25[1][0] = 7; hwcw2isd25[1][1] = 2; // s1
hwcw2isd25[2][0] = 3; hwcw2isd25[2][1] = 7; // s2
hwcw2isd25[3][0] = 4; hwcw2isd25[3][1] = 7; // s3
hwcw2isd25[4][0] = 7; hwcw2isd25[4][1] = 6; // s4*/
hwcw2isd[5] = null; // unused state
hwcw2isd[6][0] = 0; hwcw2isd[6][1] = 6; // open
hwcw2isd[7][0] = 7; hwcw2isd[7][1] = 7; // alarm
int[] assignment = new int[8];
StateToKarnaughMap[] states = new StateToKarnaughMap[perm.total];
for(int i=0;i<states.length;i++) {
hwcw2UpdateAssignment(assignment,perm);
states[i] = new StateToKarnaughMap(hwcw2isd,2,3,assignment);
perm.next();
}
Arrays.sort(states);
if(numShowedState >= 0) {
for(int i=0;i<numShowedState;i++)
hwcw2PrintState(states[i]);
} else {
for(int i=0;i<states.length;i++)
if(states[i].score == states[0].score)
hwcw2PrintState(states[i]);
}
}
|
46adbafb-51a5-4bc7-a26b-de74761d7413
|
public static void hwcw2UpdateAssignment(int[] assignment,Permutation perm) {
assignment[0] = perm.pattern[0];
assignment[1] = perm.pattern[1];
assignment[2] = perm.pattern[2];
assignment[3] = perm.pattern[3];
assignment[4] = perm.pattern[4];
assignment[5] = -1;
assignment[6] = perm.pattern[5];
assignment[7] = perm.pattern[6];
}
|
17661b10-691f-4a97-a344-fa3b55fd3cce
|
public static void hwcw2PrintState(StateToKarnaughMap state) {
System.out.println(state.score+" "+Arrays.toString(state.isMinterm));
System.out.println(Arrays.toString(state.h));
Utility.rep4varKmap(state.kmaps[0]);
Utility.rep4varKmap(state.kmaps[1]);
Utility.rep4varKmap(state.kmaps[2]);
Utility.printBoolxtables(4,4,state.kmaps);
Utility.rep4varKmap(state.kmaps[0]);
Utility.rep4varKmap(state.kmaps[1]);
Utility.rep4varKmap(state.kmaps[2]);
System.out.println();
}
|
b8abd6bf-48ab-4847-844a-bd583b5257fa
|
public static String loadContigSeq(int id) throws SQLException{
Connection conn = ConnectionManager.getConnection(0);
String seq = null;
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(" SELECT sequence from ScaffoldSeq where scaffoldId = "+id+";");
while (rs.next()){
seq = rs.getString(1);
}
rs.close();
stmt.close();
return seq;
}
|
36137986-4f6a-4209-b1aa-3a2261f4f59c
|
private static String loadScaffoldFragment(int scaffoldId, int start,int end) throws SQLException{
Connection conn = ConnectionManager.getConnection(0);
String seq = null;
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(" SELECT substring(sequence,"+start+","+(end-start)+") FROM"+
" ScaffoldSeq where scaffoldId="+scaffoldId);
while (rs.next()){
seq = rs.getString(1);
}
rs.close();
stmt.close();
return seq;
}
|
f09966f8-1eb8-4bef-b1f9-e8f86aafda4d
|
public static Sequence loadGeneUpstream(Locus l, int leftCoord) throws SQLException{
DnaPosition pos = l.pos;
Scaffold sc = l.sc;
// System.out.println(pos.toString());
int scaffoldStartPos;
int scaffoldEndPos;
if (pos.dir_PLUS) {
scaffoldStartPos = pos.begin+leftCoord;
scaffoldEndPos = pos.end+1;
}
else{
scaffoldStartPos = pos.begin;
scaffoldEndPos = pos.end-leftCoord+1;
}
String seq;
if (sc.isCircular==0){
System.out.println("not circular");
if (scaffoldStartPos<=1) scaffoldStartPos=1;
if (scaffoldEndPos>=sc.length) scaffoldEndPos=sc.length;
seq = loadScaffoldFragment(sc.scaffoldId,scaffoldStartPos,scaffoldEndPos);
}
else{
if (scaffoldStartPos<=1) {
scaffoldStartPos=sc.length+scaffoldStartPos;
if ((scaffoldEndPos<=1)){
scaffoldEndPos=sc.length+scaffoldEndPos;
seq = loadScaffoldFragment(sc.scaffoldId,scaffoldStartPos,scaffoldEndPos);
}
else{
String seq1 = loadScaffoldFragment(sc.scaffoldId,scaffoldStartPos,sc.length+1);
String seq2 = loadScaffoldFragment(sc.scaffoldId,1,scaffoldEndPos);
seq = seq1+seq2;
}
}
else if (scaffoldEndPos>=sc.length) {
scaffoldEndPos=scaffoldEndPos-sc.length;
if ((scaffoldStartPos>=sc.length)){
scaffoldStartPos=scaffoldStartPos-sc.length;
seq = loadScaffoldFragment(sc.scaffoldId,scaffoldStartPos,scaffoldEndPos);
}
else{
String seq1 = loadScaffoldFragment(sc.scaffoldId,scaffoldStartPos,sc.length+1);
String seq2 = loadScaffoldFragment(sc.scaffoldId,1,scaffoldEndPos);
seq = seq1+seq2;
}
}
else {
seq = loadScaffoldFragment(sc.scaffoldId,scaffoldStartPos,scaffoldEndPos);
}
}
byte[] res;
if (!pos.dir_PLUS){
res = Sequence.getReverseComplement(seq.getBytes());
}
else{
res = seq.getBytes();
}
String name = l.sc.taxonomyId+"|"+l.sc.scaffoldId+"|"+l.sc.isCircular+"|"+l.sc.gi+"|"+l.locusId+"|"+l.version+"|"+(l.pos.dir_PLUS?1:-1)+"|"+l.pos.begin+"|"+l.pos.end+"|"+scaffoldStartPos+"|"+scaffoldEndPos;
return new Sequence(name,res);
}
|
deb642ff-e070-46f4-8dc6-fee2be4339df
|
public ContigLoaderThread(int i,COGLoader loader,String dir) {
this.loader = loader;
this.dir = dir;
this.id = i;
}
|
43c01eea-f93a-4e1d-ada6-a2f750700d80
|
public void run(){
try{
Scaffold scaffold = loader.getNextScaffold();
while(scaffold!=null){
String f = dir+"/"+scaffold.taxonomyId+"_contig"+scaffold.scaffoldId+".fasta";
PrintWriter pw = new PrintWriter(f);
String seq = ContigSeqLoader.loadContigSeq(scaffold.scaffoldId);
pw.println(">"+scaffold.taxonomyId+"|"+scaffold.scaffoldId+"|"+scaffold.gi);
pw.println(seq);
pw.close();
System.out.println("Thread "+id+"says: contig "+scaffold.scaffoldId+" done.");
scaffold = loader.getNextScaffold();
}
}
catch (SQLException e) {
System.out.println("Thread "+id+"says SQL EXCEPTION:");
e.printStackTrace();
} catch (FileNotFoundException e) {
System.out.println("Thread "+id+"says FILE NOT FOUND EXCEPTION:");
e.printStackTrace();
}
}
|
dce8809d-782c-49de-a651-003a1930ade0
|
public COGLoaderThread(int i,COGLoader loader,String dir,String type,int upstream) {
this.loader = loader;
this.dir = dir;
this.id = i;
this.type = type;
this.upstream=upstream;
}
|
ec1fc333-bdb5-4a02-a9a3-10c905db5809
|
public void run(){
int strangeStartCount = 0;
int erroneusLocusCount = 0;
try{
Integer cog = loader.getNextCOG();
while(cog!=null){
ArrayList<Locus> genes = loader.cogs.get(cog);
String f = dir+"/"+type+cog+".fasta";
PrintWriter pw = new PrintWriter(f);
for (Iterator<Locus> iterator = genes.iterator(); iterator.hasNext();) {
Locus l = iterator.next();
Sequence s = LocusUpstreamLoader.loadGeneUpstream(l, -upstream);
String seq = new String (s.getSeq());
if (!loader.starts.contains(seq.substring(upstream, upstream+3))) {
System.out.println("Thread "+id+"says: "+type+cog+" gene "+s.getName()+":"+seq.substring(upstream, upstream+3));
String tr_seq = new String(Codon.TransSeq(s.getSeq(), 0));
String tr_seq_cut = tr_seq.substring((int)(upstream/3),tr_seq.length()-1);
String locusAA = LocusSeqLoader.loadAASeq(l.locusId,l.version);
if (!tr_seq_cut.substring(1).equals(locusAA.substring(1))) {
System.out.println("AA seqs not equal! reporting Error");
erroneusLocusCount++;
System.err.println("Thread "+id+"says: "+type+cog+" gene "+s.getName()+":"+seq.substring(upstream, upstream+3));
System.err.println("Translated from contig pos: "+tr_seq_cut);
System.err.println("From Locus aa seq: "+locusAA);
}
else strangeStartCount++;
}
pw.println(">"+s.getName());
pw.println(seq);
}
pw.close();
System.out.println("Thread "+id+"says: "+type+cog+" done.");
cog = loader.getNextCOG();
}
System.out.println("Thread "+id+"reports: "+strangeStartCount+" cases of strange start codons");
System.out.println("Thread "+id+"reports: "+erroneusLocusCount+" cases of erroneous locus");
}
catch (SQLException e) {
System.out.println("Thread "+id+"says SQL EXCEPTION:");
e.printStackTrace();
} catch (FileNotFoundException e) {
System.out.println("Thread "+id+"says FILE NOT FOUND EXCEPTION:");
e.printStackTrace();
}
}
|
0330abc0-ae0f-4dde-9aee-f32efdae806c
|
public COGLoader(String type) {
this.type = type;
}
|
f43b98c7-3813-46db-bd77-ecfb179786f6
|
private static String getQString(ArrayList<Integer> taxList,String type) throws SQLException{
String q = "";
for (Iterator<Integer> iterator = taxList.iterator(); iterator.hasNext();) {
Integer integer = iterator.next();
q+=(","+integer);
}
q=q.substring(1);
String qString = "";
if (type.equals("MOG")) qString+=
"select mogId,c.locusId,c.version,s.taxonomyId,s.scaffoldId,gi,isCircular,length,p.strand,p.begin,p.end from Scaffold s"+
" inner join Locus l ON l.scaffoldId=s.scaffoldId"+
" inner join MOGMember c ON c.locusId=l.locusId and c.version=l.version"+
" inner join Position p ON l.posId=p.posId"+
" where isActive=1 and isPartial=0 and isGenomic=1 and s.taxonomyId IN ("+q+") and l.priority=1"+
" order by mogId";
else if (type.equals("COG")) qString+=
"select cogInfoId,c.locusId,c.version,taxonomyId,s.scaffoldId,gi,isCircular,length,p.strand,p.begin,p.end from Scaffold s"+
" inner join Locus l ON l.scaffoldId=s.scaffoldId"+
" inner join COG c ON c.locusId=l.locusId and c.version=l.version"+
" inner join Position p ON l.posId=p.posId"+
" where isActive=1 and isPartial=0 and isGenomic=1 and s.taxonomyId IN ("+q+") and l.priority=1"+
" order by cogInfoId";
else return null;
return(qString);
}
|
e85f1a42-dc5d-4925-8019-08dcdb6f201b
|
private void loadMembers(ArrayList<Integer>taxList) throws SQLException{
String qString = getQString(taxList, type);
if (qString==null) {
System.out.println("Unknown type "+type);
System.exit(0);
}
cogs = new Hashtable<Integer,ArrayList<Locus>>();
scaffolds = new Hashtable<Integer,Scaffold>();
taxonomies = new HashSet<Integer>();
Connection conn = ConnectionManager.getConnection(0);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(qString);
int prevCogInfoId=-1;
ArrayList<Locus> genes = null;
while(rs.next()) {
int cogInfoId = rs.getInt(1);
if (cogInfoId!=prevCogInfoId){
if (prevCogInfoId!=-1) {
if (genes.size()>1) cogs.put(prevCogInfoId, genes);
else System.out.println(type+prevCogInfoId+" has only 1 record for specified taxonomies; not adding");
}
prevCogInfoId=cogInfoId;
genes = new ArrayList<Locus>();
}
int locusId = rs.getInt(2);
int version = rs.getInt(3);
int taxonomyId = rs.getInt(4);
int scaffoldId = rs.getInt(5);
Scaffold sc;
if (scaffolds.containsKey(scaffoldId)) sc=scaffolds.get(scaffoldId);
else {
sc = new Scaffold(scaffoldId,taxonomyId,rs.getInt(6),rs.getByte(7),rs.getInt(8));
scaffolds.put(scaffoldId, sc);
taxonomies.add(taxonomyId);
}
DnaPosition pos = new DnaPosition(sc, rs.getString(9),rs.getInt(10),rs.getInt(11));
genes.add(new Locus(locusId, version, cogInfoId, pos, sc));
}
if (genes.size()>1) cogs.put(prevCogInfoId, genes);
else System.out.println(type+prevCogInfoId+" has only 1 record for specified taxonomies; not adding");
rs.close();
stmt.close();
}
|
c2f899f4-b84e-48b9-b80f-8292709077b3
|
protected synchronized Integer getNextCOG(){
if (ind_COG<0) {
this.COGIterator = cogs.keySet().iterator();
ind_COG = 0;
}
if (COGIterator.hasNext()) return COGIterator.next();
else return null;
}
|
2bbb95fa-5ff4-4ecc-931e-e7373b60062f
|
protected synchronized Scaffold getNextScaffold(){
if (ind_contig<0) {
this.contigIterator = scaffolds.values().iterator();
ind_contig = 0;
}
if (contigIterator.hasNext()) return contigIterator.next();
else return null;
}
|
fe2df114-4d41-4b4e-8789-0cbb45400894
|
public void writeCOGs(int threadNumber, String dir,String type,int upstream){
long time = System.currentTimeMillis();
File f = new File(dir);
if (!f.exists()) f.mkdir();
else{
File[] ff = f.listFiles();
for (int i = 0; i < ff.length; i++) {
ff[i].delete();
}
}
COGLoaderThread[] threads = new COGLoaderThread[threadNumber];
for (int j = 0; j < threadNumber; j++) {
COGLoaderThread clt = new COGLoaderThread(j,this, dir,type,upstream);
clt.start();
threads[j]=clt;
System.out.println("thread "+j+" started");
}
for (int i = 0; i < threads.length; i++) {
try {
threads[i].join();
} catch (InterruptedException e) {
System.out.println("Can't join thread "+i);
e.printStackTrace();
}
}
System.out.println(type+"s loaded. Total working time: "+(System.currentTimeMillis()-time)+" ms");
}
|
8aa7bc70-c053-45b3-acf6-a3fdf6412f98
|
public void writeContigs(int threadNumber, String dir){
long time = System.currentTimeMillis();
File f = new File(dir);
if (!f.exists()) f.mkdir();
else{
File[] ff = f.listFiles();
for (int i = 0; i < ff.length; i++) {
ff[i].delete();
}
}
ContigLoaderThread[] threads = new ContigLoaderThread[threadNumber];
for (int j = 0; j < threadNumber; j++) {
ContigLoaderThread clt = new ContigLoaderThread(j,this, dir);
clt.start();
threads[j]=clt;
System.out.println("thread "+j+" started");
}
for (int i = 0; i < threads.length; i++) {
try {
threads[i].join();
} catch (InterruptedException e) {
System.out.println("Can't join thread "+i);
e.printStackTrace();
}
}
System.out.println("Contigs loadded. Total working time: "+(System.currentTimeMillis()-time)+" ms");
}
|
3fd83044-9b30-4928-bfe9-2268350a9dcb
|
public static void launch(String f,String type,int upstream,boolean withContig){
System.out.println("Reading taxonomy list..");
ArrayList<Integer> taxList = new ArrayList<Integer>();
try{
BufferedReader br = new BufferedReader(new FileReader(f));
String line = br.readLine();
while (line!=null) {
if (!line.trim().equals("")) {
int taxa = Integer.parseInt(line);
taxList.add(taxa);
System.out.println(taxa);
}
line = br.readLine();
}
br.close();
}
catch (IOException e) {
System.out.println("IO EXCEPTION READING "+f);
e.printStackTrace();
System.exit(0);
}
System.out.println("Loading "+type+" data..");
COGLoader loader = new COGLoader(type);
try {
loader.loadMembers(taxList);
} catch (SQLException e) {
System.out.println("FAILED TO LOAD "+type+" DATA");
e.printStackTrace();
System.exit(0);
}
System.out.println("ALL "+type+" NUMBER FOR SPECIFIED TAXONOMIES: "+loader.cogs.size());
System.out.println("SCAFFOLDS NUMBER:" + loader.scaffolds.size());
System.out.println("TAXONOMIES NUMBER:" + loader.taxonomies.size());
for (Iterator<Integer> iterator = loader.taxonomies.iterator(); iterator.hasNext();) {
System.out.println(iterator.next());
}
int MAX_PROCESSORS_NUMBER = 24;
int processorsNumber = Runtime.getRuntime().availableProcessors();
System.out.println("processors number:"+processorsNumber);
int threadNumber = Math.min(processorsNumber, MAX_PROCESSORS_NUMBER);
System.out.println("Loading loading "+type+" fastas..");
String dir = "MO_"+type;
loader.writeCOGs(threadNumber, dir,type,upstream);
if (withContig){
System.out.println("Loading corresponding contigs..");
loader.writeContigs(threadNumber, "MO_Contig");
}
}
|
944c8aec-4397-4084-a1d1-f50e3fa98a1a
|
public static void main(String[] args) throws FileNotFoundException {
/* String f = "genomes_list.txt";
String type = "MOG";
int upstream = 201;*/
String f = args[0];
String type = args[1];
int upstream = Integer.parseInt(args[2]);
boolean withContig = false;
try{
if (args[3].toLowerCase().equals("withcontig")) withContig = true;
}
catch(ArrayIndexOutOfBoundsException e){
}
System.out.println(withContig);
launch(f,type,upstream,withContig);
}
|
bccbed2b-4d93-414e-94a1-63b4479d0f62
|
public static String loadAASeq(int id,int version) throws SQLException{
Connection conn = ConnectionManager.getConnection(0);
String seq = null;
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(" SELECT sequence from AASeq where locusId = "+id+" and version = "+version+" ;");
while (rs.next()){
seq = rs.getString(1);
}
rs.close();
stmt.close();
return seq;
}
|
d6e203c0-fb43-4582-bb28-35760d817888
|
public static Connection getConnection(int i) {
try {
if (conn[i] == null || conn[i].isClosed()) {
conn[i] = createNewConnection(i);
}
if (!checkConnection(i))
reconnect(i);
return conn[i];
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
|
e98cab5a-d3e9-43f6-af7a-298223c56bb7
|
private static Connection createNewConnection(int i) throws Exception {
String host = Configuration.getConnHost(i);
String port = Configuration.getConnPort(i);
String url = "jdbc:mysql://" + host + ":" + port + "/";
String db = Configuration.getConnDB(i);
if (db != null)
url += db;
String usr = Configuration.getConnUser(i);
String pwd = Configuration.getConnPwd(i);
Class.forName(DRIVER_CLASS);
return DriverManager.getConnection(url, usr, pwd);
}
|
f40b4747-f695-4675-b34a-c7c015c7046c
|
private static boolean checkConnection(int i) {
if (conn[i] == null)
return false;
boolean res = false;
String testQuery = Configuration.getConnTestQuery(i);
try {
Statement stmt = conn[i].createStatement();
if (stmt.execute(testQuery))
res = true;
stmt.close();
} catch (Exception e) {
System.err.println("Bad connection.");
}
return res;
}
|
3443553c-125f-4a57-b550-6328d7dc1c99
|
private static void reconnect(int j) throws Exception {
System.out.println("Reconnectiong..");
int i = 0;
while (i < RECONNECT_NUMBER) {
closeConnection(j);
conn[i] = createNewConnection(j);
if (checkConnection(j))
break;
i++;
}
if (i == RECONNECT_NUMBER)
throw new Exception();
}
|
b025f60a-b54a-4c78-a039-afdb59f483b8
|
public static void closeConnection(int i) {
try {
if ((conn[i] != null) && (!conn[i].isClosed()))
conn[i].close();
} catch (Exception e) {
e.printStackTrace();
}
}
|
96be47b1-e8d4-45cc-b53c-85db5af34ed7
|
public static boolean isPropsNull(int i){
return (props[i]==null);
}
|
abd91bc4-e8ab-48da-bc5c-106601d91e98
|
public static String getConnHost(int i) {
Properties prpos = getProps(i);
String host = prpos.getProperty(ConnHost);
if (host == null)
host = "localhost";
return host;
}
|
429f30f6-a2d0-45e1-a88b-cf92382c3605
|
public static String getConnPort(int i) {
Properties prpos = getProps(i);
String port = prpos.getProperty(ConnPort);
if (port == null)
port = "3306";
return port;
}
|
7e2ba421-4293-4ed8-8b5e-4e6c37a05bdf
|
public static String getMysqlPath(int i) {
Properties prpos = getProps(i);
String mysql_path = prpos.getProperty(MysqlPath);
if (mysql_path == null)
mysql_path = "mysql";
return mysql_path;
}
|
2a72aaf3-554a-47ff-8c9b-a2ea022bd9dd
|
public static String getConnDB(int i) {
Properties prpos = getProps(i);
return prpos.getProperty(ConnDB);
}
|
300f45dc-6fc4-4bfe-8ccf-ab74473302be
|
public static String getConnUser(int i) {
Properties prpos = getProps(i);
return prpos.getProperty(ConnUser);
}
|
eb9c38d8-ff91-47f6-bc06-107db88a0385
|
public static String getConnPwd(int i) {
Properties prpos = getProps(i);
return prpos.getProperty(ConnPwd);
}
|
9f6d664a-ea0f-42e8-b082-baa03701057a
|
public static String getConnTestQuery(int i) {
Properties prpos = getProps(i);
String testQuery = prpos.getProperty(ConnTestQuery);
if (testQuery == null)
testQuery = "select 1";
return testQuery;
}
|
70633f80-d6cc-43e7-8762-28f2a5de712c
|
public static Properties getProps(int i) {
if (props[i] == null) {
try {
props[i] = loadConfigProps(i);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException();
}
}
return props[i];
}
|
c94ca558-cf3d-41e9-bd1f-a4a64f97910f
|
public static Properties loadConfigProps(int i) {
Properties p = new Properties();
try {
Reader fr = new InputStreamReader(Configuration.class
.getResourceAsStream(cfg_file_name[i]));
p.load(fr);
fr.close();
} catch (Exception e) {
e.printStackTrace();
System.out.println("Can't read Configurations file((");
// TODO: handle exception
}
return p;
}
|
7ffce19f-b525-40b0-aa94-96a9b3c46a28
|
public DnaPosition(Scaffold scaffold, String strand, int begin, int end) {
super();
this.scaffold = scaffold;
this.dir_PLUS = strand.equals("+")?true:false;
this.begin = begin;
this.end = end;
}
|
224dc969-1e11-4524-ba2d-ebb3470c3a47
|
public String toString(){
return "["+scaffold.toString()+"] "+dir_PLUS+" "+begin+" "+end+" ";
}
|
40296949-fb2a-4964-97ed-66cb2dbc1076
|
public Locus(int locusId, int version, int cogInfoId,DnaPosition pos,Scaffold sc) {
super();
this.locusId = locusId;
this.version = version;
this.cogInfoId = cogInfoId;
this.pos = pos;
this.sc = sc;
}
|
553420ae-5608-475a-8a84-23da4f8b83ad
|
public Scaffold(int scaffoldId, int taxonomyId, int gi, byte isCircular, int length) {
super();
this.scaffoldId = scaffoldId;
this.taxonomyId = taxonomyId;
this.gi = gi;
this.isCircular = isCircular;
this.length = length;
}
|
39ea2c5f-d381-496b-8a7e-8b3ee1238b83
|
public String toString(){
return scaffoldId+" "+taxonomyId+" "+gi+" "+isCircular+" "+length;
}
|
1a32b978-d4ed-4c55-beba-d365abfbf095
|
public SerializerTest() {
}
|
508e153f-f0f5-46f2-b836-a1053a8467b6
|
@BeforeClass
public static void setUpClass() {
obj1 = new TestClass();
obj2 = new TestClassWithPrimitiveFields();
obj3 = new TestClassWithReferenceFields();
obj4 = new TestClassWithPrimitiveArrayField();
obj5 = new TestClassWithReferenceArrayField();
}
|
bdaa5fd8-73e3-4282-9028-aea30967d147
|
@AfterClass
public static void tearDownClass() {
}
|
15e3364d-8cf4-4510-9ff6-a74bad7f8c37
|
@Before
public void setUp() {
}
|
65e050c7-7afd-4c32-9a56-6e3ab29766ab
|
@After
public void tearDown() {
}
|
e3caee60-aaa9-4372-9e7d-df4dd744cb74
|
public TestClass(){}
|
49d9549c-c28b-4a95-b0f9-ecf8954e4347
|
public TestClassWithPrimitiveFields()
{
a = 6.0;
b = 7;
c = false;
}
|
edec8f13-8af6-48a7-8b11-c299ddec6653
|
public TestClassWithReferenceFields()
{
p = new TestClassWithPrimitiveFields();
q = new TestClassWithPrimitiveFields();
}
|
03adb26e-eaa2-4fe5-9b4f-14546d677900
|
public TestClassWithPrimitiveArrayField()
{
array = new int[]{2, 4, 5};
}
|
c06c0941-8c87-403b-a8a5-2c27b4f2ec3d
|
public TestClassWithReferenceArrayField()
{
array = new TestClassWithPrimitiveFields[]
{
new TestClassWithPrimitiveFields(),
new TestClassWithPrimitiveFields(),
};
}
|
b493b5fa-f6f2-4482-8ddd-0c2a74b701e9
|
@Test
public void testSerialize_throwsNullObjException()
{
Serializer instance = new Serializer();
Object obj = null;
try
{
instance.serialize(obj);
fail("Exception for null object serialization not thrown.");
}
catch(ObjectToSerializeWasNullException e)
{
}
}
|
135053ab-45e7-4fde-8c56-3ef22cb70ee2
|
@Test
public void testSerialize_RootElem()
{
Serializer instance = new Serializer();
Document result = null;
try
{
result = instance.serialize(obj1);
}
catch(ObjectToSerializeWasNullException e)
{
fail("Object to serialize was null.");
}
Element rootElement = result.getRootElement();
assertEquals("serialized", rootElement.getName());
}
|
bd5fa6f7-b012-4a4a-86e0-be80b3b2cb58
|
@Test
public void testSerialize_RootElemHasChildren()
{
Serializer instance = new Serializer();
Document result = null;
try
{
result = instance.serialize(obj1);
}
catch(ObjectToSerializeWasNullException e)
{
fail("Object to serialize was null.");
}
Element rootElement = result.getRootElement();
assertFalse("The root element has no children", rootElement.getChildren().isEmpty());
}
|
269fc60e-525c-4a7f-a269-1d6e523ea2ff
|
@Test
public void testSerialize_ObjectElemAttributes()
{
Serializer instance = new Serializer();
Document result = null;
try
{
result = instance.serialize(obj1);
}
catch(ObjectToSerializeWasNullException e)
{
fail("Object to serialize was null.");
}
Element rootElement = result.getRootElement();
Element objElem = rootElement.getChild("object");
assertNotNull("There was no object child element", objElem);
assertTrue("Object element has no attributes, although it should", objElem.hasAttributes());
assertEquals("The class attribute was not correct", "SerializerTest.TestClass", objElem.getAttribute("class").getValue());
assertEquals("The ID number was not correct", "0", objElem.getAttribute("id").getValue());
}
|
90b12e02-a134-4a3b-b4da-1927832c2d55
|
@Test
public void testSerialize_ObjectElemPrimitiveFieldsRecognized()
{
Serializer instance = new Serializer();
Document result = null;
try
{
result = instance.serialize(obj2);
}
catch(ObjectToSerializeWasNullException e)
{
fail("Object to serialize was null.");
}
Element rootElement = result.getRootElement();
Element objElem = rootElement.getChild("object");
assertNotNull("There was no object child element", objElem);
assertEquals("Root object did not have correct number of fields", 3, objElem.getChildren().size());
for(Element elemChild : objElem.getChildren())
{
Element valueElem = elemChild.getChild("value");
Content valueContent = valueElem.getContent().get(0);
String value = valueContent.getValue();
if(!(value.equals("6.0") || value.equals("7") || value.equals("false")))
fail("The value " + value + " was not found");
}
}
|
e298c99c-eabf-4747-b64a-889904c57b5f
|
@Test
public void testSerialize_ObjectElemReferenceFieldsRecognized()
{
Serializer instance = new Serializer();
Document result = null;
try
{
result = instance.serialize(obj3);
}
catch(ObjectToSerializeWasNullException e)
{
fail("Object to serialize was null.");
}
Element rootElement = result.getRootElement();
List<Element> objElemList = rootElement.getChildren("object");
assertEquals("Doc did not have correct number of objects", 3, objElemList.size());
for(Element objElem : objElemList)
{
if(objElem.getAttributeValue("id").equals("0")) // This was original object
{
assertEquals("Root obj did not have correct number of fields", 2, objElem.getChildren("field").size());
// Check Id's of the fields which are references
List<Element> fieldElemsList = objElem.getChildren("field");
Content idOfFirstObject = fieldElemsList.get(0).getChild("reference").getContent(0);
Content idOfSecondObject = fieldElemsList.get(1).getChild("reference").getContent(0);
if(idOfFirstObject.getValue().equals("1"))
assertTrue(idOfSecondObject.getValue().equals("2"));
else
assertTrue(idOfSecondObject.getValue().equals("1"));
}
}
}
|
e1a0ed1b-132f-4d3d-99b9-7021e264d260
|
@Test
public void testSerialize_ObjectElemPrimitiveArrayFieldRecognized()
{
Serializer instance = new Serializer();
Document result = null;
try
{
result = instance.serialize(obj4);
}
catch(ObjectToSerializeWasNullException e)
{
fail("Object to serialize was null.");
}
Element rootElement = result.getRootElement();
List<Element> objElemList = rootElement.getChildren("object");
assertEquals("The doc did not have the correct amount of objects", 2, objElemList.size());
for(Element objElem : objElemList)
{
if(objElem.getAttributeValue("id").equals("0")) // This was original object
{
assertEquals("The number of fields in root object was not correct", 1, objElem.getChildren("field").size());
// Check Id of array object when it is being referenced from field
List<Element> fieldElemsList = objElem.getChildren("field");
Content idOfArrayObject = fieldElemsList.get(0).getChild("reference").getContent(0);
assertEquals("The id of array object was not correct", "" + 1, idOfArrayObject.getValue());
}
else // This is the array object
{
// Check attributes of array object
assertTrue("Object element has no attributes, although it should", objElem.hasAttributes());
assertEquals("The class attribute was not correct", "[I", objElem.getAttribute("class").getValue());
assertEquals("The ID number was not correct", "1", objElem.getAttribute("id").getValue());
assertEquals("The array length attribute was not correct", "3", objElem.getAttribute("length").getValue());
//Check array values
assertEquals("The length of array was not correct", 3, objElem.getChildren("value").size());
}
}
}
|
0c70d670-bea5-4240-b4dc-35e55a647bec
|
@Test
public void testSerialize_ObjectElemReferenceArrayFieldRecognized()
{
Serializer instance = new Serializer();
Document result = null;
try
{
result = instance.serialize(obj5);
}
catch(ObjectToSerializeWasNullException e)
{
fail("Object to serialize was null.");
}
Element rootElement = result.getRootElement();
List<Element> objElemList = rootElement.getChildren("object");
assertEquals("The doc did not have the correct amount of objects", 4, objElemList.size());
for(Element objElem : objElemList)
{
if(objElem.getAttributeValue("id").equals("0")) // This was original object
{
assertEquals("The number of fields in root object was not correct", 1, objElem.getChildren("field").size());
// Check Id of array object when it is being referenced from field
List<Element> fieldElemsList = objElem.getChildren("field");
Content idOfArrayObject = fieldElemsList.get(0).getChild("reference").getContent(0);
assertEquals("The id of array object was not correct", "" + 1, idOfArrayObject.getValue());
}
else if(objElem.getAttributeValue("id").equals("1")) // This is the array object
{
// Check attributes of array object
assertTrue("Object element has no attributes, although it should", objElem.hasAttributes());
assertEquals("The class attribute was not correct", "[LSerializerTest$TestClassWithPrimitiveFields;", objElem.getAttribute("class").getValue());
assertEquals("The ID number was not correct", "1", objElem.getAttribute("id").getValue());
assertEquals("The array length attribute was not correct", "2", objElem.getAttribute("length").getValue());
//Check array values
assertEquals("The length of array was not correct", 2, objElem.getChildren("reference").size());
}
}
}
|
4bddefa4-46c0-4450-96bf-cb98e8b6036a
|
@Test
public void testSerialize_ObjectElemCollectionReferenceRecognized()
{
Serializer instance = new Serializer();
ArrayList<Object_PrimitiveFields> list = new ArrayList<Object_PrimitiveFields>();
list.add(new Object_PrimitiveFields(3,5,6));
list.add(new Object_PrimitiveFields(13,9,6));
Object_JavaCollectionOfReferences obj6 = new Object_JavaCollectionOfReferences(list);
Document result = null;
try
{
result = instance.serialize(obj5);
}
catch(ObjectToSerializeWasNullException e)
{
fail("Object to serialize was null.");
}
fail();
}
|
da1957c8-347c-4338-883f-e1553d0e2cfa
|
public ObjectToSerializeWasNullException()
{
super();
}
|
d62af8c7-ecc5-4369-802f-3863a25d6717
|
public Serializer()
{
doc = new Document();
}
|
5a722c0a-4808-46d1-b7f7-de732ab8d6b9
|
public Document serialize(Object obj) throws ObjectToSerializeWasNullException
{
if(obj == null) throw new ObjectToSerializeWasNullException();
// Set root element
Element rootElem = new Element("serialized");
doc.setRootElement(rootElem);
serializeObject(assignIdFor(obj), obj);
return doc;
}
|
4b66f466-41c0-4c7d-9676-f84b81f7d571
|
public Document getDoc() {
return doc;
}
|
cd00e877-75b2-4d38-b3d0-578510b1569d
|
private void serializeObject(long id, Object obj)
{
Class classObj = obj.getClass();
// Create object element
Element objElem = new Element("object");
objElem.setAttribute(new Attribute("class", classObj.getCanonicalName()));
objElem.setAttribute(new Attribute("id", "" + id));
// Set fields
if(classObj.getDeclaredFields().length >= 1)
{
Field[] fields = classObj.getDeclaredFields();
for(Field fieldObj : fields)
{
fieldObj.setAccessible(true);
String valueOfField = null;
String nameOfField = null;
Class type = fieldObj.getType();
// Field is a reference to another object
if(!type .isPrimitive() && !type.isArray())
{
Object objectToSerialize = null;
try
{
objectToSerialize = fieldObj.get(obj);
}
catch(IllegalAccessException e)
{
System.out.println("Cannot access field reference: " + fieldObj.getName());
}
// Get id for this reference object
long objectToSerializeId = this.assignIdFor(objectToSerialize);
valueOfField = objectToSerializeId + "";
nameOfField = "reference";
serializeObject(objectToSerializeId, objectToSerialize);
}
// Field is a reference to an array
else if (type.isArray() || type.isAssignableFrom(ArrayList.class))
{
Object objectToSerialize = null;
try
{
objectToSerialize = fieldObj.get(obj);
}
catch(IllegalAccessException e)
{
System.out.println("Cannot access field array: " + fieldObj.getName());
}
// Get id for this reference object
long objectToSerializeId = this.assignIdFor(objectToSerialize);
valueOfField = objectToSerializeId + "";
nameOfField = "reference";
serializeArray(objectToSerializeId, objectToSerialize);
}
// Field is a primitive
else if(type.isPrimitive())
{
try
{
valueOfField = fieldObj.get(obj) + "";
}
catch(IllegalAccessException e)
{
System.out.println("Cannot access value from field: " + fieldObj.getName());
}
nameOfField = "value";
}
// Create field element
Element fieldElem = new Element("field");
// Set field attributes
fieldElem.setAttribute(new Attribute("name", fieldObj.getName()));
fieldElem.setAttribute(new Attribute("declaringclass", "" + classObj.getCanonicalName()));
// Set field value
Element fieldContentElem = new Element(nameOfField);
fieldContentElem.addContent("" + valueOfField);
fieldElem.addContent(fieldContentElem );
// Add field to object element
objElem.addContent(fieldElem);
}
}
doc.getRootElement().addContent(objElem);
}
|
e37ae213-e032-4207-a603-f5e6bb18aa9f
|
private void serializeArray(long id, Object obj)
{
Class classObj = obj.getClass();
// Create object element
Element objElem = new Element("object");
objElem.setAttribute(new Attribute("class", classObj.getName()));
objElem.setAttribute(new Attribute("id", "" + id));
objElem.setAttribute(new Attribute("length", "" + Array.getLength(obj)));
boolean arrayIsPrimitive = obj.getClass().getComponentType().isPrimitive();
String nameOfField = null;
String valueOfField = null;
//Serialize each element
int length = Array.getLength(obj);
for (int i = 0; i < length; i ++)
{
Object item = Array.get(obj, i);
if(arrayIsPrimitive)
{
nameOfField = "value";
valueOfField = item + "";
}
else
{
nameOfField = "reference";
long idOfObjectToBeSerialized = this.assignIdFor(item);
valueOfField = idOfObjectToBeSerialized + "";
this.serializeObject(idOfObjectToBeSerialized, item);
}
// Set field value
Element fieldContentElem = new Element(nameOfField);
fieldContentElem.addContent(valueOfField);
// Add field to object element
objElem.addContent(fieldContentElem);
}
doc.getRootElement().addContent(objElem);
}
|
ba7fbd49-009a-4e01-b544-f53ea29330a5
|
public long assignIdFor(Object o)
{
registry.put(nextId, o);
return nextId++;
}
|
ebc20f6b-b82b-453a-b2b4-0350481711bd
|
public Object_JavaCollectionOfReferences ()
{
list = new ArrayList<Object_PrimitiveFields>();
}
|
331dfe4b-1a95-4281-8023-7125c7b5444b
|
public Object_JavaCollectionOfReferences (ArrayList<Object_PrimitiveFields> list)
{
this.list = list;
}
|
a6b29b8f-4c98-4b5a-91d2-947f47b1722f
|
public void AssignFieldsThroughUserInput()
{
String userInput = null;
System.out.println("Please select values for the fields, or Exit:");
Scanner in = new Scanner(System.in);
System.out.println("list:");
int i = 0;
while(i < 2)
{
try
{
System.out.println("Object_PrimitiveArray, # " + i + " ");
// Get field value from user
Object_PrimitiveFields obj = new Object_PrimitiveFields();
obj.AssignFieldsThroughUserInput();
list.add(obj);
i ++;
}
catch(NumberFormatException e)
{
if(userInput.equalsIgnoreCase("exit"))
System.exit(0);
else
{
System.out.println("Not a valid answer. Please try again.");
}
}
}
}
|
e42bd15f-5a5a-4aaa-81a2-54c0a0f9f1a5
|
public Object_PrimitiveFields() {}
|
245efa11-4669-41d8-b136-cebaf228c2ad
|
public Object_PrimitiveFields(int a, int b, int c)
{
this.a = a;
this.b = b;
this.c = c;
}
|
79e77016-743e-4897-99d8-74b9ad8ebf10
|
public void AssignFieldsThroughUserInput()
{
String userInput = null;
System.out.println("Please select values for the fields, or Exit:");
Class c = this.getClass();
Field[] declaredFields = c.getDeclaredFields();
Scanner in = new Scanner(System.in);
int i = 0;
while(i < declaredFields.length)
{
System.out.print(declaredFields[i].getType() + " " + declaredFields[i].getName() + " = ");
userInput = in.nextLine();
try
{
// Get field value from user
int selection = Integer.parseInt(userInput);
declaredFields[i].setAccessible(true);
declaredFields[i].set(this, selection);
i++;
}
catch(NumberFormatException e)
{
if(userInput.equalsIgnoreCase("exit"))
System.exit(0);
else
System.out.println("Not a valid answer. Please try again.");
}
catch(IllegalAccessException e)
{
System.out.println("Cannot access the field.");
System.exit(0);
}
}
}
|
ad73f6d3-57c5-496b-8584-7be141032f0b
|
public Server(int port)
{
try
{
serverSocket = new ServerSocket(port);
serverSocket.setSoTimeout(30000);
}
catch (IOException e)
{
System.out.println("Could not open server socket");
}
}
|
517316c4-8215-4c5d-a0dc-0cc70334e0c0
|
@Override
public void run()
{
Scanner consoleIn = new Scanner(System.in);
while(true)
{
try
{
System.out.println("Waiting for client on port " +
serverSocket.getLocalPort() + "...");
Socket server = serverSocket.accept();
System.out.println("Just connected to " + server.getRemoteSocketAddress());
ObjectInputStream in = new ObjectInputStream(server.getInputStream());
Document doc = null;
try
{
doc = (Document) in.readObject();
System.out.println(doc.getRootElement().getName());
}
catch(ClassNotFoundException e)
{
System.out.println("Class not found");
System.exit(0);
}
// Deserialize object
Deserializer d = new Deserializer();
Object o = d.deserialize(doc);
// Visualize object
ObjectInspector objInsp = new ObjectInspector();
objInsp.inspect(o, true);
server.close();
}catch(SocketTimeoutException s)
{
System.out.println("Socket timed out!");
break;
}catch(IOException e)
{
e.printStackTrace();
break;
}
}
}
|
817134a5-68da-4e6e-9b2d-dddbfe6373d4
|
public Object_ReferenceArray()
{
array = new Object_PrimitiveFields[2];
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.