icfp-model/src/main/java/ru/bosony/model/cellscontents/CellContent.java
author indvdum (gotoindvdum[at]gmail[dot]com)
Mon, 16 Jul 2012 00:05:50 +0400
changeset 29 66aa96e8fd92
parent 27 505c25412b16
child 30 666821484adc
permissions -rw-r--r--
Add beards and razors
     1 package ru.bosony.model.cellscontents;
     2 
     3 import java.util.HashSet;
     4 import java.util.Set;
     5 
     6 import ru.bosony.model.io.TextRepresentable;
     7 
     8 /**
     9  * @author indvdum (gotoindvdum[at]gmail[dot]com) <br>
    10  *         13.07.2012 21:25:49
    11  * 
    12  */
    13 public enum CellContent implements TextRepresentable {
    14 
    15 	ClosedLambdaLift("L"),
    16 	Earth("."),
    17 	Empty(" "),
    18 	Lambda("\\"),
    19 	MiningRobot("R"),
    20 	OpenLambdaLift("O"),
    21 	Rock("*"),
    22 	Wall("#"),
    23 	TrampolineA("A"),
    24 	TrampolineB("B"),
    25 	TrampolineC("C"),
    26 	TrampolineD("D"),
    27 	TrampolineE("E"),
    28 	TrampolineF("F"),
    29 	TrampolineG("G"),
    30 	TrampolineH("H"),
    31 	TrampolineI("I"),
    32 	Target1("1"),
    33 	Target2("2"),
    34 	Target3("3"),
    35 	Target4("4"),
    36 	Target5("5"),
    37 	Target6("6"),
    38 	Target7("7"),
    39 	Target8("8"),
    40 	Target9("9"),
    41 	WadlersBeard("W"),
    42 	HuttonsRazor("!");
    43 
    44 	private String					text;
    45 	private CellContent				trampolineTarget	= null;
    46 	private static Set<CellContent>	trampolines			= new HashSet<CellContent>();
    47 	private static Set<CellContent>	targets				= new HashSet<CellContent>();
    48 	static {
    49 		trampolines.add(TrampolineA);
    50 		trampolines.add(TrampolineB);
    51 		trampolines.add(TrampolineC);
    52 		trampolines.add(TrampolineD);
    53 		trampolines.add(TrampolineE);
    54 		trampolines.add(TrampolineF);
    55 		trampolines.add(TrampolineG);
    56 		trampolines.add(TrampolineH);
    57 		trampolines.add(TrampolineI);
    58 		targets.add(Target1);
    59 		targets.add(Target2);
    60 		targets.add(Target3);
    61 		targets.add(Target4);
    62 		targets.add(Target5);
    63 		targets.add(Target6);
    64 		targets.add(Target7);
    65 		targets.add(Target8);
    66 		targets.add(Target9);
    67 	}
    68 
    69 	private CellContent(String text) {
    70 		this.text = text;
    71 	}
    72 
    73 	@Override
    74 	public String toText() {
    75 		return text;
    76 	}
    77 
    78 	public static CellContent fromText(String text) {
    79 		for (CellContent content : values()) {
    80 			if (text != null && text.equals(content.toText()))
    81 				return content;
    82 		}
    83 		return null;
    84 	}
    85 
    86 	public CellContent getTrampolineTarget() {
    87 		return trampolineTarget;
    88 	}
    89 
    90 	public void setTrampolineTarget(CellContent trampolineTarget) {
    91 		if (!trampolines.contains(this) || trampolineTarget != null && !targets.contains(trampolineTarget))
    92 			throw new RuntimeException("Only references from Trampolines to Targets allowed");
    93 		this.trampolineTarget = trampolineTarget;
    94 	}
    95 
    96 	public static Set<CellContent> getTrampolines() {
    97 		return trampolines;
    98 	}
    99 
   100 	public static Set<CellContent> getTargets() {
   101 		return targets;
   102 	}
   103 
   104 }