Initial commit for 2.2
parent
22a6706b90
commit
62c015eeba
@ -0,0 +1,57 @@
|
|||||||
|
package _2._2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Dance {
|
||||||
|
private String name;
|
||||||
|
private String beat;
|
||||||
|
private List<Figure> figures;
|
||||||
|
|
||||||
|
public Dance(String name, String beat) {
|
||||||
|
this.name = name;
|
||||||
|
this.beat = beat;
|
||||||
|
this.figures = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dance(String name, String beat, List<Figure> figures) {
|
||||||
|
this.name = name;
|
||||||
|
this.beat = beat;
|
||||||
|
this.figures = figures;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBeat() {
|
||||||
|
return this.beat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBeat(String beat) {
|
||||||
|
this.beat = beat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Figure> getFigures() {
|
||||||
|
return this.figures;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFigures(List<Figure> figures) {
|
||||||
|
this.figures = figures;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO remove
|
||||||
|
// @Override
|
||||||
|
// public String toString() {
|
||||||
|
// final StringBuilder sb = new StringBuilder(this.getClass().getSimpleName());
|
||||||
|
// sb.append(" ");
|
||||||
|
// sb.append(name);
|
||||||
|
// sb.append(" (").append(beat).append(") ");
|
||||||
|
// sb.append(figures);
|
||||||
|
// return sb.toString();
|
||||||
|
// }
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package _2._2;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class DanceDatabase {
|
||||||
|
|
||||||
|
private static final Figure BASIC_MOVE = new Figure("Basic Move", "Lorem ipsum.");
|
||||||
|
private static final Figure NATURAL_TURN = new Figure("Natural Turn", "Lorem ipsum.");
|
||||||
|
private static final Figure SPIN_TURN = new Figure("Spin Turn", "Lorem ipsum.");
|
||||||
|
private static final Figure FAN = new Figure("Fan", "Lorem ipsum.");
|
||||||
|
private static final Figure PROMENADE = new Figure("Promenade", "Lorem ipsum.");
|
||||||
|
private static final Figure CHASSE = new Figure("Chassé", "Lorem ipsum.");
|
||||||
|
private static final Figure WHISK = new Figure("Whisk", Arrays.asList(PROMENADE, CHASSE));
|
||||||
|
|
||||||
|
public static final LatinDance JIVE = new LatinDance( "Jive", "4/4", Arrays.asList(BASIC_MOVE));
|
||||||
|
public static final LatinDance RUMBA = new LatinDance( "Rumba", "4/4", Arrays.asList(BASIC_MOVE, FAN));
|
||||||
|
public static final LatinDance CHACHACHA = new LatinDance( "ChaChaCha", "4/4", Arrays.asList(BASIC_MOVE, FAN));
|
||||||
|
public static final StandardDance TANGO = new StandardDance("Tango", "4/4", Arrays.asList(BASIC_MOVE, PROMENADE));
|
||||||
|
public static final StandardDance QUICKSTEP = new StandardDance("Quickstep", "4/4", Arrays.asList(BASIC_MOVE, SPIN_TURN));
|
||||||
|
public static final StandardDance WALTZ = new StandardDance("Waltz", "3/4", Arrays.asList(NATURAL_TURN, SPIN_TURN, WHISK));
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//unnötig
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,92 @@
|
|||||||
|
package _2._2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Figure is described by either Text or (exclusive) a sequence of other Figures.
|
||||||
|
*/
|
||||||
|
public class Figure {
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private List<Figure> parts;
|
||||||
|
|
||||||
|
public Figure(String name, String description) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Figure(String name, List<Figure> parts) {
|
||||||
|
this.name = name;
|
||||||
|
this.parts = new ArrayList<>();
|
||||||
|
for(Figure part : parts) {
|
||||||
|
this.add(part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean add(Figure figure) {
|
||||||
|
if(figure == null || this.parts == null || this.contains(figure)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.parts.add(figure);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean contains(Figure figure) {
|
||||||
|
if(this.parts == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(this.parts.contains(figure)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for(Figure part : this.parts) {
|
||||||
|
if(part.parts == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(part.equals(figure) || part.contains(figure)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
if(this.parts != null) {
|
||||||
|
throw new IllegalStateException("This figure is already described as a sequence of other figures.");
|
||||||
|
}
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Figure> getParts() {
|
||||||
|
return this.parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParts(List<Figure> parts) {
|
||||||
|
if(this.description != null) {
|
||||||
|
throw new IllegalStateException("This figure is already described by text.");
|
||||||
|
}
|
||||||
|
this.parts = parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO remove
|
||||||
|
// @Override
|
||||||
|
// public String toString() {
|
||||||
|
// final StringBuilder sb = new StringBuilder();
|
||||||
|
// sb.append(name);
|
||||||
|
// if(parts != null) {
|
||||||
|
// sb.append(": ").append(parts);
|
||||||
|
// }
|
||||||
|
// return sb.toString();
|
||||||
|
// }
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package _2._2;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class LatinDance extends Dance {
|
||||||
|
public LatinDance(String name, String beat) {
|
||||||
|
super(name, beat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LatinDance(String name, String beat, List<Figure> figures) {
|
||||||
|
super(name, beat, figures);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package _2._2;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class StandardDance extends Dance {
|
||||||
|
public StandardDance(String name, String beat) {
|
||||||
|
super(name, beat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StandardDance(String name, String beat, List<Figure> figures) {
|
||||||
|
super(name, beat, figures);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue