-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthor.java
47 lines (45 loc) · 1.1 KB
/
Author.java
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
44
45
46
47
import java.util.*;
public class Author implements Comparable<Author>
{
private int numOfPublications;
private Set<String> names; /*!< This set contains all the names of the author */
/*!
* Constructor
*/
public Author()
{
this.names = new HashSet<String>(); /*!< Hash Set initialized */
this.numOfPublications = 0;
}
/*!
* Getter Methods
*/
void addAuthorName(String name){ this.names.add(name); }
int getNumOfPublications() { return this.numOfPublications; }
String getName()
{
String name = this.names.iterator().next().toString();
if(name != null)
return name;
else
return "";
}
Set<String> getNames(){ return this.names; }
/*!
* Increments the Number of publications by one.
*/
void incrementPub(){
this.numOfPublications += 1; }
/*!
* Returns the names of the Author
*/
public String toString(){
return getName();}
/*!
* Comparator function to compare the number of Publications
*/
public int compareTo(Author a)
{
return Integer.valueOf(this.numOfPublications).compareTo(a.numOfPublications);
}
}