Mercurial > hg > Members > nobuyasu > jungle-network
comparison src/jungle/test/functionalJava/ListTest.java @ 56:ccfe9b5e8f11
bug LogUpdateCodeSegment
author | one |
---|---|
date | Sun, 14 Jul 2013 21:26:49 +0900 |
parents | 3d78d438f97b |
children |
comparison
equal
deleted
inserted
replaced
55:25edf76b65dc | 56:ccfe9b5e8f11 |
---|---|
1 package jungle.test.functionalJava; | 1 package jungle.test.functionalJava; |
2 | 2 |
3 import java.util.Iterator; | 3 import java.util.Iterator; |
4 import java.util.concurrent.atomic.AtomicInteger; | |
4 | 5 |
5 import fj.P2; | 6 import fj.P2; |
6 import fj.data.List; | 7 import fj.data.List; |
7 | 8 |
8 public class ListTest{ | 9 public class ListTest { |
9 | 10 |
10 public static void main(String[] args) { | 11 public static void main(String[] args) { |
11 List<Integer> list = List.nil(); | 12 List<Integer> list = List.nil(); |
12 list = list.cons(1); | |
13 list = list.cons(2); | 13 list = list.cons(2); |
14 list = list.cons(4); | 14 list = list.cons(3); |
15 list = list.cons(5); | |
16 list = list.snoc(1); | |
15 System.out.println("list :"+list); | 17 System.out.println("list :"+list); |
18 System.out.println("list.reverse() :"+list.reverse()); | |
16 System.out.println("list.index(0) :"+list.index(0)); | 19 System.out.println("list.index(0) :"+list.index(0)); |
17 System.out.println("list.head() :"+ list.head()); | 20 System.out.println("list.head() :"+ list.head()); |
18 System.out.println("list.tail() :"+list.tail()); | 21 System.out.println("list.tail() :"+list.tail()); |
19 System.out.println("list.splitAt(2)"); | 22 System.out.println("list.splitAt(2)"); |
20 P2<List<Integer>, List<Integer>> p2 = list.splitAt(2); | 23 P2<List<Integer>, List<Integer>> p2 = list.splitAt(2); |
21 List<Integer> list1 = p2._1(); | 24 List<Integer> list1 = p2._1(); |
22 List<Integer> list2 = p2._2(); | 25 List<Integer> list2 = p2._2(); |
23 System.out.println(list1); | 26 System.out.println(list1); |
24 System.out.println(list2); | 27 System.out.println(list2); |
25 | 28 |
26 final int INSERT_NUM = 3; | 29 final int INSERT_NUM = 4; |
27 list = insertInteger(list, INSERT_NUM); | 30 list = insertInteger(list, INSERT_NUM); |
28 System.out.println("newList :"+ list); | 31 System.out.println("newList :"+ list); |
32 | |
33 | |
34 | |
29 } | 35 } |
30 | 36 |
31 public static List<Integer> insertInteger(List<Integer> list, final int insertNum) { | 37 public static List<Integer> insertInteger(List<Integer> list, final int insertNum) { |
32 int count = 0; | 38 int count = 0; |
33 for(Iterator<Integer> iter = list.iterator(); iter.hasNext();){ | 39 for(Iterator<Integer> iter = list.iterator(); iter.hasNext();){ |