Exception in thread "main" java.lang.IllegalArgumentException: bound must be positive - java

import java.util.Random;
import java.util.StringTokenizer;
public class FortuneCookie {
private String subjList;
private String objList;
private String verbList;
private int sWords = 0;
private int oWords = 0;
private int vWords = 0;
private Random random = new Random();
public FortuneCookie() {
subjList = "i#You#He#She#It#They";
objList = "me#you#him#her#it#them";
verbList = "hate#love#deny#find#hear#forgive#hurt#win#teach";
}
public void setSubject(String subj) {
subjList = subj;
}
public void setObjectList(String obj) {
objList = obj;
}
public void setVerbList(String verb) {
verbList = verb;
}
public String genFortuneMsg() {
String v = " ";
String o = " ";
String s = " ";
StringTokenizer st1 = new StringTokenizer(subjList, "#");
StringTokenizer st2 = new StringTokenizer(objList, "#");
StringTokenizer st3 = new StringTokenizer(verbList, "#");
while (st1.hasMoreTokens()) {
s = st1.nextToken();
sWords = st1.countTokens();
int no = random.nextInt(sWords);
if (no == sWords) {
break;
}
}
while (st2.hasMoreTokens()) {
o = st2.nextToken();
oWords = st2.countTokens();
int no2 = random.nextInt(oWords);
if (no2 == oWords) {
break;
}
}
while (st3.hasMoreTokens()) {
v = st3.nextToken();
vWords = st3.countTokens();
int no3 = random.nextInt(vWords);
if (no3 == vWords) {
break;
}
}
String gen = s + " " + v + " " + o;
return gen;
}
public void print() {
System.out.println("Tokens");
System.out.println("Subject List:" + subjList + " count = " + sWords);
System.out.println("verb List:" + verbList + " count = " + vWords);
System.out.println("object List:" + objList + " count = " + oWords);
}
}
Exception in thread "main" java.lang.IllegalArgumentException: bound
must be positive at java.util.Random.nextInt(Random.java:388) at
FortuneCookie.genFortuneMsg(FortuneCookie.java:42) at
FortuneCookieTest.main(FortuneCookieTest.java:6)

