-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttributes.java
More file actions
107 lines (95 loc) · 2.2 KB
/
Copy pathAttributes.java
File metadata and controls
107 lines (95 loc) · 2.2 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
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
import java.util.ArrayList;
import java.util.Scanner;
public class Attributes {
private java.util.ArrayList<Attribute> attributes= new ArrayList<Attribute>();
public int classIndex;//default
private boolean hasNominalAttributes = false;
private boolean hasNumericAttributes = false;
public Attributes(Scanner temp) throws Exception {
initialize();
parse(temp);
}
public Attributes() {
// TODO Auto-generated constructor stub
}
void add(Attribute attribute)
{
attributes.add(attribute);
classIndex=this.attributes.size()-1;// update the classIndex everytime when add a new attribute
if(attribute.whatAttribute().compareTo("Nominal")==0)
hasNominalAttributes = true;
else
hasNumericAttributes = true;
}
void add(int index, Attribute attribute)
{
this.attributes.add(index, attribute);
classIndex=this.attributes.size()-1;// update the classIndex everytime when add a new attribute
}
Attribute get(int i)
{
return this.attributes.get(i);
}
Attribute getClassAttribute() throws Exception
{
//
return this.get(classIndex);
}
int getClassIndex()
{
return classIndex;
}
int getSize()
{
return attributes.size();
}
int getIndex(String name)
{
//写
for(int i=0;i<attributes.size();i++)
{
if(attributes.get(i).name.compareTo(name)==0)
return i;
}
return -1;
}
private void initialize()
{
}
private void parse(Scanner scanner) throws Exception
{
//Parses the attribute declarations in the specified scanner.
scanner.useDelimiter("\n");
Attribute tem = new Attribute();
while(scanner.hasNext())
{
String s = scanner.next();
Scanner temp = new Scanner(s);
tem=AttributeFactory.make(temp);
this.attributes.add(tem);
}
classIndex=this.attributes.size()-1;
}
public String toString()
{
String output="";
for( int i=0;i<attributes.size();i++ )
{
output+=attributes.get(i).toString();
}
return output;
}
public void setClassIndex(int classIndex)
throws java.lang.Exception
{
this.classIndex=classIndex;
}
public boolean getHasNumericAttributes()
{
return hasNumericAttributes;
}
public boolean getHasNominalAttributes()
{
return hasNominalAttributes;
}
}