Browse Source
Added a controll to the commandline. Tweaked a few other portions of the code. Need to fix that part where everything is printed to the console when running AppCLI
master
Added a controll to the commandline. Tweaked a few other portions of the code. Need to fix that part where everything is printed to the console when running AppCLI
master
Drew Short
11 years ago
5 changed files with 75 additions and 10 deletions
-
51src/main/java/com/sothr/imagetools/AppCLI.java
-
1src/main/java/com/sothr/imagetools/AppConfig.java
-
15src/main/scala/com/sothr/imagetools/Engine.scala
-
17src/main/scala/com/sothr/imagetools/image/ImageCache.scala
-
1src/main/scala/com/sothr/imagetools/util/PropertiesService.scala
@ -1,20 +1,59 @@ |
|||||
package com.sothr.imagetools; |
package com.sothr.imagetools; |
||||
|
|
||||
|
import com.sothr.imagetools.image.ImageCache; |
||||
|
import com.sothr.imagetools.image.SimilarImages; |
||||
|
import org.apache.commons.cli.BasicParser; |
||||
|
import org.apache.commons.cli.CommandLine; |
||||
|
import org.apache.commons.cli.CommandLineParser; |
||||
|
import org.apache.commons.cli.Options; |
||||
|
import org.apache.commons.cli.Option; |
||||
import org.slf4j.Logger; |
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
import org.slf4j.LoggerFactory; |
||||
|
import scala.collection.immutable.List; |
||||
|
|
||||
|
import java.text.ParseException; |
||||
|
|
||||
/** |
/** |
||||
* CLI interface for Image Tools |
* CLI interface for Image Tools |
||||
*/ |
*/ |
||||
class AppCLI { |
class AppCLI { |
||||
|
|
||||
private static Logger logger; |
|
||||
|
private static Logger logger; |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
AppConfig.configureApp(); |
||||
|
logger = LoggerFactory.getLogger(AppCLI.class); |
||||
|
logger.info("Started Image Tools CLI"); |
||||
|
try { |
||||
|
Options options = getOptions(); |
||||
|
CommandLineParser parser = new BasicParser(); |
||||
|
CommandLine cmd = parser.parse(options, args); |
||||
|
process(cmd); |
||||
|
} catch (Exception ex) { |
||||
|
logger.error("Unhandled exception in AppCLI", ex); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static Options getOptions() { |
||||
|
Options options = new Options(); |
||||
|
options.addOption(new Option("s", true, "scan directories for a list of similar images")); |
||||
|
return options; |
||||
|
} |
||||
|
|
||||
public static void main(String[] args) { |
|
||||
AppConfig.configureApp(); |
|
||||
logger = LoggerFactory.getLogger(AppCLI.class); |
|
||||
logger.info("Started Image Tools CLI"); |
|
||||
System.out.println("Hello World"); |
|
||||
|
private static void process(CommandLine cmd) { |
||||
|
//scan a comma separated list of paths to search for image similarities |
||||
|
Engine engine = new Engine(new ImageCache()); |
||||
|
if (cmd.hasOption('s')) { |
||||
|
String scanList = cmd.getOptionValue('s'); |
||||
|
String[] paths = scanList.split(","); |
||||
|
for (String path : paths) { |
||||
|
List<SimilarImages> similarImages = engine.getSimilarImagesForDirectory(path); |
||||
|
for (int index = 0; index < similarImages.length(); index++) { |
||||
|
SimilarImages similar = similarImages.apply(index); |
||||
|
System.out.println(similar.toString()); |
||||
|
} |
||||
|
} |
||||
} |
} |
||||
|
} |
||||
|
|
||||
} |
} |
@ -0,0 +1,17 @@ |
|||||
|
package com.sothr.imagetools.image |
||||
|
|
||||
|
import scala.collection.mutable |
||||
|
|
||||
|
/** |
||||
|
* Created by drew on 1/26/14. |
||||
|
*/ |
||||
|
class ImageCache { |
||||
|
|
||||
|
private val cache = new mutable.HashMap[String, Image]() |
||||
|
|
||||
|
def contains(imagePath:String) = cache.contains(imagePath) |
||||
|
def get(imagePath:String) = cache(imagePath) |
||||
|
def add(imagePath:String, image:Image) = cache.put(imagePath,image) |
||||
|
def size:Int = cache.size |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue