icfp-model/src/main/java/ru/bosony/model/cellscontents/CellContent.java
author indvdum (gotoindvdum[at]gmail[dot]com)
Mon, 16 Jul 2012 01:46:54 +0400
changeset 30 666821484adc
parent 29 66aa96e8fd92
permissions -rw-r--r--
Add HighOrderRock
     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 	HighOrderRock("@");
    44 
    45 	private String					text;
    46 	private CellContent				trampolineTarget	= null;
    47 	private static Set<CellContent>	trampolines			= new HashSet<CellContent>();
    48 	private static Set<CellContent>	targets				= new HashSet<CellContent>();
    49 	static {
    50 		trampolines.add(TrampolineA);
    51 		trampolines.add(TrampolineB);
    52 		trampolines.add(TrampolineC);
    53 		trampolines.add(TrampolineD);
    54 		trampolines.add(TrampolineE);
    55 		trampolines.add(TrampolineF);
    56 		trampolines.add(TrampolineG);
    57 		trampolines.add(TrampolineH);
    58 		trampolines.add(TrampolineI);
    59 		targets.add(Target1);
    60 		targets.add(Target2);
    61 		targets.add(Target3);
    62 		targets.add(Target4);
    63 		targets.add(Target5);
    64 		targets.add(Target6);
    65 		targets.add(Target7);
    66 		targets.add(Target8);
    67 		targets.add(Target9);
    68 	}
    69 
    70 	private CellContent(String text) {
    71 		this.text = text;
    72 	}
    73 
    74 	@Override
    75 	public String toText() {
    76 		return text;
    77 	}
    78 
    79 	public static CellContent fromText(String text) {
    80 		for (CellContent content : values()) {
    81 			if (text != null && text.equals(content.toText()))
    82 				return content;
    83 		}
    84 		return null;
    85 	}
    86 
    87 	public CellContent getTrampolineTarget() {
    88 		return trampolineTarget;
    89 	}
    90 
    91 	public void setTrampolineTarget(CellContent trampolineTarget) {
    92 		if (!trampolines.contains(this) || trampolineTarget != null && !targets.contains(trampolineTarget))
    93 			throw new RuntimeException("Only references from Trampolines to Targets allowed");
    94 		this.trampolineTarget = trampolineTarget;
    95 	}
    96 
    97 	public static Set<CellContent> getTrampolines() {
    98 		return trampolines;
    99 	}
   100 
   101 	public static Set<CellContent> getTargets() {
   102 		return targets;
   103 	}
   104 
   105 }