Project 1 Diagram
Here is a simplified class diagram for Project 1.
The diagram shows five classes: Driver, FileAnalysis, TokenAnalyzer (an interface), FileSummaryAnalyzer, and DistinctTokensAnalyzer. FileAnalysis uses both analyzer classes. Both analyzer classes implement the TokenAnalyzer interface.
Reading This Diagram
If UML class diagrams are new to you, that is completely fine. The section below explains the notation used here. For more guidance, including a labeled anatomy diagram, see the Project 1 Plan page.
Visibility symbols
+means the method or variable is public (accessible from other classes)-means the method or variable is private (accessible only within the same class)
Method notation
+ methodName(parameterName : ParameterType) : ReturnType
Example: + processToken(token : String) : void means a public method named processToken that takes one String parameter and returns nothing (void).
Instance variable notation
- variableName : Type
Example: - totalTokensCount : int means a private instance variable named totalTokensCount of type int.
Relationships
- A line with an open arrow from Class A to Class B means Class A uses Class B (holds a reference to it).
- A dashed line with a different arrowhead from Class A to an interface means Class A implements that interface.
Class Reference
This section describes every class shown in the diagram. Use it as a planning reference as you work through the Project 1 Plan.
Driver
Purpose:
Entry point for the program. Instantiates FileAnalysis and starts the analysis by calling analyze().
Public Methods:
+ main(arguments : String[]) : void
Instance Variables: None.
Relationships:
Creates and uses FileAnalysis.
FileAnalysis
Purpose: The main controller for the project. Opens the input file, reads each line, splits lines into tokens, passes tokens to the analyzers, and triggers output file generation.
Public Methods:
+ analyze(arguments : String[]) : void
Instance Variables:
- summaryAnalyzer : FileSummaryAnalyzer
- distinctAnalyzer : DistinctTokensAnalyzer
- VALID_ARGS : int (constant, written in ALL_CAPS because it never changes)
Relationships:
Uses FileSummaryAnalyzer and DistinctTokensAnalyzer. The diagram shows instance variables pointing to each analyzer class.
TokenAnalyzer
Purpose:
An interface that defines the two methods every analyzer class must implement. It establishes a shared contract so that FileAnalysis can work with any analyzer the same way.
Methods Defined by This Interface:
+ processToken(token : String) : void
+ generateOutputFile(inputFilePath : String, outputFilePath : String) : void
Instance Variables: None. Interfaces do not hold data.
Relationships:
Implemented by FileSummaryAnalyzer and DistinctTokensAnalyzer.
FileSummaryAnalyzer
Purpose:
Counts the total number of tokens found in the input file and writes the summary report to summary.txt.
Public Methods:
+ processToken(token : String) : void
+ generateOutputFile(inputFilePath : String, outputFilePath : String) : void
+ getTotalTokensCount() : int
Instance Variables:
- totalTokensCount : int
Relationships:
Implements TokenAnalyzer. Referenced by FileAnalysis through the summaryAnalyzer instance variable.
DistinctTokensAnalyzer
Purpose:
Tracks all unique tokens found in the input file and writes them to distinct_tokens.txt. If a token appears more than once, it is only stored once.
Public Methods:
+ processToken(token : String) : void
+ generateOutputFile(inputFilePath : String, outputFilePath : String) : void
+ getDistinctTokens() : Set<String>
Instance Variables:
- distinctTokens : Set<String>
The constructor creates a TreeSet and assigns it to distinctTokens. A TreeSet automatically keeps tokens in alphabetical order and ignores duplicates.
Relationships:
Implements TokenAnalyzer. Referenced by FileAnalysis through the distinctAnalyzer instance variable.