SourceForTranslation.java revision 3087:ed4c306ec942
1 class Universe { // Not referenced by lambda, so should not be captured. 2 3 public String name; 4 public int galaxiesCount; 5 6 public Universe(String name, int galaxiesCount) { 7 this.name = name; 8 this.galaxiesCount = galaxiesCount; 9 } 10 11 public String toString() { 12 return "Universe" + name + " of " + galaxiesCount + " galaxies"; 13 } 14 15 class Galaxy { 16 17 String name; 18 private int starsCount; 19 20 Galaxy(String name, int starsCount) { 21 this.name = name; 22 this.starsCount = starsCount; 23 } 24 25 public String toString() { 26 return "galaxy " + name + " of " + starsCount + " solar systems"; 27 } 28 29 int starsCount() { 30 return starsCount; 31 } 32 33 private String name() { 34 return name; 35 } 36 37 class SolarSystem { 38 39 String name; 40 int planetsCount; 41 42 SolarSystem(String name, int planetsCount) { 43 this.name = name; 44 this.planetsCount = planetsCount; 45 } 46 47 public String toString() { 48 return "Solar System of " + name + " with " + planetsCount + " planets"; 49 } 50 51 int planetsCount() { 52 return planetsCount; 53 } 54 55 SolarSystem copy(SolarSystem s) { 56 return s; 57 } 58 59 class Planet { 60 61 String name; 62 int moonsCount; 63 64 Planet(String name, int moonsCount, Runnable r) { 65 this.name = name; 66 this.moonsCount = moonsCount; 67 r.run(); 68 } 69 Planet (String name, int moonsCount) { 70 this(name, moonsCount, ()-> { 71 String n = name; 72 StringBuffer buf = new StringBuffer(); 73 buf.append("This planet belongs to the galaxy " 74 + Galaxy.this.name + " with " + starsCount + " stars\n"); 75 buf.append("This planet belongs to the galaxy " 76 + Universe.Galaxy.this.name + " with " + starsCount() + " stars\n"); 77 buf.append("This planet belongs to the galaxy " 78 + Galaxy.this.name() + " with " + starsCount() + " stars\n"); 79 buf.append("This planet belongs to the galaxy " 80 + Universe.Galaxy.this.name() + " with " 81 + (Universe.Galaxy.this).starsCount() + " stars\n"); 82 83 buf.append("This planet belongs to the solar system " 84 + SolarSystem.this.name + " with " + planetsCount + " planets\n"); 85 buf.append("This planet belongs to the solar system " 86 + Galaxy.SolarSystem.this.name + " with " + planetsCount() + " planets\n"); 87 buf.append("This planet belongs to the solar system " 88 + (SolarSystem.this).name + " with " + planetsCount + " planets\n"); 89 buf.append("This planet belongs to the solar system " 90 + Universe.Galaxy.SolarSystem.this.name + " with " 91 + Universe.Galaxy.SolarSystem.this.planetsCount + " planets\n"); 92 buf.append("This planet belongs to the solar system " 93 + Universe.Galaxy.SolarSystem.this.name.toLowerCase().toUpperCase() 94 + " with " + Universe.Galaxy.SolarSystem.this.planetsCount + " planets\n"); 95 buf.append("This planet belongs to the solar system " 96 + copy(Universe.Galaxy.SolarSystem.this).name.toLowerCase().toUpperCase() 97 + " with " + Universe.Galaxy.SolarSystem.this.planetsCount + " planets\n"); 98 if (!buf.toString().equals(output)) 99 throw new AssertionError("Unexpected value\n" + buf); 100 }); 101 } 102 103 static final String output = 104 "This planet belongs to the galaxy Mily way with 23456789 stars\n" + 105 "This planet belongs to the galaxy Mily way with 23456789 stars\n" + 106 "This planet belongs to the galaxy Mily way with 23456789 stars\n" + 107 "This planet belongs to the galaxy Mily way with 23456789 stars\n" + 108 "This planet belongs to the solar system Sun with 9 planets\n" + 109 "This planet belongs to the solar system Sun with 9 planets\n" + 110 "This planet belongs to the solar system Sun with 9 planets\n" + 111 "This planet belongs to the solar system Sun with 9 planets\n" + 112 "This planet belongs to the solar system SUN with 9 planets\n" + 113 "This planet belongs to the solar system SUN with 9 planets\n"; 114 115 116 public String toString() { 117 return "Planet " + name + " with " + moonsCount + " moon(s)"; 118 } 119 } 120 } 121 } 122 } 123