forked from DavidMatuszek/SentenceGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleDefinition.java
More file actions
executable file
·43 lines (40 loc) · 1.37 KB
/
SingleDefinition.java
File metadata and controls
executable file
·43 lines (40 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package sentenceGenerator;
import java.util.ArrayList;
/**
* An <code>SingleDefinition</code> is one of the alternatives in a
* <code>ListOfDefinitions</code> object.
* It consists of one definition (a sequence of terminals and/or
* nonterminals) with no <code>'|'</code> symbols, not including the
* thing being defined (the "definiendum"). For example, given the rule</br></br>
* <verb phrase> ::= <intransitive verb> | <transitive verb> <noun phrase><br /></br>
* then <intransitive verb> is a SingleDefinition, and so is
* <transitive verb> <noun phrase>.
*
* @author <Rajveer Parikh>
*/
public class SingleDefinition extends ArrayList<String> {
/**
* Constructs an empty <code>SingleDefiniton</code> object; terms can be
* added to it via the inherited <code>ArrayList.add(String)</code> method.
*/
SingleDefinition() {}
/**
* Returns a String consisting of the elements of this
* <code>ArrayList</code>, separated by spaces.
*
* @see java.util.AbstractCollection#toString()
*/
@Override
public String toString() {
String result = "";
for (int i = 0; i < this.size(); i++){
if (i == this.size() -1){
result += this.get(i);
}
else{
result += this.get(i) + " ";
}
}
return result;
}
}