Created
February 16, 2017 14:30
-
-
Save 13andrew13/ef39040b6ad4f117ed2650cefac5f8ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Film; | |
/** | |
* Created by andrew on 10.02.17. | |
*/ | |
public class Actor { | |
private String name; | |
public Actor(String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; | |
} | |
@Override | |
public String toString() { | |
return name ; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Film; | |
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.List; | |
/** | |
* Created by andrew on 10.02.17. | |
*/ | |
public class Film { | |
private String name; | |
private int year; | |
private List<Actor> actor = new ArrayList<Actor>(); | |
private List<Genre> genres = new ArrayList<Genre>(); | |
public Film(String name, int year ){ | |
this.name = name; | |
this.year = year; | |
} | |
public void addGenre(Genre genre){ | |
this.genres.add(genre); | |
} | |
public void addActor(Actor actor){ | |
this.actor.add(actor); | |
} | |
public int getYear() { | |
return year; | |
} | |
public List<Actor> getActor() { | |
return actor; | |
} | |
public List<Genre> getGenres() { | |
return genres; | |
} | |
@Override | |
public String toString() { | |
return "Film name=\'" + name + '\'' + | |
"\nyear:" + year + | |
"\nactors:" + actor+ | |
"\ngenres:" + genres + "\n"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Film; | |
import java.util.ArrayList; | |
import java.util.Iterator; | |
/** | |
* Created by andrew on 10.02.17. | |
*/ | |
public class Films implements Iterable<Film>{ | |
private ArrayList<Film> films= new ArrayList<Film>(); | |
public void addFilm(Film film){ | |
films.add(film); | |
} | |
public void addFilm(Films films){ | |
this.films.addAll(films.getFilms()); | |
} | |
public ArrayList<Film> getFilms() { | |
return films; | |
} | |
public Iterator<Film> iterator() { | |
return new Iterator<Film> () { | |
private final Iterator<Film> iter = films.iterator(); | |
@Override | |
public boolean hasNext() { | |
return iter.hasNext(); | |
} | |
@Override | |
public Film next() { | |
return iter.next(); | |
} | |
@Override | |
public void remove() { | |
throw new UnsupportedOperationException("no changes allowed"); | |
} | |
}; | |
} | |
@Override | |
public String toString() { | |
if(films.isEmpty())return "This list is empty"; | |
return "List of filsms:\n" + films ; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Film; | |
/** | |
* Created by andrew on 15.02.17. | |
*/ | |
public class FilmsByActor implements FilmsFilter{ | |
private String name; | |
private Films films = new Films(); | |
public FilmsByActor(String name) { | |
this.name = name; | |
} | |
@Override | |
public Films getFilms(Films films) { | |
for (Film film: films ) { | |
for (Actor actor : film.getActor()) { | |
if (actor.getName().equals(name)) { | |
this.films.addFilm(film); | |
} | |
} | |
} | |
return this.films; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Film; | |
/** | |
* Created by andrew on 15.02.17. | |
*/ | |
public class FilmsByGenre implements FilmsFilter{ | |
private Genre genre; | |
private Films films = new Films(); | |
public FilmsByGenre(Genre genre) { | |
this.genre = genre; | |
} | |
@Override | |
public Films getFilms(Films films) { | |
for (Film film: films) { | |
for(Genre genre1:film.getGenres()){ | |
if(genre.equals(genre1)){ | |
this.films.addFilm(film); | |
} | |
} | |
} | |
return this.films; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Film; | |
/** | |
* Created by andrew on 16.02.17. | |
*/ | |
public class FilmsByYear { | |
private long start; | |
private long end; | |
private Films films = new Films(); | |
public FilmsByYear(long start, long end) { | |
this.start = start; | |
this.end = end; | |
} | |
public Films getFilms(Films films){ | |
if(start>end||start<1900){ | |
System.out.println("There is no films like this!"); | |
return null; | |
} | |
for(Film film: films){ | |
if(film.getYear()<=end && film.getYear()>=start){ | |
this.films.addFilm(film); | |
} | |
} | |
return films; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Film; | |
/** | |
* Created by andrew on 15.02.17. | |
*/ | |
public interface FilmsFilter { | |
public Films getFilms(Films films); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Film; | |
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Created by andrew on 10.02.17. | |
*/ | |
public class FilmsRunner { | |
public static void main(String[] args) { | |
Films films = new Films(); | |
Film killers = new Film("Killers",2001); | |
Film cinderela = new Film("Cinderela",2015); | |
films.addFilm(killers); | |
films.addFilm(cinderela); | |
killers.addGenre(Genre.ADVENTURE); | |
killers.addActor(new Actor("Johny Depp")); | |
cinderela.addActor(new Actor("Emma Watson")); | |
cinderela.addGenre(Genre.FAMILY); | |
FilmsFilter filmsFilter = new FilmsByActor("Johny Depp"); | |
FilmsFilter filmsFilter1 = new FilmsByGenre(Genre.FAMILY); | |
System.out.println(filmsFilter.getFilms(films)); | |
System.out.println(); | |
System.out.println(filmsFilter1.getFilms(films)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Film; | |
/** | |
* Created by andrew on 10.02.17. | |
*/ | |
public enum Genre { | |
HORROR, | |
WESTERN, | |
THRILLER, | |
ADVENTURE, | |
MYSTERY, | |
CRIME, | |
FAMILY; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment