-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPictureHolder.java
More file actions
94 lines (82 loc) · 2.38 KB
/
PictureHolder.java
File metadata and controls
94 lines (82 loc) · 2.38 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
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
public class PictureHolder {
ArrayList<Image> mImages;
Map<String, Set<Image>> mTags;
public static PictureHolder make_Holder(String path) throws IOException {
ArrayList<Image> pictures = new ArrayList<>();
BufferedReader in = new BufferedReader(new FileReader(path));
int i = Integer.parseInt(in.readLine());
int id=0;
while(i>0){
i--;
String[] line =in.readLine().split(" ");
boolean isHorizontal = line[0].equals("H");
int tagC = Integer.parseInt(line[1]);
Set<String> tags= Set.of(Arrays.copyOfRange(line,2,2+tagC));
pictures.add(new Image(tags,!isHorizontal,id));
id++;
}
return new PictureHolder(pictures);
}
public PictureHolder(ArrayList<Image> images) {
mTags = new HashMap<>();
mImages = images;
initTags();
}
private void initTags() {
for (Image i : mImages) {
for (String tag : i.tags) {
mTags.computeIfAbsent(tag, (t -> new HashSet<Image>()));
mTags.get(tag).add(i);
}
}
}
public Set<Image> get(String tag){
return mTags.get(tag);
}
public int getCount(String tag){
int count =0;
for (Image img:mTags.get(tag)) {
if(!img.isUsed && !img.isVertical)
count++;
}
return count;
}
public Set<Image> getLSet(){
int m_Count =-1;
Set<Image> s = null;
for(String tag:mTags.keySet()){
int c = getCount(tag);
if(c>m_Count)
{
m_Count=c;
s=get(tag);
}
}
return s;
}
public static Image getMaxTags(Set<Image> images){
Image i=null;
int c =-1;
for (Image img:images) {
if(!img.isUsed&&!img.isVertical)
if(img.tags.size()>c){
c=img.tags.size();
i=img;
}
}
return i;
}
Random random = new Random();
public Image getRVI() {
Image m;
do{
m=mImages.get(random.nextInt(mImages.size()));
}while (m!=null && !m.isUsed && m.isVertical);
return m;
}
}