-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAuthor.java
194 lines (178 loc) · 4.01 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//import javax.print.attribute.standard.PrinterMessageFromOperator;
//
//import com.sun.org.apache.bcel.internal.generic.RETURN;
//
//import jdk.internal.org.objectweb.asm.tree.analysis.Value;
//
//import java.awt.print.Printable;
import java.util.*;
//! Author Class
/*!
Used for storing Authors, their aliases and no of publications which are initialized through respective Query functions
*/
public class Author {
private static ArrayList<Author> person= new ArrayList<Author>();/*!< private member used to store the author references which gets initialized by class Entity Resolver */
/**
* Adds the input person to the person records {@code (temp)}.
*
* @param temp the values of the author variable to be added
*/
public static void add_person(Author temp)
{
person.add(temp);
}
//! A static member for entirely resetting the database of authors. Used at start to reset and intitalise
/*!
*/
public static void reset_person()
{
person=new ArrayList<Author>();
}
//! A static member for referencing kth position of ArrayList
/*!
\@param k an integer argument.
\return The author reference at k th position of arraylist
*/
public static Author ret_person(int k)
{
return person.get(k);
}
//! A static member taking one argument String as input and returning boolean value whether it is present or not
/*!
\param name is a String argument
\return if present
*/
public static Boolean find_person(String name)
{
Boolean truth_Value =false;
for(Author a: person)
{
if(a.if_present(name))
{
truth_Value=true;
break;
}
}
return truth_Value;
}
//! A static member returning entire ArrayList
/*!
*/
public static ArrayList<Author> ret_persons()
{
return person;
}
//! A static member taking one argument String as input and returning Autho reference
/*!
\@param name is String argument.
\return The author reference else null.
*/
public static Author find_person_ret_author(String name)
{
for(Author a: person)
{
if(a.if_present(name))
{
return a;
}
}
return null;
}
//redundant operations for testing only: start
public static int ret_total_no_of_distinct_authors()
{
if(person!=null)
return person.size();
return -1;
}
public static int ret_total_no_of_authors_names()
{int sum=0;
if(person!=null)
{
for(Author a : person)
{
sum+=(a.ret_aliases()).size();
}
return sum;
}
return -1;
}
public static void search_by_key(String s)
{
for(Author a:person)
{
if(a.ret_key().equals(s))
{
a.print_author();
}
}
}
//end
//data stored in Author variable : start
private ArrayList<String> aliases;
private int no_of_publications;
private String key;
//end
//Standard set, get and print Operations performed on Author variable : start
public String ret_key()
{
return key;
}
public int ret_no_of_publications()
{
return no_of_publications;
}
public void set_key(String s)
{
key=s;
}
public void print_author()
{
System.out.println("Authors:");
for(String a:aliases)
{
System.out.println(a);
}
}
//end
//!Constructor for Author
/*!
Initializing variables to valid values
*/
public Author()
{
aliases= new ArrayList<String>();
no_of_publications=0;
}
//Standard Operations performed on Author variable members : start
public void increment_no_of_publications(int i)
{
no_of_publications+=i;
}
public ArrayList<String> ret_aliases()
{
return aliases;
}
public void add_name(String nm)
{
if(!if_present(nm))
{
aliases.add(nm);
}
}
public Boolean if_present(String nm)
{
for(String s:aliases)
{
if(s.equals(nm))
{
return true;
}
}
return false;
}
public String ret_name() {
return aliases.get(0);
}
//end
}