Your case is not negative it is zero.
From the docs of countToken method
/**
* Calculates the number of times that this tokenizer's
* <code>nextToken</code> method can be called before it generates an
* exception. The current position is not advanced.
*
In a while loop when your count token return zero, you run into an exception. Well that error message should be reformatted to negative or zero.
Add 1 to your result or check for zero. Should work.

Related

how to fix blank file IO in java [duplicate]

This question already has answers here:
Blank file after writing to it?
(3 answers)
Closed 5 years ago.
I am newbie in java programming and learning Io. I am making a simple RPG game but got a problem in my code. it's about the file it's blank whenever i finish running it. somehow whenever I run it I got an empty file. can some one help me :c. (sorry for bad English)
here is my code: FOR RANDOM CLASS
public class Dice {
/** instance variables */
private final Random r;
/**
* Initializes the random number generator r
*/
public Dice() {
r = new Random();
}
/**
* Returns a random integer between 1 and 6 using Random r
* #return
*/
public int roll() {
int dieRoll = r.nextInt(6 - 1);
return dieRoll;
}
}
FOR Character CLASS
public class Character {
static Dice dice = new Dice();
private String name;
private int strength;
private int dexterity;
private int intelligence;
private int maxLife;
private int currentLife;
private int atk;
public Character(){
}
public Character(String n, int s, int d, int i) {
this.name = n;
this.strength = s;
this.dexterity = d;
this.intelligence = i;
this.maxLife = 100 + dice.roll();
this.currentLife = maxLife;
}
/**
* Returns a random die roll using the roll method in the Dice.java,
* *modified by the character's strength
*/
public int attack() {
this.atk = strength * dice.roll() + 24;
return atk;
}
public void wound(int damage) {
if ((currentLife - damage) <= 0) {
this.currentLife = 0;
} else {
this.currentLife = currentLife - damage;
}
}
public void heal(int heal) {
if ((currentLife + heal) < maxLife) {
this.currentLife = currentLife + heal;
} else {
this.currentLife = maxLife;
}
}
public boolean checkDead() {
return currentLife == 0;
}
public String getName() {
return name;
}
public int getStrength() {
return strength;
}
/**
* Returns dexterity
*/
public int getDexterity() {
return dexterity;
}
/**
* * Returns intelligence
*/
public int getIntelligence() {
return intelligence;
}
/**
* Returns currentLife
*/
public int getCurrentLife() {
return currentLife;
}
/**
* Returns maxLife
*/
public int getMaxLife() {
return maxLife;
}
public int getAtk() {
return atk;
}
}
FOR MAIN CLASS(HERE IS WERE THE PROBLEM I DONT KNOW IF I LACK SOMETHING HERE)
public class TestCharacter {
public static void main(String letsPlay[]){
PrintWriter outputStream = null;
try{
outputStream = new PrintWriter(new FileOutputStream("RPGOutput.txt",true));
Scanner s = new Scanner(System.in);
System.out.print("Enter Player 1 Character name:");
Character p1 = new Character(s.next(),s.nextInt(),s.nextInt(),s.nextInt());
System.out.println(p1.getName()+ "\tHAS ENTERED THE BATTLE!");
System.out.println("Enter Player 2 Character name:");
Character p2 = new Character(s.next(),s.nextInt(),s.nextInt(),s.nextInt());
System.out.println(p2.getName()+ "\tHAS ENTERED THE BATTLE!");
int i = 1;
do {
outputStream.println("\nR O U N D " + i + "!");
outputStream.print(p1.getName() + " "+"HP is");
outputStream.println("\t" + p1.getCurrentLife() + "/" + p1.getMaxLife());
outputStream.println("while");
outputStream.print(p2.getName() + " " + " HP is");
outputStream.println("\t" + p2.getCurrentLife() + "/" + p2.getMaxLife());
outputStream.println(" ");
p2.wound(p1.attack());
outputStream.println(p1.getName() + " attacks " + p2.getName() + " for " + p1.getAtk() + " damage!");
if (p2.checkDead() == true) {
outputStream.println(p2.getName() + " lose " + p1.getName() + " has won!");
return;
}
p1.wound(p2.attack());
outputStream.println(p2.getName() + " attacks " + p1.getName() + " for " + p2.getAtk() + " damage!");
if (p1.checkDead() == true) {
outputStream.println(p1.getName() + " lose " + p2.getName() + " has won!");
return;
}
i++;
} while (p1.checkDead() == false || p2.checkDead() == false);
}catch(FileNotFoundException e){
System.out.println("Error no file" + e);
System.exit(0);
}
}
}
When you open a stream you should always finally close it.
In java 1.7 and above you just try( ... open the stream here ){ ... useit ...}, the compilers adds the finally close implicitly .
You need to finally close to be sure you don't leave open resources allocated.
It could be wise to set the PrintWriter to autoflush or make sure you flush before closing the stream, if not so maybe the PrintWriter does not write to the output stream until is buffer is full.
Java 1.6 and below
OutputStream fos = null;
try{
fos = new FileOutputStream("RPGOutput.txt",true);
PrintWriter out = new PrintWriter(fos, true);
out.println("Someting");
out.println("...");
//
out.flush();
}catch(IOException e){
// Manage exception
} finally {
try{
if(fos!=null){
fos.close();
}
}catch(IOException e){
// Swallow exception
}
}
Java 1.7 and above
try(OutputStream fos = new FileOutputStream("RPGOutput2.txt",true);
PrintWriter out = new PrintWriter(fos,true);) {
out.println("Hello");
out.print("Hello 2");
} catch (IOException e) {
// Manage exception
}

Exception when trying to instrument source code by WALA: java.lang.ClassFormatError: StackMapTable format error: wrong attribute size

