UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.metrics
Class CodeCounter

java.lang.Object
  |
  +--edu.berkeley.guir.lib.metrics.CodeCounter

public class CodeCounter
extends Object

Runs some simple metrics on your code, like number of methods, number of logical lines of code, etc.

This software is distributed under the Berkeley Software License.

 Revisions:  - GUIRLib-v1.0-1.0.0, Apr 15 1997, JH
               Created class
             - GUIRLib-v1.2-1.0.0, Jun 22 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.3-1.0.0, Aug 11 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.4-1.0.0, Aug 31 2000, JH
               Touched for GUIRLib release
 

Version:
GUIRLib-v1.4-1.0.0, Aug 31 2000
Author:
Jason Hong ( jasonh@cs.berkeley.edu)

Field Summary
static String BEGIN_TOKEN
           
static String COMMENT_BEGIN
           
static String COMMENT_CONTINUE
           
static String COMMENT_END
           
static String COMMENT_EOLN
           
static String END_TOKEN
           
static int METHOD_DEPTH
           
static String STATEMENT_END
           
 
Constructor Summary
CodeCounter(String strFileName)
          Constructor.
 
Method Summary
static int countOccurrencesOfCharacter(char chSearch, String strLine)
          Count the number of occurrences of a character in a String.
static int countOccurrencesOfString(String strSearch, String strLine)
          Count the number of occurrences of a String in a String.
 int getLinesOfComments()
          Get the number of lines of comments in the source code.
 int getLinesOfLogicalCode()
          Get the number of lines of logical code in the source code.
 int getLinesOfPhysicalCode()
          Get the number of lines of physical code in the source code.
 int getNumMethods()
          Get the number of methods in the source code.
static void main(String[] argv)
           
static String removeSubstring(char chFrom, char chTo, String strLine)
          Remove all characters from a String starting from the first location of one character to the first location of another character.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BEGIN_TOKEN

public static final String BEGIN_TOKEN

END_TOKEN

public static final String END_TOKEN

COMMENT_EOLN

public static final String COMMENT_EOLN

COMMENT_BEGIN

public static final String COMMENT_BEGIN

COMMENT_CONTINUE

public static final String COMMENT_CONTINUE

COMMENT_END

public static final String COMMENT_END

STATEMENT_END

public static final String STATEMENT_END

METHOD_DEPTH

public static final int METHOD_DEPTH
Constructor Detail

CodeCounter

public CodeCounter(String strFileName)
Constructor.
Parameters:
strFilename - is the name of the file to open.
Method Detail

countOccurrencesOfCharacter

public static int countOccurrencesOfCharacter(char chSearch,
                                              String strLine)
Count the number of occurrences of a character in a String.
Parameters:
chSearch - is the character to search for.
strLine - is the String to search through.
Returns:
The number of times the character was found in the String.

countOccurrencesOfString

public static int countOccurrencesOfString(String strSearch,
                                           String strLine)
Count the number of occurrences of a String in a String.
Parameters:
strSearch - is the String to search for.
strLine - is the String to search through.
Returns:
The number of times the character was found in the String.

removeSubstring

public static String removeSubstring(char chFrom,
                                     char chTo,
                                     String strLine)
Remove all characters from a String starting from the first location of one character to the first location of another character.
Parameters:
chFrom - is the character to start deleting from.
chTo - is the character to end deleting.
strLine - is the String to remove characters from.
Returns:
A String with characters removed, unmodified if the delimiting characters do not exist in the String.

getLinesOfComments

public int getLinesOfComments()
Get the number of lines of comments in the source code.
Returns:
The number of lines of comments.

getLinesOfLogicalCode

public int getLinesOfLogicalCode()
Get the number of lines of logical code in the source code.
Returns:
The number of lines of logical code.

getLinesOfPhysicalCode

public int getLinesOfPhysicalCode()
Get the number of lines of physical code in the source code.
Returns:
The number of lines of physical code.

getNumMethods

public int getNumMethods()
Get the number of methods in the source code.
Returns:
The number of lines of physical code.

toString

public String toString()
Overrides:
toString in class Object

main

public static void main(String[] argv)

Copyright Information