Skip to content

Commit ab704b0

Browse files
author
Sergey Lukichev
committed
2 parents 660a0fb + 9992f9e commit ab704b0

41 files changed

Lines changed: 1080 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ImageProcessor2/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/bin/
2+
/out
3+
*.iml
4+
.idea
5+
.project
6+
.classpath
7+
/target/
8+
.idea
9+
*.iws
10+
*.ipr

ImageProcessor2/pom.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>de.telran</groupId>
8+
<artifactId>ImageProcessor3</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>junit</groupId>
15+
<artifactId>junit</artifactId>
16+
<version>4.12</version>
17+
<scope>test</scope>
18+
</dependency>
19+
20+
<dependency>
21+
<groupId>org.mockito</groupId>
22+
<artifactId>mockito-core</artifactId>
23+
<version>3.3.3</version>
24+
<scope>test</scope>
25+
</dependency>
26+
</dependencies>
27+
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-compiler-plugin</artifactId>
33+
<configuration>
34+
<source>1.8</source>
35+
<target>1.8</target>
36+
</configuration>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
</project>
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+
}

0 commit comments

Comments
 (0)