I have a simple program like this:
package tests;
import java.util.Scanner;
public class TestSum {
public static void main(String[] args) {
int sum = 0;
System.out.print("Please enter starting i: ");
int i = new Scanner(System.in).nextInt();
while ( i < 11 ) {
sum = sum + i;
i = i + 1;
}
System.out.println("sum = " + sum);
System.out.println("Ending i = " + i);
}
}
I built this into a jar file and I want to use WALA to add more instrumented source code to count the number of loop execution for dynamic analysis purpose.
This is what I have done by using Wala, most of the stuffs is taken from this example Wala Bench Example
import com.ibm.wala.shrikeBT.*;
import com.ibm.wala.shrikeBT.analysis.Verifier;
import com.ibm.wala.shrikeBT.shrikeCT.CTDecoder;
import com.ibm.wala.shrikeBT.shrikeCT.ClassInstrumenter;
import com.ibm.wala.shrikeBT.shrikeCT.OfflineInstrumenter;
import com.ibm.wala.shrikeCT.ClassWriter;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.PrintStream;
import java.io.Writer;
/**
* Created by quocnghi on 2/2/17.
*/
public class InstrumentedTest {
private final static boolean disasm = true;
private final static boolean verify = true;
private static OfflineInstrumenter instrumenter = new OfflineInstrumenter(true);
public static void main(String[] args) throws Exception {
for (int i = 0; i < 1; i++) {
Writer w = new BufferedWriter(new FileWriter("report", false));
args = instrumenter.parseStandardArgs(args);
instrumenter.setPassUnmodifiedClasses(true);
instrumenter.beginTraversal();
ClassInstrumenter ci;
while ((ci = instrumenter.nextClass()) != null) {
doClass(ci, w);
}
instrumenter.close();
}
}
static final String fieldName = "_Bench_enable_trace";
// Keep these commonly used instructions around
static final Instruction getSysOut = Util.makeGet(System.class, "out");
static final Instruction callPrintln = Util.makeInvoke(PrintStream.class, "println", new Class[]{String.class});
private static void doClass(final ClassInstrumenter ci, Writer w) throws Exception {
final String className = ci.getReader().getName();
System.out.println("Class name : " + className);
w.write("Class: " + className + "\n");
w.flush();
for (int m = 0; m < ci.getReader().getMethodCount(); m++) {
MethodData d = ci.visitMethod(m);
System.out.println(d.getName());
// d could be null, e.g., if the method is abstract or native
if (d != null) {
w.write("Instrumenting " + ci.getReader().getMethodName(m) + " " + ci.getReader().getMethodType(m) + ":\n");
w.flush();
if (disasm) {
w.write("Initial ShrikeBT code:\n");
(new Disassembler(d)).disassembleTo(w);
w.flush();
}
if (verify) {
Verifier v = new Verifier(d);
v.verify();
}
MethodEditor methodEditor = new MethodEditor(d);
methodEditor.beginPass();
final int noTraceLabel = methodEditor.allocateLabel();
IInstruction[] instr = methodEditor.getInstructions();
final String msg0 = "Loop called at " + Util.makeClass("L" + ci.getReader().getName() + ";") + "."
+ ci.getReader().getMethodName(m);
int i = 0;
for (IInstruction in : instr) {
if (in instanceof ConditionalBranchInstruction) {
int b = i;
methodEditor.insertBefore(i, new MethodEditor.Patch() {
#Override
public void emitTo(MethodEditor.Output w) {
w.emit(getSysOut);
w.emit(ConstantInstruction.makeString(msg0));
w.emit(callPrintln);
w.emitLabel(noTraceLabel);
}
});
}
i++;
System.out.println(in.toString());
}
methodEditor.applyPatches();
if (disasm) {
w.write("Final ShrikeBT code:\n");
(new Disassembler(d)).disassembleTo(w);
w.flush();
}
}
}
ClassWriter cw = ci.emitClass();
instrumenter.outputModifiedClass(ci, cw);
}
}
I expect that after adding more instrumented code, the program should become like this, which add a line System.out.println in the loop :
package tests;
import java.util.Scanner;
public class TestSum {
public static void main(String[] args) {
int sum = 0;
System.out.print("Please enter starting i: ");
int i = new Scanner(System.in).nextInt();
while ( i < 11 ) {
sum = sum + i;
i = i + 1;
System.out.println("One count for this loop");
}
System.out.println("sum = " + sum);
System.out.println("Ending i = " + i);
}
}
But I got this error :
java.lang.ClassFormatError: StackMapTable format error: wrong attribute size
WALA does have StackMapTable support, but perhaps something is broken. I suggest filing an issue.

Error message for StorageResource type

