Repository navigation
Expand file tree
/
Copy pathAutoRecommender.java
More file actions
84 lines (75 loc) · 2.5 KB
/
Copy pathAutoRecommender.java
File metadata and controls
84 lines (75 loc) · 2.5 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
import javax.swing.*;
import java.awt.*;
public class AutoRecommender extends Component
{
int[] tree;
int[] features;
JComboBox<String> cmbUse = new JComboBox<>(Globals.USAGE);
JComboBox<String> cmbPC = new JComboBox<>(Globals.PC);
//-----------------------------------------------------------------------------------------------------------
/*
This is the auto recommender constructor
Input: file size
Output: None
*/
public AutoRecommender(int size)
{
this.tree = new int[] {0,1,500,1,1,-1,-4,-5,0,-2,0,-2,-3,-2, 0};
this.features = new int[] {0, size, 0};
AddInputEvents();
}
//-----------------------------------------------------------------------------------------------------------
/*
This function shows popup form which gets relevant data from user in order to encrypt
Input: None
Output: form exit code - OK / Cancel
*/
public int showForm()
{
Object[] inputFields = {"Usage Type: ", cmbUse, "PC Strength: ", cmbPC};
return JOptionPane.showConfirmDialog(this, inputFields, "Auto Recommender", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
}
//-----------------------------------------------------------------------------------------------------------
/*
This function iterates through the decision tree (heap)
Input: tree index and features index
Output: index of the recommended encryption
*/
public int recommend(int tindex, int findex)
{
if(features[0] == 1 && findex == 1)
{
findex = 2;
}
// If done
if(tree[tindex] <= 0)
{
return tree[tindex] * -1;
}
if(features[findex] >= tree[tindex])
{
return recommend(2 * tindex + 1, findex + 1);
}
else
{
return recommend(2 * tindex, findex + 1);
}
}
//-----------------------------------------------------------------------------------------------------------
/*
This function appends events to the popup form
Input: None
Output: None
*/
private void AddInputEvents()
{
cmbUse.addActionListener( e ->
this.features[0] = cmbUse.getSelectedIndex());
cmbPC.addActionListener( e ->
this.features[2] = cmbPC.getSelectedIndex());
}
}
/*
* Enterprise - File size - PC power
* Home - PC Power
* */