Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-20-2008, 11:06 PM
Member
 
Join Date: Mar 2008
Posts: 12
Rep Power: 0
sunjavaboy is on a distinguished road
Question System.out.println
Hello,

The java application I work on has thousands of System.out.println statements. Now I have to make all these S.o.p's execute only if a condition is true and restrict executing them if the condition is false.

I cannot put the check at all the places where S.o.p statement is written in the code. Can somebody suggest a way out where I can have one common method which I can replace it with all the S.o.p's in the application?

Any help would be appreciated.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 03-21-2008, 05:57 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 289
Rep Power: 3
roots is on a distinguished road
Default
System.setOut(PrintStream out)

or AOP
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-21-2008, 11:22 PM
Member
 
Join Date: Nov 2007
Posts: 3
Rep Power: 0
eljarrah is on a distinguished road
Default
hi sunjavaboy

You Can use Initialization Blocks

print one if statement

{
if (true)
}

like that


My Regards
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-22-2008, 02:30 AM
Member
 
Join Date: Feb 2008
Location: Oregon, USA
Posts: 48
Rep Power: 0
Bluefox815 is on a distinguished road
Default
If you still need help, perhaps it would be easier to see your posted code, or if you like your privacy, an example.

I would use for statements, like in the below code

Code:
/* place this code wherever is preferable, I apologize for any mistakes in my code */

// the total number of println statements, i used the name objects for MyPrintObject
int objects = 20;
// all the lines you don't want to print, I chose random numbers
int[] exceptions = {2, 5, 7, 15, 17}
// other variables
MyPrintObject[] p = new MyPrintObject[objects];
boolean makeTrue = true;

for (int i = 0; i <= objects; i++) {
makeTrue = true;
for (int x = 0; x <= totalExceptions; x++) {
if (i == exception[x]) // if this object is equal to one of the exceptions, make it false
makeTrue = false;
}
if (makeTrue)
p[i] = new MyPrintObject(true);
else
p[i] = new MyPrintObject(false);
}

// print objects
for (i = 0; i <= objects; i++) {
if (p[i].print()) // for information on the print() method, see below
System.out.println(i);
}
Here is an example of MyPrintObject

Code:
/* My very simple MyPrintObject class */

public class MyPrintObject {

private boolean print;

public MyPrintObject() {
print = true;
}

public MyPrintObject(boolean b) {
print = b;
}

public boolean print() {
return print;
}

}

Last edited by Bluefox815; 03-22-2008 at 02:33 AM.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Template for System.out.println eva Eclipse 3 01-05-2008 01:46 PM
shortcut of System.out.println() without netbeans VipinKeshri New To Java 1 11-18-2007 10:24 AM
Eclipse - shortcut to System.out.println Java Tip Java Tips 0 11-07-2007 05:21 PM
System.out.println shortcut ravian Eclipse 2 11-07-2007 11:17 AM
Help me with system.out.println baltimore New To Java 1 07-31-2007 09:30 PM


All times are GMT +2. The time now is 05:32 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org