I've been trying to work on this problem for a while now but to no avail. When I run the code I get this error message: incompatible types: edu.duke.StorageResource cannot be converted to java.lang.String on line String geneList = FMG.storeAll(dna);. Does this mean I'm trying to make edu.duke object work with a java.lang.String type object? What would we go about resolving this issue?
Here's my code so far:
package coursera_java_duke;
import java.io.*;
import edu.duke.FileResource;
import edu.duke.StorageResource;
import edu.duke.DirectoryResource;
public class FindMultiGenes5 {
public int findStopIndex(String dna, int index) {
int stop1 = dna.indexOf("TGA", index);
if (stop1 == -1 || (stop1 - index) % 3 != 0) {
stop1 = dna.length();
}
int stop2 = dna.indexOf("TAA", index);
if (stop2 == -1 || (stop2 - index) % 3 != 0) {
stop2 = dna.length();
}
int stop3 = dna.indexOf("TAG", index);
if (stop3 == -1 || (stop3 - index) % 3 != 0) {
stop3 = dna.length();
}
return Math.min(stop1, Math.min(stop2, stop3));
}
public StorageResource storeAll(String dna) {
//CATGTAATAGATGAATGACTGATAGATATGCTTGTATGCTATGAAAATGTGAAATGACCCAdna = "CATGTAATAGATGAATGACTGATAGATATGCTTGTATGCTATGAAAATGTGAAATGACCCA";
String geneAL = new String();
String sequence = dna.toUpperCase();
StorageResource store = new StorageResource();
int index = 0;
while (true) {
index = sequence.indexOf("ATG", index);
if (index == -1)
break;
int stop = findStopIndex(sequence, index + 3);
if (stop != sequence.length()) {
String gene = dna.substring(index, stop + 3);
store.add(gene);
//index = sequence.substring(index, stop + 3).length();
index = stop + 3; // start at the end of the stop codon
}else{ index = index + 3;
}
}
return store;//System.out.println(sequence);
}
public void testStorageFinder() {
DirectoryResource dr = new DirectoryResource();
StorageResource dnaStore = new StorageResource();
for (File f : dr.selectedFiles()) {
FileResource fr = new FileResource(f);
String s = fr.asString();
dnaStore = storeAll(s);
printGenes(dnaStore);
}
System.out.println("size = " + dnaStore.size());
}
public String readStrFromFile(){
FileResource readFile = new FileResource();
String DNA = readFile.asString();
//System.out.println("DNA: " + DNA);
return DNA;
}//end readStrFromFile() method;
public float calCGRatio(String gene){
gene = gene.toUpperCase();
int len = gene.length();
int CGCount = 0;
for(int i=0; i<len; i++){
if(gene.charAt(i) == 'C' || gene.charAt(i) == 'G')
CGCount++;
}//end for loop
System.out.println("CGCount " + CGCount + " Length: " + len + " Ratio: " + (float)CGCount/len);
return (float)CGCount/len;
}//end of calCGRatio() method;
public void printGenes(StorageResource sr){
//create a FindMultiGenesFile object FMG
FindMultiGenes5 FMG = new FindMultiGenes5();
//read a DNA sequence from file
String dna = FMG.readStrFromFile();
String geneList = FMG.storeAll(dna);
//store all genes into a document
StorageResource dnaStore = new StorageResource();
System.out.println("\n There are " + geneList.size() + " genes. ");
int longerthan60 = 0;
int CGGreaterthan35 = 0;
for(int i=0; i<geneList.size(); i++){
if(!dnaStore.contains(geneList.get(i)))
dnaStore.add(geneList.get(i));
if(geneList.get(i).length() > 60) longerthan60++;
if(FMG.calCGRatio(geneList.get(i)) > 0.35) CGGreaterthan35++;
}
System.out.println("dnaStore.size: " + dnaStore.size());
System.out.println("\n There are " + dnaStore.size() + " genes. ");
System.out.println("There are " + longerthan60 + " genes longer than 60.");
System.out.println("There are " + CGGreaterthan35 + " genes with CG ratio greater than 0.35.");
}//end main();
}
I found your post as I am also doing a similar course at Duke using those edu.duke libraries.
When I get that error message it is because I'm using the wrong method to access it.
Try FMD.data() to get an iterable of all of the gene strings.

How to parse a String into multiple arrays

