@@ -4952,7 +4952,9 @@ public static String generateSubrangeOp() // for Java
49524952 " }\n \n " ;
49534953
49544954 res = res + " public static List subrange(List l, int i, int j)\n " ;
4955- res = res + " { List tmp = new Vector(); \n " +
4955+ res = res + " { List tmp = new Vector(); \n " +
4956+ " if (i < 0) { i = l.size() + i; }\n " +
4957+ " if (j < 0) { j = l.size() + j; }\n " +
49564958 " for (int k = i-1; k < j; k++)\n " +
49574959 " { tmp.add(l.get(k)); } \n " +
49584960 " return tmp; \n " +
@@ -4980,6 +4982,8 @@ public static String generateSubrangeOpJava6() // for Java6
49804982
49814983 res = res + " public static ArrayList subrange(ArrayList l, int i, int j)\n " ;
49824984 res = res + " { ArrayList tmp = new ArrayList(); \n " +
4985+ " if (i < 0) { i = l.size() + i; }\n " +
4986+ " if (j < 0) { j = l.size() + j; }\n " +
49834987 " for (int k = i-1; k < j; k++)\n " +
49844988 " { tmp.add(l.get(k)); } \n " +
49854989 " return tmp; \n " +
@@ -5007,6 +5011,8 @@ public static String generateSubrangeOpJava7() // for Java7
50075011
50085012 res = res + " public static <T> ArrayList<T> subrange(ArrayList<T> l, int i, int j)\n " ;
50095013 res = res + " { ArrayList<T> tmp = new ArrayList<T>(); \n " +
5014+ " if (i < 0) { i = l.size() + i; }\n " +
5015+ " if (j < 0) { j = l.size() + j; }\n " +
50105016 " for (int k = i-1; k < j; k++)\n " +
50115017 " { tmp.add(l.get(k)); } \n " +
50125018 " return tmp; \n " +
@@ -5034,6 +5040,8 @@ public static String generateSubrangeOpCSharp() // for CSharp
50345040
50355041 res = res + " public static ArrayList subrange(ArrayList l, int i, int j)\n " ;
50365042 res = res + " { ArrayList tmp = new ArrayList(); \n " +
5043+ " if (i < 0) { i = l.Count + i; }\n " +
5044+ " if (j < 0) { j = l.Count + j; }\n " +
50375045 " if (i < 1) { i = 1; }\n " +
50385046 " for (int k = i-1; k < j; k++)\n " +
50395047 " { tmp.Add(l[k]); } \n " +
@@ -7694,8 +7702,8 @@ public static String generateAsSetOp()
76947702 " }\n \n " ;
76957703
76967704 res = res +
7697- " public static List mapAsSequence(Map m)\n " +
7698- " { List range = new Vector();\n " +
7705+ " public static Vector mapAsSequence(Map m)\n " +
7706+ " { Vector range = new Vector();\n " +
76997707 " java.util.Set ss = m.entrySet();\n " +
77007708 " for (Object x : ss)\n " +
77017709 " { Map.Entry ee = (Map.Entry) x;\n " +
@@ -7707,8 +7715,8 @@ public static String generateAsSetOp()
77077715 " }\n \n " ;
77087716
77097717 res = res +
7710- " public static List mapAsSet(Map m)\n " +
7711- " { List range = mapAsSequence(m); \n " +
7718+ " public static Vector mapAsSet(Map m)\n " +
7719+ " { Vector range = mapAsSequence(m); \n " +
77127720 " return asSet(range); \n " +
77137721 " }\n \n " ;
77147722
@@ -7764,7 +7772,7 @@ public static String generateAsSetOpCSharp()
77647772 " }\n \n " ;
77657773
77667774 return res ;
7767- } // and map
7775+ } // and map as a set
77687776
77697777 public static String refOps ()
77707778 { String res = "" ;
@@ -9938,6 +9946,25 @@ public static String generateAsSetOpJava6()
99389946 " return res; \n " +
99399947 " }\n \n " ;
99409948
9949+ res = res +
9950+ " public static ArrayList mapAsSequence(Map m)\n " +
9951+ " { ArrayList range = new ArrayList();\n " +
9952+ " java.util.Set ss = m.entrySet();\n " +
9953+ " for (Object x : ss)\n " +
9954+ " { Map.Entry ee = (Map.Entry) x;\n " +
9955+ " HashMap mx = new HashMap(); \n " +
9956+ " mx.put(ee.getKey(), ee.getValue());\n " +
9957+ " range.add(mx); \n " +
9958+ " } \n " +
9959+ " return range;\n " +
9960+ " }\n \n " ;
9961+
9962+ res = res +
9963+ " public static HashSet mapAsSet(Map m)\n " +
9964+ " { ArrayList range = mapAsSequence(m); \n " +
9965+ " return asSet(range); \n " +
9966+ " }\n \n " ;
9967+
99419968 return res ;
99429969 }
99439970
@@ -9949,6 +9976,11 @@ public static String generateAsSetOpJava7()
99499976 " return res;\n " +
99509977 " }\n \n " ;
99519978
9979+ res = res + " public static <S,T> HashSet<HashMap<S,T>> asSet(Map<S,T> m)\n " +
9980+ " { ArrayList<HashMap<S,T>> res = Ocl.asSequence(m);\n " +
9981+ " return Ocl.asSet(res);\n " +
9982+ " }\n \n " ;
9983+
99529984 res = res + " public static <T> ArrayList<T> asOrderedSet(Collection<T> c)\n " +
99539985 " { ArrayList<T> res = new ArrayList<T>();\n " +
99549986 " for (T x : c)\n " +
@@ -9959,6 +9991,17 @@ public static String generateAsSetOpJava7()
99599991 " return res;\n " +
99609992 " }\n \n " ;
99619993
9994+ res = res + " public static <S,T> ArrayList<HashMap<S,T>> asSequence(Map<S,T> m)\n " +
9995+ " { Set<Map.Entry<S,T>> ss = m.entrySet();\n " +
9996+ " ArrayList<HashMap<S,T>> res = new ArrayList<HashMap<S,T>>();\n " +
9997+ " for (Map.Entry<S,T> item : ss)\n " +
9998+ " { HashMap<S,T> maplet = new HashMap<S,T>();\n " +
9999+ " maplet.put(item.getKey(), item.getValue()); \n " +
10000+ " res.add(maplet); \n " +
10001+ " } \n " +
10002+ " return res;\n " +
10003+ " }\n " ;
10004+
996210005 return res ;
996310006 }
996410007
0 commit comments