Skip to content

Commit 566f206

Browse files
Merge branch 'master' into mavenized
2 parents f223308 + 6b47d58 commit 566f206

15 files changed

Lines changed: 350 additions & 0 deletions

ImageProcessor2/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
.idea
55
.project
66
.classpath
7+
/target/
8+
.idea
9+
*.iws
10+
*.ipr
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
action.names=GrayscaleImageAction,DefaultImageAction,PreviewImageAction,NewImageAction
2+
action.package=de.telran.processor.action
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package de.telran.processor;
2+
3+
import de.telran.processor.entity.DownloadedImage;
4+
import de.telran.processor.entity.ImageDescriptor;
5+
import de.telran.processor.service.DownloadService;
6+
import de.telran.processor.service.FileService;
7+
8+
import java.util.List;
9+
import java.util.stream.Collectors;
10+
11+
public class ImageProcessor {
12+
13+
private FileService fileService;
14+
private DownloadService downloadService;
15+
16+
public static void main(String[] args) {
17+
18+
String csvFile = args[0];
19+
20+
FileService fs = new FileService();
21+
DownloadService ds = new DownloadService();
22+
ImageProcessor processor = new ImageProcessor(fs, ds);
23+
processor.process(csvFile);
24+
25+
}
26+
27+
public ImageProcessor(FileService fileService, DownloadService downloadService) {
28+
this.fileService = fileService;
29+
this.downloadService = downloadService;
30+
}
31+
32+
public void process(String fileName) {
33+
//main logic is here
34+
35+
List<ImageDescriptor> imageDescriptors = fileService.readImageDescriptors(fileName);
36+
37+
List<DownloadedImage> downloadedImages = downloadService.downloadImages(imageDescriptors);
38+
39+
List<DownloadedImage> successfullyDownloadedimages = downloadedImages
40+
.stream()
41+
.filter(DownloadedImage::isSuccessful)
42+
.collect(Collectors.toList());
43+
44+
45+
46+
//try {
47+
// DownloadService ds = new Downloadservice();
48+
// List<DownloadedImage> downloadedImages = ds.downloadImages(images);
49+
//}
50+
51+
52+
}
53+
54+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package de.telran.processor.action;
2+
3+
import java.awt.image.BufferedImage;
4+
5+
public class DefaultImageAction implements ImageAction {
6+
7+
@Override
8+
public String getName() {
9+
return "DEFAULT";
10+
}
11+
12+
@Override
13+
public BufferedImage doAction(BufferedImage image) throws Exception {
14+
System.out.println("default action");
15+
throw new Exception("Action not supported");
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package de.telran.processor.action;
2+
3+
import java.awt.image.BufferedImage;
4+
5+
public class GrayscaleImageAction implements ImageAction {
6+
@Override
7+
public String getName() {
8+
return "GRAYSCALE";
9+
}
10+
11+
@Override
12+
public BufferedImage doAction(BufferedImage image) throws Exception {
13+
System.out.println("Grayscaling an image");
14+
//tranformation
15+
return null;
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package de.telran.processor.action;
2+
3+
import java.awt.image.BufferedImage;
4+
5+
public interface ImageAction {
6+
String getName();
7+
BufferedImage doAction(BufferedImage image) throws Exception;
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package de.telran.processor.action;
2+
3+
import java.awt.image.BufferedImage;
4+
5+
public class NewImageAction implements ImageAction {
6+
@Override
7+
public String getName() {
8+
return "NEW ACTION";
9+
}
10+
11+
@Override
12+
public BufferedImage doAction(BufferedImage image) throws Exception {
13+
System.out.println("executing new action");
14+
return image;
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package de.telran.processor.action;
2+
3+
import java.awt.image.BufferedImage;
4+
5+
public class PreviewImageAction implements ImageAction {
6+
@Override
7+
public String getName() {
8+
return "PREVIEW";
9+
}
10+
11+
@Override
12+
public BufferedImage doAction(BufferedImage image) throws Exception {
13+
System.out.println("Generating a preview");
14+
return null;
15+
}
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package de.telran.processor.entity;
2+
3+
import java.awt.image.BufferedImage;
4+
5+
public class DownloadedImage {
6+
private BufferedImage image;
7+
private boolean isSuccessful;
8+
private ImageDescriptor descriptor;
9+
10+
public DownloadedImage(BufferedImage image, boolean isSuccessful, ImageDescriptor descriptor) {
11+
this.image = image;
12+
this.isSuccessful = isSuccessful;
13+
this.descriptor = descriptor;
14+
}
15+
16+
public BufferedImage getImage() {
17+
return image;
18+
}
19+
20+
public boolean isSuccessful() {
21+
return isSuccessful;
22+
}
23+
24+
public ImageDescriptor getDescriptor() {
25+
return descriptor;
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package de.telran.processor.entity;
2+
3+
public class ImageDescriptor {
4+
private String imageURL;
5+
private String actionName;
6+
7+
public ImageDescriptor(String imageURL, String actionName) {
8+
this.imageURL = imageURL;
9+
this.actionName = actionName;
10+
}
11+
12+
public String getImageURL() {
13+
return imageURL;
14+
}
15+
16+
public String getActionName() {
17+
return actionName;
18+
}
19+
20+
@Override
21+
public String toString() {
22+
return "ImageDescriptor{" +
23+
"imageURL='" + imageURL + '\'' +
24+
", actionName='" + actionName + '\'' +
25+
'}';
26+
}
27+
}

0 commit comments

Comments
 (0)