Good day!
I am making a mini bookstore program and we are required to read a file based from what the customer buys on the specified counter as follows:
counter 4,book1 2,book2 2,book3 2,tender 100.00
counter 1,book1 2,book2 1,book3 3, book4 5,tender 200.00
counter 1,book3 1,tender 50.00
In short the format is:
COUNTER -> ITEMS BOUGHT -> TENDER
I tried doing this but it is not that efficient:
public List<String> getOrder(int i) {
List <String> tempQty = new ArrayList<String>();
String[] orders = orderList.get(0).split(",");
for (String order : orders) {
String[] fields = order.split(" ");
tempQty.add(fields[i]);
}
return tempQty;
}
How can i read the file and at the same time, ensures that I will put it on the correct array? Besides the counter and the tender, I need to know the name of the book and the qty so I could get its price and computer for the total price. Do I need to do multiple arrays to store each values? Any suggestions/ codes will be
highly appreciated.
Thank you.
Map<String, Integer> itemsBought = new HashMap<String, Integer>();
final String COUNTER = "counter";
final String TENDER = "tender";
String[] splitted = s.split(",");
for (String str : splitted) {
str = str.trim();
if (str.startsWith(COUNTER)) {
//do what you want with counter
} else if (str.startsWith(TENDER)) {
//do what you want with tender
} else {
//process items, e.g:
String[] itemInfo = str.split(" ");
itemsBought.put(itemInfo[0], Integer.valueOf(itemInfo[1]));
}
}
How about this? Here we have a class that is modeling a purchase, containing counter, tender and a list of the bought items. The bought item consists of an id (e.g. book1) and a quantity. Use the method readPurchases() to read the contents of a file and get a list of purchases.
Does this solve your problem?
public class Purchase {
private final int counter;
private final List<BoughtItem> boughtItems;
private final double tender;
public Purchase(int counter, List<BoughtItem> boughtItems, double tender) {
this.counter = counter;
this.boughtItems = new ArrayList<BoughtItem>(boughtItems);
this.tender = tender;
}
public int getCounter() {
return counter;
}
public List<BoughtItem> getBoughtItems() {
return boughtItems;
}
public double getTender() {
return tender;
}
}
public class BoughtItem {
private final String id;
private final int quantity;
public BoughtItem(String id, int quantity) {
this.id = id;
this.quantity = quantity;
}
public String getId() {
return id;
}
public int getQuantity() {
return quantity;
}
}
public class Bookstore {
/**
* Reads purchases from the given file.
*
* #param file The file to read from, never <code>null</code>.
* #return A list of all purchases in the file. If there are no
* purchases in the file, i.e. the file is empty, an empty list
* is returned
* #throws IOException If the file cannot be read or does not contain
* correct data.
*/
public List<Purchase> readPurchases(File file) throws IOException {
List<Purchase> purchases = new ArrayList<Purchase>();
BufferedReader lines = new BufferedReader(new FileReader(file));
String line;
for (int lineNum = 0; (line = lines.readLine()) != null; lineNum++) {
String[] fields = line.split(",");
if (fields.length < 2) {
throw new IOException("Line " + lineNum + " of file " + file + " has wrong number of fields");
}
// Read counter field
int counter;
try {
String counterField = fields[0];
counter = Integer.parseInt(counterField.substring(counterField.indexOf(' ') + 1));
} catch (Exception ex) {
throw new IOException("Counter field on line " + lineNum + " of file " + file + " corrupt");
}
// Read tender field
double tender;
try {
String tenderField = fields[fields.length - 1];
tender = Double.parseDouble(tenderField.substring(tenderField.indexOf(' ') + 1));
} catch (Exception ex) {
throw new IOException("Tender field on line " + lineNum + " of file " + file + " corrupt");
}
// Read bought items
List<BoughtItem> boughtItems = new ArrayList<BoughtItem>();
for (int i = 1; i < fields.length - 1; i++) {
String id;
int quantity;
try {
String bookField = fields[i];
id = bookField.substring(0, bookField.indexOf(' '));
quantity = Integer.parseInt(bookField.substring(bookField.indexOf(' ') + 1));
BoughtItem boughtItem = new BoughtItem(id, quantity);
boughtItems.add(boughtItem);
} catch (Exception ex) {
throw new IOException("Cannot read items from line " + lineNum + " of file " + file);
}
}
// We're done with this line!
Purchase purchase = new Purchase(counter, boughtItems, tender);
purchases.add(purchase);
}
return purchases;
}
}

JPA wrapper to convert unchecked exceptions into checked exceptions?

