Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-20-2008, 11:06 PM
Member
 
Join Date: Mar 2008
Posts: 8
sunjavaboy is on a distinguished road
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
Sponsored Links
  #2 (permalink)  
Old 03-21-2008, 05:57 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 251
roots is on a distinguished road
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
eljarrah is on a distinguished road
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: 24
Bluefox815 is on a distinguished road
Send a message via MSN to Bluefox815
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
Sponsored Links
Reply


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

vB 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 +3. The time now is 01:06 PM.


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