125 lines
9.3 KiB
HTML
125 lines
9.3 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>FD.java</title>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<style type="text/css">
|
|
<!--
|
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
|
.literal {color: #cc7832}
|
|
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
|
.string {color: #6a8759}
|
|
.number {color: #6897bb}
|
|
.ST0 {color: #9876aa}
|
|
.ST2 {color: #ffc66d}
|
|
.ST1 {color: #8a653b}
|
|
.whitespace {color: #505050}
|
|
.comment {color: #808080}
|
|
-->
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/FD.java</td></tr></table>
|
|
<pre>
|
|
<span class="literal">package</span> com.calebfontenot.mp5_calebfontenot;
|
|
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">ASDV2</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> <span class="literal">class</span> FD
|
|
{
|
|
|
|
<span class="literal">private</span> String <span class="ST0">lhs</span>;
|
|
|
|
<span class="literal">private</span> String <span class="ST0">rhs</span>;
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST1">lhs</span> <span class="comment">the</span> <span class="comment">LHS</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">FD</span>
|
|
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST1">rhs</span> <span class="comment">the</span> <span class="comment">RHS</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">FD</span>
|
|
<span class="comment"> * </span><span class="comment">@throws</span> <span class="comment">IllegalArgumentException</span> <span class="comment">if</span> <span class="comment">the</span> <span class="comment">length</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">LHS</span> <span class="comment">or</span> <span class="comment">the</span> <span class="comment">length</span>
|
|
<span class="comment"> * </span><span class="comment">of</span> <span class="comment">the</span> <span class="comment">RHS</span> <span class="comment">are</span> <span class="comment">less</span> <span class="comment">than</span><span class="comment"> 1 </span><span class="comment">or</span> <span class="comment">if</span> <span class="comment">they</span> <span class="comment">are</span> <span class="comment">null</span><span class="comment">.</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> FD(String lhs, String rhs)
|
|
<span class="literal">throws</span> IllegalArgumentException
|
|
{
|
|
<span class="literal">if</span> (lhs == <span class="literal">null</span> || rhs == <span class="literal">null</span> )
|
|
<span class="literal">throw</span> <span class="literal">new</span> IllegalArgumentException( <span class="string">"</span><span class="string">the LHS and/or RHS cannot be null.</span><span class="string">"</span>);
|
|
|
|
<span class="literal">if</span> (lhs.length() < <span class="number">1</span> || rhs.length() < <span class="number">1</span> )
|
|
<span class="literal">throw</span> <span class="literal">new</span> IllegalArgumentException( <span class="string">"</span><span class="string">the LHS and/or RHS cannot be of lenght less than 1.</span><span class="string">"</span>);
|
|
|
|
<span class="literal">this</span>.<span class="ST0">lhs</span> = lhs;
|
|
<span class="literal">this</span>.<span class="ST0">rhs</span> = rhs;
|
|
}
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">rhs</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="comment">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">rhs</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> String <span class="ST2">getRhs</span>()
|
|
{
|
|
<span class="literal">return</span> <span class="ST0">rhs</span>;
|
|
}
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">rhs</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST1">rhs</span> <span class="comment">new</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">rhs</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">setRhs</span>(String rhs)
|
|
{
|
|
<span class="literal">this</span>.<span class="ST0">rhs</span> = rhs;
|
|
}
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">lhs</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="comment">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">lhs</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> String <span class="ST2">getLhs</span>()
|
|
{
|
|
<span class="literal">return</span> <span class="ST0">lhs</span>;
|
|
}
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">lhs</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST1">lhs</span> <span class="comment">new</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">lhs</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">setLhs</span>(String lhs)
|
|
{
|
|
<span class="literal">this</span>.<span class="ST0">lhs</span> = lhs;
|
|
}
|
|
|
|
@Override
|
|
<span class="literal">public</span> String <span class="ST2">toString</span>()
|
|
{
|
|
<span class="literal">return</span> <span class="ST0">lhs</span> + <span class="string">"</span><span class="string"> -> </span><span class="string">"</span> + <span class="ST0">rhs</span>;
|
|
}
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> * </span><span class="comment">Decomposes</span> <span class="comment">the</span> <span class="comment">RHS</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">FD</span> <span class="comment">into</span> <span class="comment">singletons</span><span class="comment">.</span> <span class="comment">where</span> <span class="comment">the</span> <span class="comment">LHS</span> <span class="comment">is</span> <span class="comment">the</span> <span class="comment">same</span>
|
|
<span class="comment"> * </span><span class="comment">as</span> <span class="comment">this</span> <span class="comment">FD</span> <span class="comment">and</span> <span class="comment">the</span> <span class="comment">RHS</span> <span class="comment">is</span><span class="comment"> 1 </span><span class="comment">character</span> <span class="comment">of</span> <span class="comment">each</span> <span class="comment">character</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">FD</span><span class="comment">.</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="comment">@return</span> <span class="comment">array</span> <span class="comment">of</span> <span class="comment">FD</span> <span class="comment">he</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> FD[] <span class="ST2">decomposeRightHandSide</span>()
|
|
{
|
|
FD[] fdDecomosition = <span class="literal">new</span> FD[<span class="literal">this</span>.<span class="ST0">rhs</span>.length()];
|
|
|
|
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < <span class="literal">this</span>.<span class="ST0">rhs</span>.length(); ++i)
|
|
{
|
|
fdDecomosition[i] = <span class="literal">new</span> FD(<span class="literal">t</span><span class="literal">his</span>.<span class="ST0">lhs</span>, Character.<span class="ST3">toString</span>(<span class="ST0">r</span><span class="ST0">hs</span>.charAt(i)));
|
|
}
|
|
<span class="literal">return</span> fdDecomosition;
|
|
}
|
|
}
|
|
</pre></body>
|
|
</html>
|