├── .gitignore ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── libs └── bolts.jar └── src ├── main ├── ceylon │ └── com │ │ └── naver │ │ └── helloworld │ │ └── resort │ │ ├── module.ceylon │ │ ├── package.ceylon │ │ ├── run.ceylon │ │ └── service │ │ └── resort.ceylon ├── groovy │ └── com │ │ └── naver │ │ └── helloworld │ │ └── resort │ │ ├── repository │ │ └── GroovyRepository.groovy │ │ └── service │ │ ├── GroovyAdvancedResort.groovy │ │ └── GroovyResort.groovy ├── java │ └── com │ │ └── naver │ │ └── helloworld │ │ ├── basiclambda │ │ ├── CustomFunctionReference.java │ │ ├── FunctionParameterExam.java │ │ ├── JdkFunctionReference.java │ │ ├── SimpleLambda.java │ │ └── ThisDifference.java │ │ ├── resort │ │ ├── JinqResortRun.java │ │ ├── ResortServer.java │ │ ├── android │ │ │ ├── ClassicFragment.java │ │ │ └── ModernFragment.java │ │ ├── domain │ │ │ └── Guest.java │ │ ├── repository │ │ │ ├── ClassicJdbcRepository.java │ │ │ ├── GuestCrudRepository.java │ │ │ ├── GuestRepository.java │ │ │ ├── MemoryRepository.java │ │ │ └── ModernJdbcRepository.java │ │ └── service │ │ │ ├── BoltsResort.java │ │ │ ├── ClassicJavaResort.java │ │ │ ├── CommonsCollectionsResort.java │ │ │ ├── FunctionalJavaResort.java │ │ │ ├── GsCollectionsResort.java │ │ │ ├── GuavaResort.java │ │ │ ├── JediResort.java │ │ │ ├── JinqResort.java │ │ │ ├── LambdaJResort.java │ │ │ ├── ModernJavaAdvancedResort.java │ │ │ ├── ModernJavaBreak2Resort.java │ │ │ ├── ModernJavaBreakResort.java │ │ │ ├── ModernJavaResort.java │ │ │ ├── Op4JResort.java │ │ │ ├── ResortService.java │ │ │ └── TotallyLazyResort.java │ │ └── web │ │ ├── ClassicAsyncServlet.java │ │ ├── ModernAsyncServlet.java │ │ └── SparkServer.java ├── kotlin │ └── com │ │ └── naver │ │ └── helloworld │ │ └── resort │ │ └── service │ │ ├── KotlinAdvancedResort.kt │ │ └── KotlinResort.kt ├── resources │ ├── application.properties │ ├── data.sql │ └── schema.sql ├── scala │ └── com │ │ └── naver │ │ └── helloworld │ │ └── resort │ │ └── service │ │ ├── ScalaAdvancedResort.scala │ │ └── ScalaResort.scala └── xtend │ └── com │ └── naver │ └── helloworld │ └── resort │ └── service │ ├── .gitignore │ ├── XtendAdvancedResort.xtend │ └── XtendResort.xtend └── test └── java └── com └── naver └── helloworld └── resort └── service ├── GroovyResortTest.java ├── JavaResortTest.java ├── KotlinResortTest.java ├── ResortServiceSpec.java ├── ScalaResortTest.java ├── Workaround.xtend └── XtendResortTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | build/ 3 | .classpath 4 | .gradle/ 5 | .project 6 | .settings/ 7 | .externalToolBuilders/ 8 | .springBeans 9 | 10 | *.iml 11 | *.ipr 12 | *.iws 13 | .idea/ 14 | .exploded/ 15 | modules/ 16 | .cache 17 | .ceylon/ 18 | xtend-gen/ 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Filtering, sorting, mapping 3 | 4 | ### Backgrounds 5 | [Guest.java](src/main/java/com/naver/helloworld/resort/domain/Guest.java) 6 | 7 | ```java 8 | public class Guest { 9 | private final int grade; 10 | private final String name; 11 | private final String company; 12 | ... 13 | } 14 | ``` 15 | 16 | [GuestRepository.java](src/main/java/com/naver/helloworld/resort/repository/GuestRepository.java) 17 | 18 | ```java 19 | import java.util.List; 20 | 21 | public interface GuestRepository { 22 | public List findAllGuest (); 23 | } 24 | ``` 25 | 26 | [ResortService.java](src/main/java/com/naver/helloworld/resort/service/ResortService.java) 27 | 28 | ```java 29 | public interface ResortService { 30 | public List findGuestNamesByCompany (String company); 31 | } 32 | ``` 33 | 34 | ## Implementations by classic Java 35 | ### JDK Collections framework 36 | [ClassicJavaResort.java](src/main/java/com/naver/helloworld/resort/service/ClassicJavaResort.java) 37 | 38 | ```java 39 | public List findGuestNamesbyCompany(String company) { 40 | List all = repository.findAllGuest(); 41 | 42 | List filtered = filter(guests, company); 43 | sort(filtered); 44 | return mapNames(filtered); 45 | } 46 | 47 | private List filter(List guests, String company) { 48 | List filtered = new ArrayList<>(); 49 | for(Guest guest : guests ) { 50 | if (company.equals(guest.getCompany())) { 51 | filtered.add(guest); 52 | } 53 | } 54 | return filtered; 55 | } 56 | 57 | private void sort(List guests) { 58 | Collections.sort(guests, new Comparator() { 59 | public int compare(Guest o1, Guest o2) { 60 | return Integer.compare(o1.getGrade(), o2.getGrade()); 61 | } 62 | }); 63 | } 64 | 65 | private List mapNames(List guests) { 66 | List names = new ArrayList<>(); 67 | for(Guest guest : guests ) { 68 | names.add(guest.getName()); 69 | } 70 | return names; 71 | } 72 | ``` 73 | 74 | ### [Guava](https://github.com/google/guava) 75 | [GuavaResort.java](src/main/java/com/naver/helloworld/resort/service/GuavaResort.java) 76 | 77 | ```java 78 | public List findGuestNamesByCompany(final String company) { 79 | List all = repository.findAll(); 80 | 81 | List sorted = FluentIterable.from(all) 82 | .filter(new Predicate() { 83 | public boolean apply(Guest g) { 84 | return company.equals(g.getCompany()); 85 | } 86 | }) 87 | .toSortedList(Ordering.natural().onResultOf( 88 | new Function() { 89 | public Integer apply(Guest g) { 90 | return g.getGrade(); 91 | } 92 | })); 93 | 94 | return FluentIterable.from(sorted) 95 | .transform(new Function() { 96 | public String apply(Guest g) { 97 | return g.getName(); 98 | } 99 | }) 100 | .toList(); 101 | } 102 | ``` 103 | 104 | ### [Totally Lazy](http://totallylazy.com/) 105 | [TotallyLazyResort.java](src/main/java/com/naver/helloworld/resort/service/TotallyLazyResort.java) 106 | 107 | ```java 108 | public List findGuestNamesByCompany(final String company) { 109 | List all = repository.findAll(); 110 | return Sequences.sequence(all) 111 | .filter(new Predicate() { 112 | public boolean matches(Guest g) { 113 | return company.equals(g.getCompany()); 114 | } 115 | }) 116 | .sortBy(new Callable1(){ 117 | public Integer call(Guest g) { 118 | return g.getGrade(); 119 | } 120 | }) 121 | .map(new Callable1(){ 122 | public String call(Guest g) { 123 | return g.getName(); 124 | } 125 | }) 126 | .toList(); 127 | } 128 | ``` 129 | 130 | ### [GS Collections](https://github.com/goldmansachs/gs-collections) 131 | [GsCollectoinsResort.java](src/main/java/com/naver/helloworld/resort/service/GsCollectionsResort.java) 132 | 133 | ```java 134 | public List findGuestNamesByCompany(final String company) { 135 | List all = repository.findAll(); 136 | return FastList.newList(all) 137 | .select(new Predicate() { 138 | public boolean accept(Guest g) { 139 | return company.equals(g.getCompany()); 140 | } 141 | }) 142 | .sortThisBy(new Function() { 143 | public Integer valueOf(Guest g) { 144 | return g.getGrade(); 145 | } 146 | }) 147 | .collect(new Function () { 148 | public String valueOf(Guest g) { 149 | return g.getName(); 150 | } 151 | }); 152 | } 153 | ``` 154 | 155 | ### [Bolts](https://bitbucket.org/stepancheg/bolts/wiki/Home) 156 | [BoltsResort.java](src/main/java/com/naver/helloworld/resort/service/BoltsResort.java) 157 | 158 | ```java 159 | public List findGuestNamesByCompany(final String company) { 160 | List all = repository.findAllGuest(); 161 | return Cf.list(all) 162 | .filter(new Function1B() { 163 | public boolean apply(Guest g) { 164 | return company.equals(g.getCompany()); 165 | } 166 | }) 167 | .sortBy(new Function() { 168 | public Integer apply(Guest g) { 169 | return g.getGrade(); 170 | } 171 | }) 172 | .map(new Function() { 173 | public String apply(Guest g) { 174 | return g.getName(); 175 | } 176 | }); 177 | } 178 | ``` 179 | 180 | ### [Op4j](www.op4j.org) 181 | [Op4JResort.java](src/main/java/com/naver/helloworld/resort/service/Op4JResort.java) 182 | 183 | ```java 184 | public List findGuestNamesByCompany(final String company) { 185 | List all = repository.findAllGuest(); 186 | return Op.on(all) 187 | .removeAllFalse(new IFunction() { 188 | public Boolean execute(Guest g, ExecCtx ctx) throws Exception { 189 | return company.equals(g.getCompany()); 190 | } 191 | }) 192 | .sortBy(new IFunction() { 193 | public Integer execute(Guest g, ExecCtx ctx) throws Exception { 194 | return g.getGrade(); 195 | } 196 | }) 197 | .map(new IFunction() { 198 | public String execute(Guest g, ExecCtx ctx) throws Exception { 199 | return g.getName(); 200 | } 201 | }).get(); 202 | } 203 | ``` 204 | 205 | ### [Lambdaj](https://code.google.com/p/lambdaj) 206 | [LambdaJResort.java](src/main/java/com/naver/helloworld/resort/service/LambdaJResort.java) 207 | 208 | ```java 209 | import static ch.lambdaj.Lambda.*; 210 | import static org.hamcrest.Matchers.*; 211 | ... 212 | 213 | public List findGuestNamesByCompany(final String company) { 214 | List all = repository.findAll(); 215 | return LambdaCollections.with(all) 216 | .retain(having(on(Guest.class).getCompany(), equalTo(company))) 217 | .sort(on(Guest.class).getGrade()) 218 | .extract(on(Guest.class).getName()); 219 | } 220 | ``` 221 | 222 | ### [Functional Java](http://functionaljava.org/) 223 | [FunctionalJavaResort.java](src/main/java/com/naver/helloworld/resort/service/FunctionalJavaResort.java) 224 | 225 | ```java 226 | public List findGuestNamesByCompany(String company) { 227 | List all = repository.findAll(); 228 | 229 | Collection mapped = Stream.iterableStream(all) 230 | .filter(new F() { 231 | public Boolean f(Guest g){ 232 | return company.equals(g.getCompany()); 233 | } 234 | }) 235 | .sort(Ord.ord( 236 | new F>() { 237 | public F f(final Guest a1) { 238 | return new F() { 239 | public Ordering f(final Guest a2) { 240 | int x = Integer.compare(a1.getGrade(), a2.getGrade()); 241 | return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; 242 | } 243 | }; 244 | } 245 | })) 246 | .map(new F() { 247 | public String f(Guest g) { 248 | return g.getName(); 249 | } 250 | }) 251 | .toCollection(); 252 | return new ArrayList(mapped); 253 | } 254 | ``` 255 | 256 | ### [Apache Commons Collections](http://commons.apache.org/proper/commons-collections/) 257 | [CommonsCollectionsResort.java](src/main/java/com/naver/helloworld/resort/service/CommonsCollectionsResort.java) 258 | 259 | ```java 260 | public List findGuestNamesByCompany(final String company) { 261 | List all = repository.findAll(); 262 | List filtered = ListUtils.select(all, new Predicate() { 263 | public boolean evaluate(Guest g) { 264 | return company.equals(g.getCompany()); 265 | } 266 | }); 267 | Collections.sort(filtered, new Comparator() { 268 | public int compare(Guest o1, Guest o2) { 269 | return Integer.compare(o1.getGrade(), o2.getGrade()); 270 | } 271 | }); 272 | Collection names = CollectionUtils.collect(filtered, new Transformer(){ 273 | public String transform(Guest g) { 274 | return g.getName(); 275 | } 276 | }); 277 | return new ArrayList<>(names); 278 | } 279 | ``` 280 | 281 | ### [Jedi](http://jedi.codehaus.org/) 282 | [JediResort.java](src/main/java/com/naver/helloworld/resort/service/JediResort.java) 283 | 284 | ```java 285 | public List findGuestNamesByCompany(final String company) { 286 | List all = repository.findAll(); 287 | List filtered = FunctionalPrimitives.select(all, new Filter() { 288 | public Boolean execute(Guest g) { 289 | return company.equals(g.getCompany()); 290 | } 291 | }); 292 | List sorted = Comparables.sort(filtered, new Functor() { 293 | public Integer execute(Guest g) { 294 | return g.getGrade(); 295 | } 296 | }); 297 | return FunctionalPrimitives.map(sorted, new Functor() { 298 | public String execute(Guest g) { 299 | return g.getName(); 300 | } 301 | }); 302 | } 303 | ``` 304 | 305 | ## Implementations by other JVM languages 306 | - Groovy : 2.3.9 307 | - Scala : 2.11.4 308 | - Kotlin : 0.10.195 309 | - Xtend : 2.7 310 | - Ceylon : 1.1.0 311 | 312 | ### [Groovy](http://groovy.codehaus.org/) 313 | [GroovyAdvancedResort.groovy](src/main/groovy/com/naver/helloworld/resort/service/GroovyAdvancedResort.groovy) 314 | 315 | ```groovy 316 | List findGuestNamesByCompany(String company) { 317 | List all = repository.findAll() 318 | all.findAll { it.company == company } 319 | .sort { it.grade } 320 | .collect { it.name } 321 | } 322 | ``` 323 | 324 | ### [Scala](http://www.scala-lang.org/) 325 | [ScalaAdvancedResort.scala](src/main/scala/com/naver/helloworld/resort/service/ScalaAdvancedResort.scala) 326 | 327 | ```scala 328 | import scala.collection.JavaConversions._ 329 | ... 330 | 331 | def findGuestNamesByCompany(company: String): java.util.List[String] = { 332 | val all = repository.findAll 333 | all.filter ( _.getCompany == company) 334 | .sortBy ( _.getGrade ) 335 | .map ( _.getName ) 336 | } 337 | ``` 338 | 339 | ### [Kotlin](http://kotlinlang.org) 340 | [KotlinAdvancedResort.kt](src/main/kotlin/com/naver/helloworld/resort/service/KotlinAdvancedResort.kt) 341 | 342 | ```kotlin 343 | 344 | override fun findGuestNamesByCompany(company: String): List { 345 | val all = repository.findAll() 346 | return all.filter { it.getCompany() == company } 347 | .sortBy { it.getGrade() } 348 | .map { it.getName() } 349 | } 350 | ``` 351 | 352 | ### [Xtend](http://www.eclipse.org/xtend/) 353 | [XtendAdvancedResort.xtend](src/main/xtend/com/naver/helloworld/resort/service/XtendAdvancedResort.xtend) 354 | 355 | ```xtend 356 | override findGuestNamesByCompany(String aCompany) { 357 | val all = repository.findAll() 358 | all.filter [company == aCompany] 359 | .sortBy[grade] 360 | .map[name] 361 | } 362 | ``` 363 | 364 | ### [Ceylon](http://ceylon-lang.org/) 365 | [resort.ceylon](src/main/ceylon/com/naver/helloworld/resort/service/resort.ceylon) 366 | 367 | ```ceylon 368 | import ceylon.interop.java { CeylonIterable } 369 | import java.util {JList = List, JArrayList = ArrayList } 370 | import java.lang {JString = String} 371 | 372 | ... 373 | 374 | shared actual JList findGuestNamesByCompany(String company) { 375 | value all = repository.findAll() ; 376 | value names = CeylonIterable(all) 377 | .filter((Guest g) => g.company == company) 378 | .sort(byIncreasing((Guest g) => g.grade.intValue())) 379 | .map((Guest g) => g.name); 380 | 381 | value jnames = JArrayList(); 382 | for (name in names) {jnames.add(JString(name));} 383 | return jnames; 384 | } 385 | ``` 386 | 387 | ## Implementations by modern Java 388 | [ModernJavaAdvancedResort.java](src/main/java/com/naver/helloworld/resort/service/ModernJavaAdvancedResort.java) 389 | 390 | ```java 391 | public List findGuestNamesByCompany(String company) { 392 | List guests = repository.findAll(); 393 | return guests.stream() 394 | .filter(g -> company.equals(g.getCompany())) 395 | .sorted(Comparator.comparing(Guest::getGrade)) 396 | .map(Guest::getName) 397 | .collect(Collectors.toList()); 398 | } 399 | ``` 400 | 401 | # Refactoring by lambda expressions 402 | 403 | ## Async Servlet 404 | 405 | ### Classic Java 406 | [ClassicAsyncServlet.java](src/main/java/com/naver/helloworld/web/ClassicAsyncServlet.java) 407 | 408 | ```java 409 | public void doGet(final HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 410 | final AsyncContext asyncContext = request.startAsync(); 411 | asyncContext.start(new Runnable() { 412 | public void run() { 413 | // long running job 414 | asyncContext.dispatch("/status.jsp"); 415 | } 416 | }); 417 | } 418 | ``` 419 | 420 | ### Modern Java 421 | [ModernAsyncServlet.java](src/main/java/com/naver/helloworld/web/ModernAsyncServlet.java) 422 | 423 | ```java 424 | public void doGet(final HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 425 | AsyncContext asyncContext = request.startAsync(); 426 | asyncContext.start(() -> { 427 | // long running job 428 | asyncContext.dispatch("/status.jsp"); 429 | }); 430 | } 431 | ``` 432 | 433 | ## Spring JDBC 434 | ### Classic Java 435 | [ClassicJdbcRepository.java](src/main/java/com/naver/helloworld/resort/repository/ClassicJdbcRepository.java) 436 | 437 | ```java 438 | public List findAll() { 439 | return jdbcTemplate.query(SELECT_ALL, new RowMapper(){ 440 | public Guest mapRow(ResultSet rs, int rowNum) throws SQLException { 441 | return new Guest ( 442 | rs.getInt("id"), 443 | rs.getString("name"), 444 | rs.getString("company"), 445 | rs.getInt("grade") 446 | ); 447 | } 448 | }); 449 | } 450 | ``` 451 | 452 | ### Modern Java 453 | [ModernJdbcRepository.java](src/main/java/com/naver/helloworld/resort/repository/ModernJdbcRepository.java) 454 | 455 | ```java 456 | public List findAll() { 457 | return jdbcTemplate.query(SELECT_ALL, 458 | (rs, rowNum) ->new Guest ( 459 | rs.getInt("id"), 460 | rs.getString("name"), 461 | rs.getString("company"), 462 | rs.getInt("grade") 463 | ) 464 | ); 465 | } 466 | ``` 467 | 468 | ### Event bindings in Android 469 | ### Classic Java 470 | [ClassicFragment.java](src/main/java/com/naver/helloworld/resort/android/ClassicFragment.java) 471 | 472 | ```java 473 | Button calcButton = (Button) view.findViewById(R.id.calcBtn); 474 | Button sendButton = (Button) view.findViewById(R.id.sendBtn); 475 | 476 | calcButton.setOnClickListener(new OnClickListener() { 477 | public void onClick(View view) { 478 | calculate(); 479 | } 480 | }); 481 | sendButton.setOnClickListener(new OnClickListener() { 482 | public void onClick(View view) { 483 | send(); 484 | } 485 | }); 486 | ``` 487 | 488 | ### Modern Java 489 | [ModernFragment.java](src/main/java/com/naver/helloworld/web/ModernAsyncServlet.java) 490 | 491 | ```java 492 | Button calcButton = (Button) view.findViewById(R.id.calcBtn); 493 | Button sendButton = (Button) view.findViewById(R.id.sendBtn); 494 | 495 | calcButton.setOnClickListener(v -> calculate()); 496 | sendButton.setOnClickListener(v -> send()); 497 | ``` 498 | 499 | # Frameworks using lambda expressions 500 | ### [Lambda Behave](http://richardwarburton.github.io/lambda-behave/) 501 | [ResortServiceSpec.java](src/test/java/com/naver/helloworld/resort/service/ResortServiceSpec.java) 502 | 503 | ```java 504 | @RunWith(JunitSuiteRunner.class) 505 | public class ResortServiceSpec {{ 506 | GuestRepository repository = new MemoryRepository(); 507 | ResortService service = new ModernJavaResort(repository); 508 | 509 | describe("ResortService with modern Java", it -> { 510 | it.isSetupWith(() -> { 511 | repository.save( 512 | new Guest(1, "jsh", "Naver", 15), 513 | new Guest(2, "hny", "Line", 10), 514 | new Guest(3, "chy", "Naver", 5) 515 | ); 516 | 517 | }); 518 | it.isConcludedWith(repository::deleteAll); 519 | 520 | it.should("find names of guests by company ", expect -> { 521 | List names = service.findGuestNamesByCompany("Naver"); 522 | expect.that(names).isEqualTo(Arrays.asList("chy","jsh")); 523 | }); 524 | }); 525 | }} 526 | ``` 527 | 528 | ### [Jinq](http://www.jinq.org/) 529 | [JinqResort.java](src/main/java/com/naver/helloworld/resort/service/JinqResort.java) 530 | 531 | ```java 532 | private EntityManager em; 533 | @Autowired 534 | public JinqResort(EntityManager em) { 535 | this.em = em; 536 | } 537 | private JinqStream stream(Class clazz) { 538 | return new JinqJPAStreamProvider(em.getEntityManagerFactory()).streamAll(em, clazz); 539 | } 540 | 541 | public List findGuestNamesByCompany(String company) { 542 | return stream(Guest.class) 543 | .where(g -> g.getCompany().equals(company)) 544 | .sortedBy(Guest::getGrade) 545 | .select(Guest::getName) 546 | .toList(); 547 | } 548 | ``` 549 | 550 | A query generated by JinqResort 551 | 552 | ```sql 553 | Hibernate: select guest0_.id as id1_0_, guest0_.company as company2_0_, guest0_.grade as grade3_0_, guest0_.name as name4_0_ from guest guest0_ where guest0_.company=? order by guest0_.grade ASC limit ? 554 | ``` 555 | 556 | ### [Spark](http://www.sparkjava.com/) 557 | [SparkServer.java](src/main/java/com/naver/helloworld/web/SparkServer.java) 558 | 559 | ```java 560 | import static spark.Spark.*; 561 | 562 | import com.naver.helloworld.resort.service.ResortService; 563 | 564 | public class SparkServer { 565 | public static void main(String[] args) { 566 | get("/guests/:company", (request, response) -> { 567 | String company = request.params(":company"); 568 | return "No guests from " + company; 569 | }); 570 | } 571 | } 572 | ``` 573 | 574 | [ResortServer.java](src/main/java/com/naver/helloworld/resort/ResortServer.java) (Spark + Spring) 575 | 576 | ```java 577 | @SpringBootApplication 578 | public class ResortServer { 579 | @Autowired 580 | private ResortService service; 581 | 582 | public void start() { 583 | get("/guests/:company", (request, response) -> { 584 | String company = request.params(":company"); 585 | List names = service.findGuestNamesByCompany(company); 586 | return "Guests from " + company + " : " + names; 587 | }); 588 | } 589 | 590 | public static void main(String[] args) { 591 | ApplicationContext context = SpringApplication.run(ResortServer.class); 592 | context.getBean(ResortServer.class).start(); 593 | } 594 | } 595 | ``` 596 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | description = 'Lambda of Java, Groovy, Scala, Kotlin, Xtend, Ceylon' 2 | 3 | group = "helloworld" 4 | version = "1.0" 5 | 6 | buildscript { 7 | repositories { jcenter() } 8 | dependencies { 9 | classpath 'org.xtend:xtend-gradle-plugin:0.3.6' 10 | classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.10.195' 11 | } 12 | } 13 | 14 | apply plugin: 'java' 15 | apply plugin: 'groovy' 16 | apply plugin: 'scala' 17 | apply plugin: 'org.xtend.xtend' 18 | apply plugin: 'kotlin' 19 | apply plugin: 'eclipse' 20 | apply plugin: 'idea' 21 | 22 | compileJava { 23 | sourceCompatibility = 1.8 24 | targetCompatibility = 1.8 25 | } 26 | 27 | compileGroovy { 28 | classpath.add(files('build/classes/main-unenhanced')) 29 | // workaround for conflict with the 'xtend' plugin 30 | } 31 | 32 | repositories { 33 | jcenter() 34 | maven { 35 | url "http://repo.bodar.com/" 36 | } 37 | 38 | } 39 | 40 | sourceSets { 41 | main.java.srcDirs += 'src/main/xtend' 42 | main.java.srcDirs += 'src/main/kotlin' 43 | } 44 | 45 | test { 46 | beforeTest { descriptor -> 47 | logger.lifecycle("Running test: " + descriptor) 48 | } 49 | } 50 | 51 | dependencies { 52 | compile fileTree(dir: 'libs', include: ['*.jar']) 53 | compile 'com.googlecode.lambdaj:lambdaj:2.3.3' 54 | compile 'com.google.guava:guava:17.0' 55 | compile 'org.op4j:op4j:1.2' 56 | compile 'org.functionaljava:functionaljava:4.1' 57 | compile 'com.googlecode.totallylazy:totallylazy:1049' 58 | compile 'org.apache.commons:commons-collections4:4.0' 59 | compile 'com.goldmansachs:gs-collections:5.1.0' 60 | compile 'org.codehaus.groovy:groovy-all:2.3.9' 61 | compile 'org.codehaus.jedi:jedi-core:3.0.5' 62 | compile 'org.scala-lang:scala-library:2.11.4' 63 | compile 'org.eclipse.xtext:org.eclipse.xtext.xbase.lib.slim:2.7.+' 64 | compile 'org.jetbrains.kotlin:kotlin-stdlib:0.10.195' 65 | compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.2.1.RELEASE' 66 | compile 'javax.servlet:javax.servlet-api:3.0.1' 67 | compile 'com.google.android:android:4.1.1.4' 68 | compile 'org.jinq:jinq-jpa:1.0' 69 | compile 'com.h2database:h2:1.3.166' 70 | compile ('com.sparkjava:spark-core:2.1') { 71 | exclude group: 'org.slf4j' 72 | } 73 | testCompile 'org.assertj:assertj-core:1.6.1' 74 | testCompile 'junit:junit:4.11' 75 | testCompile 'com.insightfullogic:lambda-behave:0.3' 76 | } 77 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benelog/lambda-resort/e80eb0dee83188b27744633056e691f1c7e04c60/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Aug 26 01:44:41 KST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /libs/bolts.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benelog/lambda-resort/e80eb0dee83188b27744633056e691f1c7e04c60/libs/bolts.jar -------------------------------------------------------------------------------- /src/main/ceylon/com/naver/helloworld/resort/module.ceylon: -------------------------------------------------------------------------------- 1 | module com.naver.helloworld.resort "1.0.0" { 2 | import java.base "8"; 3 | import ceylon.interop.java "1.1.0"; 4 | import ceylon.test "1.1.0"; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/ceylon/com/naver/helloworld/resort/package.ceylon: -------------------------------------------------------------------------------- 1 | shared package com.naver.helloworld.resort; 2 | -------------------------------------------------------------------------------- /src/main/ceylon/com/naver/helloworld/resort/run.ceylon: -------------------------------------------------------------------------------- 1 | import com.naver.helloworld.resort.domain { 2 | Guest 3 | } 4 | import com.naver.helloworld.resort.repository { 5 | MemoryRepository 6 | } 7 | import com.naver.helloworld.resort.service { 8 | CeylonResort 9 | } 10 | 11 | "Run the module `com.naver.helloworld.resort`." 12 | shared void run() { 13 | 14 | value repository = MemoryRepository(); 15 | repository.save( 16 | Guest(1, "jsh", "Naver", 15), 17 | Guest(2, "hny", "Line", 10), 18 | Guest(3, "chy", "Naver", 5) 19 | ); 20 | value service = CeylonResort(repository); 21 | value names = service.findGuestNamesByCompany("Naver"); 22 | print(names); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/ceylon/com/naver/helloworld/resort/service/resort.ceylon: -------------------------------------------------------------------------------- 1 | import com.naver.helloworld.resort.domain {Guest} 2 | import com.naver.helloworld.resort.repository {GuestRepository} 3 | import ceylon.interop.java { CeylonIterable } 4 | import java.util {JList = List, JArrayList = ArrayList } 5 | import java.lang {JString = String} 6 | 7 | shared class CeylonResort (GuestRepository repository) satisfies ResortService { 8 | shared actual JList findGuestNamesByCompany(String company) { 9 | value all = repository.findAll() ; 10 | value names = CeylonIterable(all) 11 | .filter((Guest g) => g.company == company) 12 | .sort(byIncreasing((Guest g) => g.grade.intValue())) 13 | .map((Guest g) => g.name); 14 | 15 | value jnames = JArrayList(); 16 | for (name in names) {jnames.add(JString(name));} 17 | return jnames; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/groovy/com/naver/helloworld/resort/repository/GroovyRepository.groovy: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.repository 2 | 3 | import java.util.List 4 | 5 | import javax.sql.DataSource; 6 | 7 | import org.springframework.jdbc.core.JdbcTemplate; 8 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 9 | import org.springframework.jdbc.core.simple.SimpleJdbcInsert; 10 | 11 | import com.naver.helloworld.resort.domain.Guest; 12 | 13 | class GroovyRepository implements GuestRepository { 14 | 15 | private static final String SELECT_ALL = "SELECT name, grade, company FROM guest"; 16 | private static final String DELETE_ALL = "DELETE FROM guest"; 17 | 18 | private JdbcTemplate jdbc; 19 | 20 | GroovyRepository(DataSource dataSource) { 21 | this.jdbc = new JdbcTemplate(dataSource); 22 | } 23 | @Override 24 | void save(Guest... guests) { 25 | SimpleJdbcInsert insertStmt = new SimpleJdbcInsert(jdbc).withTableName("guest") 26 | for ( Guest guest: guests) { 27 | BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(guest); 28 | insertStmt.execute(params); 29 | } 30 | } 31 | 32 | @Override 33 | List findAll() { 34 | jdbc.query(SELECT_ALL, { rs, rowNum -> 35 | new Guest ( 36 | rs.getInt("id"), 37 | rs.getString("name"), 38 | rs.getString("company"), 39 | rs.getInt("grade") 40 | ) 41 | } 42 | ) 43 | } 44 | 45 | void deleteAll() { 46 | jdbc.update(DELETE_ALL); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/groovy/com/naver/helloworld/resort/service/GroovyAdvancedResort.groovy: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service 2 | 3 | import com.naver.helloworld.resort.domain.Guest; 4 | import com.naver.helloworld.resort.repository.GuestRepository; 5 | 6 | class GroovyAdvancedResort implements ResortService { 7 | private GuestRepository repository 8 | 9 | GroovyAdvancedResort(GuestRepository repository) { 10 | this.repository = repository 11 | } 12 | 13 | @Override 14 | List findGuestNamesByCompany(String company) { 15 | List all = repository.findAll() 16 | all.findAll { it.company == company } 17 | .sort { it.grade } 18 | .collect { it.name } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/groovy/com/naver/helloworld/resort/service/GroovyResort.groovy: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service 2 | 3 | import com.naver.helloworld.resort.domain.Guest; 4 | import com.naver.helloworld.resort.repository.GuestRepository; 5 | 6 | class GroovyResort implements ResortService { 7 | private GuestRepository repository 8 | 9 | GroovyResort(GuestRepository repository) { 10 | this.repository = repository 11 | } 12 | 13 | @Override 14 | List findGuestNamesByCompany(String company) { 15 | List all = repository.findAll() 16 | all.findAll { g -> g.company == company } 17 | .sort { g -> g.grade } 18 | .collect { g -> g.name } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/basiclambda/CustomFunctionReference.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.basiclambda; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class CustomFunctionReference { 7 | @FunctionalInterface 8 | public static interface StringAction { 9 | void execute(String str); 10 | // void anotherExecute(); // 주석을 제거하면 컴파일 에러 11 | } 12 | 13 | public static void main(String[] args) { 14 | List alphabet = Arrays.asList("a","b","c"); 15 | 16 | StringAction f1 = (String s) -> System.out.println ("!" + s); 17 | StringAction f2 = s -> System.out.println ("!!" + s); 18 | StringAction f3 = System.out::println; 19 | 20 | doAction(alphabet, f1); 21 | doAction(alphabet, f2); 22 | doAction(alphabet, s -> System.out.println ("!!!" + s)); 23 | doAction(alphabet, f3); 24 | doAction(alphabet, System.out::println); 25 | } 26 | 27 | private static void doAction(List list, StringAction action) { 28 | list.forEach(action::execute); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/basiclambda/FunctionParameterExam.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.basiclambda; 2 | 3 | import java.util.function.IntUnaryOperator; 4 | 5 | public class FunctionParameterExam { 6 | public static void main(String[] args) { 7 | FunctionParameterExam printer = new FunctionParameterExam(); 8 | int base = 7; 9 | printer.printWeighted(weight -> base * weight, 10); 10 | } 11 | public void printWeighted(IntUnaryOperator calc, int weight) { 12 | System.out.print(calc.applyAsInt(weight)); 13 | } 14 | /* 15 | public void print( #int(int) calc, int weight) { 16 | System.out.print(calc.(weight)); 17 | } 18 | */ 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/basiclambda/JdkFunctionReference.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.basiclambda; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.function.Consumer; 6 | 7 | public class JdkFunctionReference { 8 | public static void main(String[] args) { 9 | List alphabet = Arrays.asList("a","b","c"); 10 | 11 | alphabet.forEach(System.out::println); 12 | 13 | Consumer jdkFunc = System.out::println; 14 | alphabet.forEach(jdkFunc); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/basiclambda/SimpleLambda.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.basiclambda; 2 | 3 | public class SimpleLambda { 4 | public static void main(String[] args) { 5 | Runnable labmda= () -> System.out.println(1); 6 | labmda.run(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/basiclambda/ThisDifference.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.basiclambda; 2 | 3 | public class ThisDifference { 4 | public static void main(String[] args) { 5 | new ThisDifference().print(); 6 | } 7 | public void print() { 8 | Runnable anonClass = new Runnable(){ 9 | @Override 10 | public void run() { 11 | verifyRunnable(this); 12 | } 13 | }; 14 | 15 | anonClass.run(); 16 | 17 | Runnable lambda = () -> verifyRunnable(this); 18 | lambda.run(); 19 | } 20 | 21 | private void verifyRunnable(Object obj) { 22 | System.out.println(obj instanceof Runnable); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/JinqResortRun.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.context.ConfigurableApplicationContext; 8 | 9 | import com.naver.helloworld.resort.service.JinqResort; 10 | import com.naver.helloworld.resort.service.ResortService; 11 | 12 | @SpringBootApplication 13 | public class JinqResortRun { 14 | 15 | public static void main(String[] args) { 16 | ConfigurableApplicationContext context = SpringApplication.run(JinqResortRun.class); 17 | ResortService service = context.getBean(JinqResort.class); 18 | List names = service.findGuestNamesByCompany("naver"); 19 | System.out.println(names); 20 | context.close(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/ResortServer.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort; 2 | 3 | import static spark.Spark.*; 4 | 5 | import java.util.List; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | import org.springframework.context.ApplicationContext; 11 | 12 | import com.naver.helloworld.resort.service.ResortService; 13 | 14 | @SpringBootApplication 15 | public class ResortServer { 16 | @Autowired 17 | private ResortService service; 18 | 19 | public void start() { 20 | get("/guests/:company", (request, response) -> { 21 | String company = request.params(":company"); 22 | List names = service.findGuestNamesByCompany(company); 23 | return "Guests from " + company + " : " + names; 24 | }); 25 | } 26 | 27 | public static void main(String[] args) { 28 | ApplicationContext context = SpringApplication.run(ResortServer.class); 29 | context.getBean(ResortServer.class).start(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/android/ClassicFragment.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.android; 2 | 3 | import android.R; 4 | import android.app.Fragment; 5 | import android.os.Bundle; 6 | import android.util.Log; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.View.OnClickListener; 10 | import android.view.ViewGroup; 11 | import android.widget.Button; 12 | 13 | 14 | public class ClassicFragment extends Fragment { 15 | private static final String TAG = "GuestFinderFragment"; 16 | @Override 17 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { 18 | Log.d(TAG,"on create view"); 19 | return inflater.inflate(0, container, false); 20 | } 21 | 22 | public void onViewCreated(View view, Bundle savedInstanceState) { 23 | Button calcButton = (Button) view.findViewById(R.id.button1); 24 | Button sendButton = (Button) view.findViewById(R.id.button2); 25 | 26 | calcButton.setOnClickListener(new OnClickListener() { 27 | @Override 28 | public void onClick(View v) { 29 | calculate(); 30 | } 31 | }); 32 | sendButton.setOnClickListener(new OnClickListener() { 33 | @Override 34 | public void onClick(View v) { 35 | send(); 36 | } 37 | }); 38 | } 39 | 40 | private void calculate() { 41 | } 42 | 43 | private void send() { 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/android/ModernFragment.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.android; 2 | 3 | import android.R; 4 | import android.app.Fragment; 5 | import android.os.Bundle; 6 | import android.util.Log; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Button; 11 | 12 | 13 | public class ModernFragment extends Fragment { 14 | private static final String TAG = "GuestFinderFragment"; 15 | @Override 16 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { 17 | Log.d(TAG,"on create view"); 18 | return inflater.inflate(99999, container, false); 19 | } 20 | 21 | public void onViewCreated(View view, Bundle savedInstanceState) { 22 | Button calcButton = (Button) view.findViewById(R.id.button1); 23 | Button sendButton = (Button) view.findViewById(R.id.button2); 24 | 25 | calcButton.setOnClickListener(v -> calculate()); 26 | sendButton.setOnClickListener(v -> send()); 27 | } 28 | 29 | private void calculate() { 30 | } 31 | 32 | private void send() { 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/domain/Guest.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.GenerationType; 8 | import javax.persistence.Id; 9 | 10 | 11 | /** 12 | * @author sanghyk.jung 13 | * 14 | */ 15 | @Entity 16 | public class Guest implements Serializable { 17 | private static final long serialVersionUID = 1L; 18 | private Integer id; 19 | private Integer grade; 20 | private String name; 21 | private String company; 22 | 23 | public Guest(){} 24 | public Guest(int id, String name, String company, int grade) { 25 | this.id = id; 26 | this.grade = grade; 27 | this.name = name; 28 | this.company = company; 29 | } 30 | public String getCompany() { 31 | return company; 32 | } 33 | public String getName() { 34 | return name; 35 | } 36 | public Integer getGrade() { 37 | return grade; 38 | } 39 | @Id 40 | @GeneratedValue(strategy=GenerationType.IDENTITY) 41 | public Integer getId() { 42 | return id; 43 | } 44 | 45 | public void setId(Integer id) { 46 | this.id = id; 47 | } 48 | public void setGrade(Integer grade) { 49 | this.grade = grade; 50 | } 51 | public void setName(String name) { 52 | this.name = name; 53 | } 54 | public void setCompany(String company) { 55 | this.company = company; 56 | } 57 | @Override 58 | public String toString() { 59 | return "Guest [id=" + id + ", grade=" + grade + ", name=" + name 60 | + ", company=" + company + "]"; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/repository/ClassicJdbcRepository.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.repository; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | import java.util.List; 6 | 7 | import javax.sql.DataSource; 8 | 9 | import org.springframework.jdbc.core.JdbcTemplate; 10 | import org.springframework.jdbc.core.RowMapper; 11 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 12 | import org.springframework.jdbc.core.simple.SimpleJdbcInsert; 13 | 14 | import com.naver.helloworld.resort.domain.Guest; 15 | 16 | public class ClassicJdbcRepository implements GuestRepository { 17 | private JdbcTemplate jdbc; 18 | public ClassicJdbcRepository(DataSource dataSource) { 19 | this.jdbc = new JdbcTemplate(dataSource); 20 | } 21 | 22 | private static final String SELECT_ALL = "SELECT name, grade, company FROM guest"; 23 | private static final String DELETE_ALL = "DELETE FROM guest"; 24 | 25 | @Override 26 | public void save(Guest... guests) { 27 | SimpleJdbcInsert insertStmt = new SimpleJdbcInsert(jdbc).withTableName("guest"); 28 | for ( Guest guest: guests) { 29 | BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(guest); 30 | insertStmt.execute(params); 31 | } 32 | } 33 | 34 | public List findAll() { 35 | return jdbc.query(SELECT_ALL, new RowMapper(){ 36 | @Override 37 | public Guest mapRow(ResultSet rs, int rowNum) throws SQLException { 38 | return new Guest ( 39 | rs.getInt("id"), 40 | rs.getString("name"), 41 | rs.getString("company"), 42 | rs.getInt("grade") 43 | ); 44 | } 45 | 46 | }); 47 | } 48 | 49 | @Override 50 | public void deleteAll() { 51 | jdbc.update(DELETE_ALL); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/repository/GuestCrudRepository.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.repository; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import com.naver.helloworld.resort.domain.Guest; 6 | 7 | public interface GuestCrudRepository extends CrudRepository { 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/repository/GuestRepository.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.repository; 2 | 3 | import java.util.List; 4 | 5 | import com.naver.helloworld.resort.domain.Guest; 6 | 7 | public interface GuestRepository { 8 | public void save(Guest ... guest); 9 | public List findAll (); 10 | public void deleteAll(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/repository/MemoryRepository.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.repository; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | import com.naver.helloworld.resort.domain.Guest; 8 | 9 | public class MemoryRepository implements GuestRepository { 10 | 11 | private List savedGuest = new ArrayList<>(); 12 | 13 | @Override 14 | public void save(Guest... guests) { 15 | savedGuest.addAll(Arrays.asList(guests)); 16 | } 17 | 18 | public List findAll() { 19 | return new ArrayList(savedGuest); 20 | } 21 | 22 | @Override 23 | public void deleteAll() { 24 | savedGuest.clear(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/repository/ModernJdbcRepository.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.repository; 2 | 3 | import java.util.List; 4 | 5 | import javax.sql.DataSource; 6 | 7 | import org.springframework.jdbc.core.JdbcTemplate; 8 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 9 | import org.springframework.jdbc.core.simple.SimpleJdbcInsert; 10 | 11 | import com.naver.helloworld.resort.domain.Guest; 12 | 13 | public class ModernJdbcRepository implements GuestRepository { 14 | private JdbcTemplate jdbc; 15 | public ModernJdbcRepository(DataSource dataSource) { 16 | this.jdbc = new JdbcTemplate(dataSource); 17 | } 18 | 19 | private static final String SELECT_ALL = "SELECT name, grade, company FROM guest"; 20 | private static final String DELETE_ALL = "DELETE FROM guest"; 21 | 22 | @Override 23 | public void save(Guest... guests) { 24 | SimpleJdbcInsert insertStmt = new SimpleJdbcInsert(jdbc).withTableName("guest"); 25 | for ( Guest guest: guests) { 26 | BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(guest); 27 | insertStmt.execute(params); 28 | } 29 | } 30 | 31 | public List findAll() { 32 | return jdbc.query(SELECT_ALL, (rs, rowNum) -> new Guest ( 33 | rs.getInt("id"), 34 | rs.getString("name"), 35 | rs.getString("company"), 36 | rs.getInt("grade") 37 | ) 38 | ); 39 | } 40 | 41 | @Override 42 | public void deleteAll() { 43 | jdbc.update(DELETE_ALL); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/BoltsResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.List; 4 | 5 | import ru.yandex.bolts.collection.Cf; 6 | import ru.yandex.bolts.function.Function; 7 | import ru.yandex.bolts.function.Function1B; 8 | 9 | import com.naver.helloworld.resort.domain.Guest; 10 | import com.naver.helloworld.resort.repository.GuestRepository; 11 | 12 | public class BoltsResort implements ResortService { 13 | private GuestRepository repository; 14 | public BoltsResort(GuestRepository repository) { 15 | this.repository = repository; 16 | } 17 | 18 | public List findGuestNamesByCompany(final String company) { 19 | List all = repository.findAll(); 20 | return Cf.list(all) 21 | .filter(new Function1B() { 22 | public boolean apply(Guest g) { 23 | return company.equals(g.getCompany()); 24 | } 25 | }) 26 | .sortBy(new Function() { 27 | public Integer apply(Guest g) { 28 | return g.getGrade(); 29 | } 30 | }) 31 | .map(new Function() { 32 | public String apply(Guest g) { 33 | return g.getName(); 34 | } 35 | }); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/ClassicJavaResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.Comparator; 6 | import java.util.List; 7 | 8 | import com.naver.helloworld.resort.domain.Guest; 9 | import com.naver.helloworld.resort.repository.GuestRepository; 10 | 11 | public class ClassicJavaResort implements ResortService { 12 | private GuestRepository repository; 13 | public ClassicJavaResort(GuestRepository repository) { 14 | this.repository = repository; 15 | } 16 | 17 | public List findGuestNamesByCompany(String company) { 18 | List all = repository.findAll(); 19 | 20 | List filtered = filter(all, company); 21 | sort(filtered); 22 | return mapNames(filtered); 23 | } 24 | 25 | private List filter(List guests, String company) { 26 | List filtered = new ArrayList<>(); 27 | for(Guest guest : guests ) { 28 | if (company.equals(guest.getCompany())) { 29 | filtered.add(guest); 30 | } 31 | } 32 | return filtered; 33 | } 34 | 35 | private void sort(List guests) { 36 | Collections.sort(guests, new Comparator() { 37 | @Override 38 | public int compare(Guest o1, Guest o2) { 39 | return Integer.compare(o1.getGrade(), o2.getGrade()); 40 | } 41 | }); 42 | } 43 | 44 | private List mapNames(List guests) { 45 | List names = new ArrayList<>(); 46 | for(Guest guest : guests ) { 47 | names.add(guest.getName()); 48 | } 49 | return names; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/CommonsCollectionsResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.Collections; 6 | import java.util.Comparator; 7 | import java.util.List; 8 | 9 | import org.apache.commons.collections4.CollectionUtils; 10 | import org.apache.commons.collections4.ListUtils; 11 | import org.apache.commons.collections4.Predicate; 12 | import org.apache.commons.collections4.Transformer; 13 | 14 | import com.naver.helloworld.resort.domain.Guest; 15 | import com.naver.helloworld.resort.repository.GuestRepository; 16 | 17 | public class CommonsCollectionsResort implements ResortService { 18 | 19 | private GuestRepository repository; 20 | 21 | public CommonsCollectionsResort(GuestRepository repository) { 22 | this.repository = repository; 23 | } 24 | 25 | @Override 26 | public List findGuestNamesByCompany(final String company) { 27 | List all = repository.findAll(); 28 | List filtered = ListUtils.select(all, new Predicate() { 29 | public boolean evaluate(Guest g) { 30 | return company.equals(g.getCompany()); 31 | } 32 | }); 33 | 34 | Collections.sort(filtered, new Comparator() { 35 | @Override 36 | public int compare(Guest o1, Guest o2) { 37 | return Integer.compare(o1.getGrade(), o2.getGrade()); 38 | } 39 | }); 40 | 41 | Collection names = CollectionUtils.collect(filtered, new Transformer(){ 42 | public String transform(Guest g) { 43 | return g.getName(); 44 | } 45 | }); 46 | 47 | return new ArrayList<>(names); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/FunctionalJavaResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.Collection; 6 | import java.util.List; 7 | 8 | import com.naver.helloworld.resort.domain.Guest; 9 | import com.naver.helloworld.resort.repository.GuestRepository; 10 | 11 | import fj.F; 12 | import fj.Ord; 13 | import fj.Ordering; 14 | import fj.data.Stream; 15 | 16 | public class FunctionalJavaResort implements ResortService { 17 | private GuestRepository repository; 18 | public FunctionalJavaResort(GuestRepository repository) { 19 | this.repository = repository; 20 | } 21 | 22 | public List findGuestNamesByCompany(final String company) { 23 | List all = repository.findAll(); 24 | 25 | Collection mapped = Stream.iterableStream(all) 26 | .filter(new F() { 27 | public Boolean f(Guest g){ 28 | return company.equals(g.getCompany()); 29 | } 30 | }) 31 | .sort(Ord.ord( 32 | new F>() { 33 | public F f(final Guest a1) { 34 | return new F() { 35 | public Ordering f(final Guest a2) { 36 | int x = Integer.compare(a1.getGrade(), a2.getGrade()); 37 | return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; 38 | } 39 | }; 40 | } 41 | })) 42 | .map(new F() { 43 | @Override 44 | public String f(Guest g) { 45 | return g.getName(); 46 | } 47 | 48 | }) 49 | .toCollection(); 50 | return new ArrayList(mapped); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/GsCollectionsResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.List; 4 | 5 | import com.gs.collections.api.block.function.Function; 6 | import com.gs.collections.api.block.predicate.Predicate; 7 | import com.gs.collections.impl.list.mutable.FastList; 8 | import com.naver.helloworld.resort.domain.Guest; 9 | import com.naver.helloworld.resort.repository.GuestRepository; 10 | 11 | public class GsCollectionsResort implements ResortService { 12 | private GuestRepository repository; 13 | 14 | public GsCollectionsResort(GuestRepository repository) { 15 | this.repository = repository; 16 | } 17 | 18 | @SuppressWarnings("serial") 19 | @Override 20 | public List findGuestNamesByCompany(final String company) { 21 | List all = repository.findAll(); 22 | return FastList.newList(all) 23 | .select(new Predicate() { 24 | public boolean accept(Guest g) { 25 | return company.equals(g.getCompany()); 26 | } 27 | }) 28 | .sortThisBy(new Function() { 29 | public Integer valueOf(Guest g) { 30 | return g.getGrade(); 31 | } 32 | }) 33 | .collect(new Function () { 34 | public String valueOf(Guest g) { 35 | return g.getName(); 36 | } 37 | }); 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/GuavaResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.List; 4 | 5 | import com.google.common.base.Function; 6 | import com.google.common.base.Predicate; 7 | import com.google.common.collect.FluentIterable; 8 | import com.google.common.collect.Ordering; 9 | import com.naver.helloworld.resort.domain.Guest; 10 | import com.naver.helloworld.resort.repository.GuestRepository; 11 | 12 | public class GuavaResort implements ResortService { 13 | private GuestRepository repository; 14 | public GuavaResort(GuestRepository repository) { 15 | this.repository = repository; 16 | } 17 | 18 | public List findGuestNamesByCompany(final String company) { 19 | List all = repository.findAll(); 20 | 21 | List sorted = FluentIterable.from(all) 22 | .filter(new Predicate() { 23 | public boolean apply(Guest g) { 24 | return company.equals(g.getCompany()); 25 | } 26 | }) 27 | .toSortedList(Ordering.natural().onResultOf( 28 | new Function() { 29 | public Integer apply(Guest g) { 30 | return g.getGrade(); 31 | } 32 | })); 33 | 34 | return FluentIterable.from(sorted) 35 | .transform(new Function() { 36 | public String apply(Guest g) { 37 | return g.getName(); 38 | } 39 | }) 40 | .toList(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/JediResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.List; 4 | 5 | import jedi.functional.Comparables; 6 | import jedi.functional.Filter; 7 | import jedi.functional.FunctionalPrimitives; 8 | import jedi.functional.Functor; 9 | 10 | import com.naver.helloworld.resort.domain.Guest; 11 | import com.naver.helloworld.resort.repository.GuestRepository; 12 | 13 | public class JediResort implements ResortService { 14 | 15 | private GuestRepository repository; 16 | 17 | public JediResort(GuestRepository repository) { 18 | this.repository = repository; 19 | } 20 | 21 | @Override 22 | public List findGuestNamesByCompany(final String company) { 23 | List all = repository.findAll(); 24 | List filtered = FunctionalPrimitives.select(all, new Filter() { 25 | public Boolean execute(Guest g) { 26 | return company.equals(g.getCompany()); 27 | } 28 | }); 29 | List sorted = Comparables.sort(filtered, new Functor() { 30 | public Integer execute(Guest g) { 31 | return g.getGrade(); 32 | } 33 | }); 34 | return FunctionalPrimitives.map(sorted, new Functor() { 35 | public String execute(Guest g) { 36 | return g.getName(); 37 | } 38 | 39 | }); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/JinqResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.EntityManager; 6 | 7 | import org.jinq.jpa.JinqJPAStreamProvider; 8 | import org.jinq.orm.stream.JinqStream; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Repository; 11 | 12 | import com.naver.helloworld.resort.domain.Guest; 13 | 14 | @Repository 15 | public class JinqResort implements ResortService { 16 | @Autowired 17 | public JinqResort(EntityManager em) { 18 | this.em = em; 19 | } 20 | private EntityManager em; 21 | public List findGuestNamesByCompany(String company) { 22 | return stream(Guest.class) 23 | .where(g -> g.getCompany().equals(company)) 24 | .sortedBy(Guest::getGrade) 25 | .select(Guest::getName) 26 | .toList(); 27 | } 28 | 29 | private JinqStream stream(Class clazz) { 30 | return new JinqJPAStreamProvider(em.getEntityManagerFactory()).streamAll(em, clazz); 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/LambdaJResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import static ch.lambdaj.Lambda.*; 4 | import static org.hamcrest.Matchers.*; 5 | 6 | import java.util.List; 7 | 8 | import ch.lambdaj.collection.LambdaCollections; 9 | 10 | import com.naver.helloworld.resort.domain.Guest; 11 | import com.naver.helloworld.resort.repository.GuestRepository; 12 | 13 | public class LambdaJResort implements ResortService { 14 | private GuestRepository repository; 15 | public LambdaJResort(GuestRepository repository) { 16 | this.repository = repository; 17 | } 18 | 19 | public List findGuestNamesByCompany(final String company) { 20 | List all = repository.findAll(); 21 | return LambdaCollections.with(all) 22 | .retain(having(on(Guest.class).getCompany(), equalTo(company))) 23 | .sort(on(Guest.class).getGrade()) 24 | .extract(on(Guest.class).getName()); 25 | /* 26 | last line has a same effect with 27 | 28 | 1) 29 | .convert(new Converter() { 30 | @Override 31 | public String convert(Guest g) { 32 | g.getName(); 33 | } 34 | }) 35 | 36 | 2) 37 | convert(new PropertyExtractor("name")); 38 | */ 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/ModernJavaAdvancedResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.Comparator; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | import com.naver.helloworld.resort.domain.Guest; 8 | import com.naver.helloworld.resort.repository.GuestRepository; 9 | public class ModernJavaAdvancedResort implements ResortService { 10 | private GuestRepository repository; 11 | public ModernJavaAdvancedResort(GuestRepository repository) { 12 | this.repository = repository; 13 | } 14 | 15 | public List findGuestNamesByCompany(String company) { 16 | List guests = repository.findAll(); 17 | return guests.stream() 18 | .filter(g -> company.equals(g.getCompany())) 19 | .sorted(Comparator.comparing(Guest::getGrade)) 20 | .map(Guest::getName) 21 | .collect(Collectors.toList()); 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/ModernJavaBreak2Resort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.Comparator; 4 | import java.util.List; 5 | import java.util.function.Function; 6 | import java.util.function.Predicate; 7 | import java.util.stream.Collector; 8 | import java.util.stream.Collectors; 9 | import java.util.stream.Stream; 10 | 11 | import com.naver.helloworld.resort.domain.Guest; 12 | import com.naver.helloworld.resort.repository.GuestRepository; 13 | 14 | public class ModernJavaBreak2Resort implements ResortService { 15 | private GuestRepository repository; 16 | public ModernJavaBreak2Resort(GuestRepository repository) { 17 | this.repository = repository; 18 | } 19 | 20 | public List findGuestNamesByCompany(String company) { 21 | List all = repository.findAll(); 22 | 23 | Stream stream = all.stream(); 24 | 25 | // filtering 26 | Predicate filterFunc = g -> company.equals(g.getCompany()); 27 | Stream filtered = stream.filter(filterFunc); 28 | 29 | // sorting 30 | Comparator sortFunc = Comparator.comparing(Guest::getGrade); 31 | Stream sorted = filtered.sorted(sortFunc); 32 | 33 | // mapping 34 | Function mapFunc = Guest::getName; 35 | Stream mapped = sorted.map(mapFunc); 36 | Collector> collector = Collectors.toList(); 37 | return mapped.collect(collector); 38 | } 39 | } -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/ModernJavaBreakResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.Comparator; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | import java.util.stream.Stream; 7 | 8 | import com.naver.helloworld.resort.domain.Guest; 9 | import com.naver.helloworld.resort.repository.GuestRepository; 10 | 11 | public class ModernJavaBreakResort implements ResortService { 12 | private GuestRepository repository; 13 | public ModernJavaBreakResort(GuestRepository repository) { 14 | this.repository = repository; 15 | } 16 | 17 | public List findGuestNamesByCompany(String company) { 18 | List all = repository.findAll(); 19 | Stream stream = all.stream(); 20 | // filter 21 | Stream filtered = stream.filter(g -> company.equals(g.getCompany())); 22 | // sort 23 | Stream sorted = filtered.sorted(Comparator.comparing(Guest::getGrade)); 24 | // map 25 | Stream mapped = sorted.map(Guest::getName); 26 | return mapped.collect(Collectors.toList()); 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/ModernJavaResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.Comparator; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | import com.naver.helloworld.resort.domain.Guest; 8 | import com.naver.helloworld.resort.repository.GuestRepository; 9 | public class ModernJavaResort implements ResortService { 10 | private GuestRepository repository; 11 | public ModernJavaResort(GuestRepository repository) { 12 | this.repository = repository; 13 | } 14 | 15 | public List findGuestNamesByCompany(String company) { 16 | List guests = repository.findAll(); 17 | return guests.stream() 18 | .filter(g -> company.equals(g.getCompany())) 19 | .sorted(Comparator.comparing(g -> g.getGrade())) 20 | .map(g -> g.getName()) 21 | .collect(Collectors.toList()); 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/Op4JResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.List; 4 | 5 | import org.op4j.Op; 6 | import org.op4j.functions.ExecCtx; 7 | import org.op4j.functions.IFunction; 8 | 9 | import com.naver.helloworld.resort.domain.Guest; 10 | import com.naver.helloworld.resort.repository.GuestRepository; 11 | 12 | public class Op4JResort implements ResortService { 13 | private GuestRepository repository; 14 | public Op4JResort(GuestRepository repository) { 15 | this.repository = repository; 16 | } 17 | 18 | public List findGuestNamesByCompany(final String company) { 19 | List all = repository.findAll(); 20 | return Op.on(all) 21 | .removeAllFalse(new IFunction() { 22 | public Boolean execute(Guest g, ExecCtx ctx) throws Exception { 23 | return company.equals(g.getCompany()); 24 | } 25 | }) 26 | .sortBy(new IFunction() { 27 | public Integer execute(Guest g, ExecCtx ctx) throws Exception { 28 | return g.getGrade(); 29 | } 30 | }) 31 | .map(new IFunction() { 32 | public String execute(Guest g, ExecCtx ctx) throws Exception { 33 | return g.getName(); 34 | } 35 | }).get(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/ResortService.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.List; 4 | 5 | public interface ResortService { 6 | public List findGuestNamesByCompany (String company); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/resort/service/TotallyLazyResort.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import java.util.List; 4 | 5 | import com.googlecode.totallylazy.Callable1; 6 | import com.googlecode.totallylazy.Predicate; 7 | import com.googlecode.totallylazy.Sequences; 8 | import com.naver.helloworld.resort.domain.Guest; 9 | import com.naver.helloworld.resort.repository.GuestRepository; 10 | 11 | public class TotallyLazyResort implements ResortService { 12 | private GuestRepository repository; 13 | public TotallyLazyResort(GuestRepository repository) { 14 | this.repository = repository; 15 | } 16 | 17 | @Override 18 | public List findGuestNamesByCompany(final String company) { 19 | List all = repository.findAll(); 20 | return Sequences.sequence(all) 21 | .filter(new Predicate() { 22 | public boolean matches(Guest g) { 23 | return company.equals(g.getCompany()); 24 | } 25 | }) 26 | .sortBy(new Callable1(){ 27 | public Integer call(Guest g) { 28 | return g.getGrade(); 29 | } 30 | }) 31 | .map(new Callable1(){ 32 | public String call(Guest g) { 33 | return g.getName(); 34 | } 35 | }).toList(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/web/ClassicAsyncServlet.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.web; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.AsyncContext; 5 | import javax.servlet.ServletException; 6 | import javax.servlet.annotation.WebServlet; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | @WebServlet(name = "AsyncDispatchServlet", urlPatterns = { "/asyncDispatch" }, asyncSupported = true) 12 | public class ClassicAsyncServlet extends HttpServlet { 13 | private static final long serialVersionUID = 222L; 14 | @Override 15 | public void doGet(final HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 16 | final AsyncContext asyncContext = request.startAsync(); 17 | asyncContext.start(new Runnable(){ 18 | public void run(){ 19 | // do long running job 20 | asyncContext.dispatch("/threadNames.jsp"); 21 | } 22 | }); 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/web/ModernAsyncServlet.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.web; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.AsyncContext; 5 | import javax.servlet.ServletException; 6 | import javax.servlet.annotation.WebServlet; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | @WebServlet(name = "AsyncDispatchServlet", urlPatterns = { "/asyncDispatch" }, asyncSupported = true) 12 | public class ModernAsyncServlet extends HttpServlet { 13 | private static final long serialVersionUID = 222L; 14 | 15 | @Override 16 | public void doGet(final HttpServletRequest request, 17 | HttpServletResponse response) throws ServletException, IOException { 18 | AsyncContext asyncContext = request.startAsync(); 19 | asyncContext.start(() -> { 20 | // do long running job 21 | asyncContext.dispatch("/threadNames.jsp"); 22 | }); 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/java/com/naver/helloworld/web/SparkServer.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.web; 2 | 3 | import static spark.Spark.*; 4 | 5 | public class SparkServer { 6 | public static void main(String[] args) { 7 | get("/guests/:company", (request, response) -> { 8 | String company = request.params(":company"); 9 | return "No guests from " + company; 10 | }); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/kotlin/com/naver/helloworld/resort/service/KotlinAdvancedResort.kt: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service 2 | 3 | import com.naver.helloworld.resort.repository.GuestRepository 4 | import java.util.Comparator 5 | import com.naver.helloworld.resort.domain.Guest 6 | import java.util.stream.Collectors 7 | 8 | public class KotlinAdvancedResort (private val repository: GuestRepository) : ResortService { 9 | override fun findGuestNamesByCompany(company: String): List { 10 | val all = repository.findAll() 11 | return all.filter { it.getCompany() == company } 12 | .sortBy { it.getGrade() } 13 | .map { it.getName() } 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/naver/helloworld/resort/service/KotlinResort.kt: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service 2 | 3 | import com.naver.helloworld.resort.repository.GuestRepository 4 | import java.util.Comparator 5 | import com.naver.helloworld.resort.domain.Guest 6 | import java.util.stream.Collectors 7 | 8 | public class KotlinResort (private val repository: GuestRepository) : ResortService { 9 | override fun findGuestNamesByCompany(company: String): List { 10 | val all = repository.findAll() 11 | return all.filter { g -> g.getCompany() == company } 12 | .sortBy { g -> g.getGrade() } 13 | .map { g -> g.getName() } 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.jpa.show-sql: true 2 | spring.jpa.hibernate.naming_strategy: org.hibernate.cfg.ImprovedNamingStrategy 3 | spring.jpa.hibernate.ddl-auto: validate -------------------------------------------------------------------------------- /src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO guest(name, company, grade) VALUES( 'jsh','Naver',15); 2 | INSERT INTO guest(name, company, grade) VALUES( 'hny','Line',10); 3 | INSERT INTO guest(name, company, grade) VALUES( 'chy','Naver',15); -------------------------------------------------------------------------------- /src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create table guest ( id integer generated by default as identity, company varchar(255), grade integer, name varchar(255),primary key (id)) 2 | -------------------------------------------------------------------------------- /src/main/scala/com/naver/helloworld/resort/service/ScalaAdvancedResort.scala: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service 2 | 3 | import com.naver.helloworld.resort.repository.GuestRepository 4 | 5 | import scala.collection.JavaConversions._ 6 | 7 | class ScalaAdvancedResort(repository: GuestRepository) extends ResortService { 8 | override def findGuestNamesByCompany(company: String): java.util.List[String] = { 9 | val all = repository.findAll 10 | all.filter ( _.getCompany == company) 11 | .sortBy ( _.getGrade ) 12 | .map ( _.getName ) 13 | } 14 | } -------------------------------------------------------------------------------- /src/main/scala/com/naver/helloworld/resort/service/ScalaResort.scala: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service 2 | 3 | import com.naver.helloworld.resort.repository.GuestRepository 4 | import scala.collection.JavaConversions._ 5 | 6 | class ScalaResort(repository: GuestRepository) extends ResortService { 7 | override def findGuestNamesByCompany(company: String): java.util.List[String] = { 8 | val all = repository.findAll 9 | all.filter ( g => g.getCompany == company) 10 | .sortBy ( g => g.getGrade ) 11 | .map ( g => g.getName ) 12 | } 13 | } -------------------------------------------------------------------------------- /src/main/xtend/com/naver/helloworld/resort/service/.gitignore: -------------------------------------------------------------------------------- 1 | /.XtendService.java._trace 2 | -------------------------------------------------------------------------------- /src/main/xtend/com/naver/helloworld/resort/service/XtendAdvancedResort.xtend: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service 2 | 3 | import com.naver.helloworld.resort.repository.GuestRepository 4 | 5 | class XtendAdvancedResort implements ResortService { 6 | GuestRepository repository 7 | new (GuestRepository repository) { 8 | this.repository = repository 9 | } 10 | override findGuestNamesByCompany(String aCompany) { 11 | val all = repository.findAll() 12 | 13 | all.filter [company == aCompany] 14 | .sortBy[grade] 15 | .map[name] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/xtend/com/naver/helloworld/resort/service/XtendResort.xtend: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service 2 | 3 | import com.naver.helloworld.resort.repository.GuestRepository 4 | 5 | class XtendResort implements ResortService { 6 | GuestRepository repository 7 | new (GuestRepository repository) { 8 | this.repository = repository 9 | } 10 | override findGuestNamesByCompany(String company) { 11 | val all = repository.findAll() 12 | all.filter [g | g.company == company ] 13 | .sortBy[g | g.grade] 14 | .map[g | g.name] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/naver/helloworld/resort/service/GroovyResortTest.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import static org.assertj.core.api.Assertions.*; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | 10 | import com.naver.helloworld.resort.domain.Guest; 11 | import com.naver.helloworld.resort.repository.GuestRepository; 12 | import com.naver.helloworld.resort.repository.MemoryRepository; 13 | 14 | public class GroovyResortTest { 15 | GuestRepository repository = new MemoryRepository(); 16 | 17 | @Test 18 | public void groovy(){ 19 | assertImpl(new GroovyResort(repository)); 20 | } 21 | 22 | @Test 23 | public void groovyUsingIt(){ 24 | assertImpl(new GroovyAdvancedResort(repository)); 25 | } 26 | 27 | private void assertImpl(ResortService service) { 28 | repository.save( 29 | new Guest(1, "jsh", "Naver", 15), 30 | new Guest(2, "hny", "Line", 10), 31 | new Guest(3, "chy", "Naver", 5) 32 | ); 33 | 34 | List names = service.findGuestNamesByCompany("Naver"); 35 | assertThat(names).isEqualTo(Arrays.asList("chy","jsh")); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/naver/helloworld/resort/service/JavaResortTest.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import static org.assertj.core.api.Assertions.*; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | 10 | import com.naver.helloworld.resort.domain.Guest; 11 | import com.naver.helloworld.resort.repository.GuestRepository; 12 | import com.naver.helloworld.resort.repository.MemoryRepository; 13 | 14 | public class JavaResortTest { 15 | GuestRepository repository = new MemoryRepository(); 16 | 17 | @Test 18 | public void classjava(){ 19 | assertImpl(new ClassicJavaResort(repository)); 20 | } 21 | 22 | @Test 23 | public void modernJava(){ 24 | assertImpl(new ModernJavaResort(repository)); 25 | } 26 | 27 | @Test 28 | public void modernJavaWithMethodReference(){ 29 | assertImpl(new ModernJavaAdvancedResort(repository)); 30 | } 31 | 32 | @Test 33 | public void bolts(){ 34 | assertImpl(new BoltsResort(repository)); 35 | } 36 | 37 | @Test 38 | public void op4j(){ 39 | assertImpl(new Op4JResort(repository)); 40 | } 41 | 42 | @Test 43 | public void guava(){ 44 | assertImpl(new GuavaResort(repository)); 45 | } 46 | 47 | @Test 48 | public void lambdaj(){ 49 | assertImpl(new LambdaJResort(repository)); 50 | } 51 | 52 | @Test 53 | public void functionalJava(){ 54 | assertImpl(new FunctionalJavaResort(repository)); 55 | } 56 | 57 | @Test 58 | public void totallyLazy(){ 59 | assertImpl(new TotallyLazyResort(repository)); 60 | } 61 | 62 | @Test 63 | public void gsCollections(){ 64 | assertImpl(new GsCollectionsResort(repository)); 65 | } 66 | 67 | @Test 68 | public void commonsCollections(){ 69 | assertImpl(new CommonsCollectionsResort(repository)); 70 | } 71 | 72 | @Test 73 | public void jedi(){ 74 | assertImpl(new JediResort(repository)); 75 | } 76 | 77 | private void assertImpl(ResortService service) { 78 | repository.save( 79 | new Guest(1, "jsh", "Naver", 15), 80 | new Guest(2, "hny", "Line", 10), 81 | new Guest(3, "chy", "Naver", 5) 82 | ); 83 | 84 | List names = service.findGuestNamesByCompany("Naver"); 85 | assertThat(names).isEqualTo(Arrays.asList("chy","jsh")); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/test/java/com/naver/helloworld/resort/service/KotlinResortTest.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import static org.assertj.core.api.Assertions.*; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import org.junit.Test; 8 | 9 | import com.naver.helloworld.resort.domain.Guest; 10 | import com.naver.helloworld.resort.repository.GuestRepository; 11 | import com.naver.helloworld.resort.repository.MemoryRepository; 12 | 13 | public class KotlinResortTest { 14 | GuestRepository repository = new MemoryRepository(); 15 | 16 | @Test 17 | public void kotlin(){ 18 | assertImpl(new KotlinResort(repository)); 19 | } 20 | 21 | @Test 22 | public void kotlinWithIt(){ 23 | assertImpl(new KotlinAdvancedResort(repository)); 24 | } 25 | 26 | private void assertImpl(ResortService service) { 27 | repository.save( 28 | new Guest(1, "jsh", "naver", 15), 29 | new Guest(2, "hny", "daum", 10), 30 | new Guest(3, "chy", "naver", 5) 31 | ); 32 | 33 | List names = service.findGuestNamesByCompany("naver"); 34 | assertThat(names).isEqualTo(Arrays.asList("chy","jsh")); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/naver/helloworld/resort/service/ResortServiceSpec.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import static com.insightfullogic.lambdabehave.Suite.*; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | import org.junit.runner.RunWith; 9 | 10 | import com.insightfullogic.lambdabehave.JunitSuiteRunner; 11 | import com.naver.helloworld.resort.domain.Guest; 12 | import com.naver.helloworld.resort.repository.GuestRepository; 13 | import com.naver.helloworld.resort.repository.MemoryRepository; 14 | 15 | @RunWith(JunitSuiteRunner.class) 16 | public class ResortServiceSpec {{ 17 | GuestRepository repository = new MemoryRepository(); 18 | ResortService service = new ModernJavaResort(repository); 19 | 20 | describe("ResortService with modern Java", it -> { 21 | it.isSetupWith(() -> { 22 | repository.save( 23 | new Guest(1, "jsh", "Naver", 15), 24 | new Guest(2, "hny", "Line", 10), 25 | new Guest(3, "chy", "Naver", 5) 26 | ); 27 | 28 | }); 29 | it.isConcludedWith(repository::deleteAll); 30 | 31 | it.should("find names of guests by company ", expect -> { 32 | List names = service.findGuestNamesByCompany("Naver"); 33 | expect.that(names).isEqualTo(Arrays.asList("chy","jsh")); 34 | }); 35 | }); 36 | }} 37 | -------------------------------------------------------------------------------- /src/test/java/com/naver/helloworld/resort/service/ScalaResortTest.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import static org.assertj.core.api.Assertions.*; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import org.junit.Test; 8 | 9 | import com.naver.helloworld.resort.domain.Guest; 10 | import com.naver.helloworld.resort.repository.GuestRepository; 11 | import com.naver.helloworld.resort.repository.MemoryRepository; 12 | 13 | public class ScalaResortTest { 14 | GuestRepository repository = new MemoryRepository(); 15 | 16 | @Test 17 | public void scala(){ 18 | assertImpl(new ScalaResort(repository)); 19 | } 20 | 21 | @Test 22 | public void scalaWithUnderscore(){ 23 | assertImpl(new ScalaAdvancedResort(repository)); 24 | } 25 | 26 | private void assertImpl(ResortService service) { 27 | repository.save( 28 | new Guest(1, "jsh", "Naver", 15), 29 | new Guest(2, "hny", "Line", 10), 30 | new Guest(3, "chy", "Naver", 5) 31 | ); 32 | 33 | List names = service.findGuestNamesByCompany("Naver"); 34 | assertThat(names).isEqualTo(Arrays.asList("chy","jsh")); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/naver/helloworld/resort/service/Workaround.xtend: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service 2 | 3 | class Workaround { 4 | // Without this file, 'xtend plugin' cannot copy 'test-unhanced/java' to 'test/java 5 | } -------------------------------------------------------------------------------- /src/test/java/com/naver/helloworld/resort/service/XtendResortTest.java: -------------------------------------------------------------------------------- 1 | package com.naver.helloworld.resort.service; 2 | 3 | import static org.assertj.core.api.Assertions.*; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import org.junit.Test; 8 | 9 | import com.naver.helloworld.resort.domain.Guest; 10 | import com.naver.helloworld.resort.repository.GuestRepository; 11 | import com.naver.helloworld.resort.repository.MemoryRepository; 12 | 13 | public class XtendResortTest { 14 | GuestRepository repository = new MemoryRepository(); 15 | 16 | @Test 17 | public void xtend(){ 18 | assertImpl(new XtendResort(repository)); 19 | } 20 | 21 | @Test 22 | public void xtendWhiout(){ 23 | assertImpl(new XtendAdvancedResort(repository)); 24 | } 25 | 26 | private void assertImpl(ResortService service) { 27 | repository.save( 28 | new Guest(1, "jsh", "Naver", 15), 29 | new Guest(2, "hny", "Line", 10), 30 | new Guest(3, "chy", "Naver", 5) 31 | ); 32 | 33 | List names = service.findGuestNamesByCompany("Naver"); 34 | assertThat(names).isEqualTo(Arrays.asList("chy","jsh")); 35 | } 36 | } 37 | --------------------------------------------------------------------------------