root/trunk/src/java/org/jcoderz/guidelines/snippets/JCoderZJavaExample.java

Revision 1011, 4.8 kB (checked in by amandel, 4 years ago)

Aligned svn keyword settings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 *
4 * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *    * Redistributions of source code must retain the above copyright
11 *      notice, this list of conditions and the following disclaimer.
12 *    * Redistributions in binary form must reproduce the above
13 *      copyright notice, this list of conditions and the following
14 *      disclaimer in the documentation and/or other materials
15 *      provided with the distribution.
16 *    * Neither the name of the jCoderZ.org Project nor the names of
17 *      its contributors may be used to endorse or promote products
18 *      derived from this software without specific prior written
19 *      permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33package org.jcoderz.guidelines.snippets;
34
35
36import java.util.logging.Level;
37import java.util.logging.Logger;
38
39
40/**
41 * Class description goes here.
42 * @author Firstname Lastname
43 */
44public class JCoderZJavaExample
45{
46    /* A class implementation comment can go here. */
47
48    /** MIN_WIDTH documentation comment. */
49    public static final int MIN_WIDTH = 4;
50
51    /** MAX_WIDTH documentation comment. */
52    public static final int MAX_WIDTH = 999;
53
54    /** BAD_PARAM documentation comment. */
55    public static final int BAD_PARAM = -1;
56
57    /** INTERNAL_ERROR documentation comment. */
58    public static final int INTERNAL_ERROR = -2;
59
60    /** classVar1 documentation comment. */
61    protected static int sClassVar1;
62
63    /**
64     * The logger.
65     */
66    private static final Logger logger =
67            Logger.getLogger(JCoderZJavaExample.class.getName());
68
69    private static final String CLASS_NAME = "JCoderZJavaExample";
70
71    /**
72     * classVar2 documentation comment that happens to be more than one
73     * line long.
74     */
75    private static Object sClassVar2;
76
77    /** instanceVar2 documentation comment. */
78    protected int mInstanceVar2;
79
80    /** instanceVar3 documentation comment. */
81    private Object[] mInstanceVar3;
82
83    /**
84     * ... Constructor blah documentation comment...
85     */
86    public JCoderZJavaExample ()
87    {
88        // ...implementation goes here...
89        if (logger.isLoggable(Level.FINER))
90        {
91            logger.finer("Sample constructor " + this);
92        }
93    }
94
95    /**
96     * ... method doSomething documentation comment...
97     */
98    public final void setupConfiguration ()
99    {
100        // write message to log
101        logger.info("Message");
102    }
103
104    /**
105     * ... method doSomething documentation comment...
106     */
107    public void doSomething ()
108    {
109        // ...implementation goes here...
110    }
111
112    /**
113     * ...method doSomethingElse documentation comment...
114     * @param someParam this is the input parameter
115     * @return result The method returns an int.
116     */
117    public int doSomethingElse (Object someParam)
118    {
119        int result = BAD_PARAM;
120
121        if (logger.isLoggable(Level.FINER))
122        {
123            logger.entering(CLASS_NAME, "doSomethingElse",
124                    new Object[] {someParam});
125        }
126
127        // ...implementation goes here...
128        if (BAD_PARAM == result)
129        {
130            final RuntimeException ex
131                    = new RuntimeException("Bad parameter");
132            if (logger.isLoggable(Level.FINER))
133            {
134                logger.throwing(CLASS_NAME, "doSomethingElse", ex);
135            }
136            throw ex;
137        }
138        try
139        {
140            result = doSometingFine();
141        }
142        catch (Throwable th)
143        {
144            result = INTERNAL_ERROR;
145        }
146
147        // FIXME: finally must log exiting() function
148        if (logger.isLoggable(Level.FINER))
149        {
150            logger.exiting(CLASS_NAME, "doSomethingElse", 
151                    new Integer(result));
152        }
153        return result;
154    }
155
156    /**
157     * Method doSomethingElse documentation comment.
158     * @return result The method returns an int.
159     */
160    private int doSometingFine ()
161    {
162        // ...implementation goes here...
163        return 0;
164    }
165
166}
Note: See TracBrowser for help on using the browser.