소스 검색

some final fixes before the project is dead

Phil 7 년 전
부모
커밋
a8e390f5d7
3개의 변경된 파일114개의 추가작업 그리고 15개의 파일을 삭제
  1. 1 5
      MovieDB/src/logic/Recomendations.java
  2. 112 9
      MovieDB/src/main/ConsoleReader.java
  3. 1 1
      MovieDB/src/main/Main.java

+ 1 - 5
MovieDB/src/logic/Recomendations.java

@@ -23,12 +23,8 @@ public class Recomendations {
 			limit = 200;
 		ArrayList<Movie> out = new ArrayList<>();
 		for(Movie m : db.getMovies()) {
-			System.out.println("comparing "+m.getTitle()+" and "+a.getName());
 			if(m.getActors().contains(a)) {
 				out.add(m);
-//				if(out.size() >= limit)
-//					Collections.sort(out, new MovieComparatorRating());
-//					return out;
 			}
 		}
 		Collections.sort(out, new MovieComparatorRating());
@@ -80,7 +76,7 @@ public class Recomendations {
 		}
 		Collections.sort(temp, new MovieComparatorRating());
 		ArrayList<Movie> ret = new ArrayList<>();
-		for(int i = 0;i < limit ;i++ ) {
+		for(int i = 0;i < temp.size()-1 ;i++ ) {
 			ret.add(temp.get(i));
 		}
 		return ret;

+ 112 - 9
MovieDB/src/main/ConsoleReader.java

@@ -1,60 +1,105 @@
 package main;
 
+import java.util.ArrayList;
 import java.util.Scanner;
 
+import data.Actor;
+import data.DataBase;
+import data.Director;
+import data.Movie;
+import logic.Recomendations;
+
 public class ConsoleReader {
-	Scanner in;
+	
+	private Scanner in;
+	private DataBase db = DataBase.getInstance();
+	private ArrayList<Movie> m = new ArrayList<>();
+	private ArrayList<Actor> a = new ArrayList<>();
+	private ArrayList<Director> d = new ArrayList<>();
+	private ArrayList<String> g = new ArrayList<>();
+	private int limit = 200;
+	private Recomendations rec = new Recomendations();
+	
 	public ConsoleReader() {
 		in = new Scanner(System.in);
 		read();
 	}
 	
 	private void read() {
-		printMenu();
 		String msg;
+		System.out.println("MovieDB interactive mode");
+		System.out.println("Enter help for a list of commands");
 		while(true) {
 			while(in.hasNextLine()) {
 				msg = in.nextLine();
-				System.out.println(msg);
 				String[] args = msg.split(" ");
+				String[] data = msg.split("'");
 				switch(args[0]) {
 				case "set":
+					if(args.length >= 2) {
 					switch(args [1]) {
 					case "actor":
+						a.add(db.getActorByName(data[1]));
 						break;
 					case "director":
+						d.add(db.getDirectorByName(data[1]));
 						break;
 					case "film":
+						m.add(db.getMovieByName(data[1]));
 						break;
 					case "genre":
+						g.add(data[1]);
 						break;
 					case "limit":
+						int lim = Integer.valueOf(args[2]);
+						if(lim < 200)
+							limit = lim;
 						break;
 					default:
-						System.out.println("bla helptext bla");
+						System.out.println("invalid input please use help to show valid command");
+					}
 					}
 					break;
 				case "show":
+					if(args.length >= 2) {
 					switch(args [1]) {
 					case "actor":
+						for(Actor ac : a) {
+							System.out.println(ac.getName());
+						}
 						break;
 					case "director":
+						for(Director dc : d) {
+							System.out.println(dc.getName());
+						}
 						break;
 					case "film":
+						for(Movie f : m) {
+							System.out.println(f.getTitle());
+						}
 						break;
 					case "genre":
+						for(String s : g) {
+							System.out.println(s);
+						}
 						break;
 					case "limit":
+						System.out.println(limit);
 						break;
 					default:
-						System.out.println("bla helptext bla");
+						System.out.println("invalid input please use help to show valid command");
+					}
 					}
 					break;
 				case "42":
 					System.out.println("is the answer to life the universe and everything.");
 					break;
+				case "exit":
+					System.exit(0);
+					break;
 				case "random":
 					System.out.println("are you really bored enough to search for random movies? get a life!!");
+					break;
 				case "go":
 				case "run":
 				case "exploit":
@@ -62,17 +107,75 @@ public class ConsoleReader {
 					break;
 				case "help":
 				default:
-					System.out.println("dafuq nigga");
+					System.out.println("add criteria using set like: set <criteria> '<value>' \n"+
+							"e.g. set actor 'Vin Diesel' \n"+
+							"show your options using show <criteria> \n"+
+							"e.g. show actor \n"+
+							"valid criterias are:\n"+
+							"- actor\n"+
+							"- director\n"
+							+ "- film\n"
+							+ "- genre\n"
+							+ "- limit\n"
+							+ "\n"
+							+ "To search for recomandations use run or go");
 				}
 			}
 		}
 	}
 	
 	private void executeSearch() {
-		
+		ArrayList<Movie> response = new ArrayList<>();
+		ArrayList<Movie> buffer;
+		if(!this.a.isEmpty()) {
+			for(Actor ac : a) {
+				buffer = new ArrayList<>();
+					for(Movie m : rec.withActor(ac,limit)) {
+						buffer.add(m);
+					}
+				response.addAll(combine(buffer, response));
+			}
+		}
+		if(!this.d.isEmpty()) {
+			for(Director dc : d) {
+				buffer = new ArrayList<>();
+					for(Movie m : rec.withDirector(dc,limit)) {
+						buffer.add(m);
+					}
+				response.addAll(combine(buffer, response));
+			}
+		}
+		if(!this.g.isEmpty()) {
+			for(String s : g) {
+				buffer = new ArrayList<>();
+					for(Movie m : rec.withGenre(s,limit)) {
+						buffer.add(m);
+					}
+				response.addAll(combine(buffer, response));
+			}
+		}if(!this.m.isEmpty()) {
+			for(Movie f : m) {
+				buffer = new ArrayList<>();
+					for(Movie m : rec.likedByUserWhoLike(f,limit)) {
+						buffer.add(m);
+					}
+				response.addAll(combine(buffer, response));
+			}
+		}
+		for(Movie m : response) {
+			System.out.println(m.getTitle()+" - "+m.getPlot());
+		}
 	}
 	
-	private void printMenu() {
-		System.out.println("MovieDB interactive Mode");
+	private ArrayList<Movie> combine(ArrayList<Movie> a, ArrayList<Movie> b){
+		ArrayList out = new ArrayList<>();
+		if(b.isEmpty())
+			return a;
+		for(Movie m : a) {
+			if(b.contains(a))
+				out.add(m);
+		}
+		return out;
 	}
+	
 }

+ 1 - 1
MovieDB/src/main/Main.java

@@ -26,7 +26,7 @@ public class Main {
 				switch(s.substring(0,s.indexOf("="))) {
 				case "--test":
 					buffer = new ArrayList<>();
-					for(Movie m : rec.withActor(DataBase.getInstance().getActorByName(s.substring(s.indexOf("=")+1).replaceAll("'", "")), 20)) {
+					for(Movie m : rec.withActor(DataBase.getInstance().getActorByName("Vin Diesel"), 20)) {
 						buffer.add(m);
 					}
 						printlist.addAll(combine(buffer,printlist));