Before I wander off and re-create the wheel, does anyone know of a JPA wrapper that turns the unchecked exceptions JPA throws into checked exceptions?
Not looking for an argument about why I should not want checked exceptions, I do want them :-)
You can do 99% of rolling your own using the code below. It will leave you with two compile errors due to the members of a Collection needing to be encapsulated, but it does take you past the point where it is no longer worth automating.
package so;
import javax.persistence.*;
import java.io.File;
import java.io.FileWriter;
import java.lang.reflect.*;
public class CheckedPersistenceMaker {
static final String PACKAGE = "stackoverflow.javax.persistence";
static final String PACKAGE_DIR = PACKAGE.replace('.', '/');
static Class<?>[] CLASSES = new Class<?>[] { Cache.class,
EntityManager.class, EntityManagerFactory.class,
EntityTransaction.class, Parameter.class,
PersistenceUnitUtil.class, PersistenceUtil.class,
Persistence.class, Query.class, Tuple.class, TupleElement.class,
TypedQuery.class };
private static String getName(Class<?> c) {
String name = c.getName();
for(Class<?> p:CLASSES) {
if (p.equals(c))
return PACKAGE + ".Checked"
+ name.substring(name.lastIndexOf('.') + 1);
}
return c.getName();
}
static void generateWrapper(Class<?> c) throws Exception {
String name = c.getName();
TypeVariable<?>[] genType = c.getTypeParameters();
String varNames = "";
if (genType != null && genType.length != 0) {
StringBuilder b = new StringBuilder();
b.append("<");
for(int i = 0;i < genType.length;i++) {
if (i > 0) b.append(",");
b.append(genType[i].getName());
}
b.append(">");
varNames = b.toString();
}
name = "Checked" + name.substring(name.lastIndexOf('.') + 1);
File javaFile = new File(PACKAGE_DIR + "/" + name + ".java");
javaFile.getParentFile().mkdirs();
FileWriter w = new FileWriter(javaFile);
w.write("package " + PACKAGE + ";\n");
w.write("public class " + name + varNames + " {\n");
w.write(" private final " + c.getName() + varNames
+ " wrapped;\n\n ");
w.write(name + "(" + c.getName() + varNames
+ " original) {\nwrapped=original;\n}\n\n");
w.write(" public " + c.getName() + varNames
+ " getOriginal() { return wrapped; }\n\n");
Method[] ms = c.getDeclaredMethods();
for(Method m:ms) {
if (!Modifier.isPublic(m.getModifiers())) continue;
w.write(" ");
String s = m.toGenericString();
s = s.replace(" abstract ", " ");
s = s.replace(c.getName() + ".", "");
String q = s.substring(0, s.indexOf('('));
if (q.indexOf('<',10) != -1) q = q.substring(0, q.indexOf('<',10));
boolean needsTranslate = false;
for(Class<?> cc:CLASSES) {
String ccn = cc.getName();
if (q.indexOf(ccn) != -1) needsTranslate = true;
String ccc = ccn.replace(cc.getPackage().getName() + ".",
PACKAGE + ".Checked");
s = s.replace(ccn, ccc);
}
int pc = 0;
int p = s.indexOf('(');
if (s.charAt(p + 1) != ')') {
StringBuilder b = new StringBuilder(s);
int g = 0;
char ch;
do {
ch = b.charAt(p);
switch (ch) {
case '<': {
g++;
break;
}
case '>': {
g--;
break;
}
case ',':
case ')': {
if (g == 0) {
String pa = " p" + pc;
b.insert(p, pa);
pc++;
p += pa.length();
}
break;
}
}
p++;
} while( ch != ')' );
s = b.toString();
}
w.write(s);
w.write(" throws CheckedPersistenceException");
Class<?>[] excs = m.getExceptionTypes();
for(Class<?> e:excs) {
w.write(", " + e.getName());
}
w.write(" {\n try {\n ");
Class<?> ret = m.getReturnType();
if (!ret.equals(Void.TYPE)) {
w.write("return ");
if (needsTranslate) {
String retName = ret.getName();
retName = retName.replace(c.getPackage().getName() + ".",
PACKAGE + ".Checked");
w.write("new " + retName + "(");
}
}
if (Modifier.isStatic(m.getModifiers())) {
w.write(c.getName() + "." + m.getName() + "(");
} else {
w.write("wrapped." + m.getName() + "(");
}
Class<?> paramTypes[] = m.getParameterTypes();
for(int i = 0;i < pc;i++) {
if (i > 0) w.write(',');
boolean isChecked = false;
for(int j=0;j<CLASSES.length;j++) {
if( CLASSES[j].equals(paramTypes[i]) ) isChecked=true;
}
w.write("p" + i);
if(isChecked) w.write(".getOriginal()");
}
w.write(')');
if (needsTranslate) w.write(')');
w.write(";\n } catch ( javax.persistence.PersistenceException e ) { throw new CheckedPersistenceException(e); }\n }\n\n");
}
w.write("}\n");
w.close();
}
public static void main(String[] args) throws Exception {
for(Class<?> c:CLASSES) {
generateWrapper(c);
}
}
}

Categories

Resources