Skip to content

Commit

Permalink
Added SortedSet to C# code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlano authored Mar 3, 2025
1 parent 90cf8e5 commit f78d15c
Show file tree
Hide file tree
Showing 17 changed files with 398 additions and 72 deletions.
Binary file modified ATLFileFilter.class
Binary file not shown.
Binary file modified BSystemTypes.class
Binary file not shown.
226 changes: 201 additions & 25 deletions BSystemTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -4728,6 +4728,14 @@ public static String generateCopyOpsCSharp()
" return res; \n" +
" }\n\n";

res = res +
" public static SortedSet<T> copyCollection<T>(SortedSet<T> a)\n" +
" {\n" +
" SortedSet<T> res = new SortedSet<T>();\n" +
" res.UnionWith(a);\n" +
" return res;\n" +
" }\n\n";

res = res +
" public static Hashtable copyMap(Hashtable m)\n" +
" { Hashtable res = new Hashtable(); \n" +
Expand All @@ -4744,6 +4752,15 @@ public static String generateCopyOpsCSharp()
" return res; \n" +
" }\n\n";

res = res +
" public static ArrayList collectSortedSet<T>(SortedSet<T> col, Func<T, object> f)\n" +
" {\n" +
" ArrayList res = new ArrayList();\n" +
" foreach (T x in col)\n" +
" { res.Add(f(x)); }\n" +
" return res;\n" +
" }\n\n";

res = res +
" public static object iterate(ArrayList col, object init, Func<object,Func<object,object>> f)\n" +
" { object res = init;\n" +
Expand Down Expand Up @@ -5130,18 +5147,42 @@ public static String generateIncludesAllMapOpCSharp() // for CSharp
return res;
}

public static String generateExcludesAllMapOpCSharp() // for CSharp
{ String res = " public static bool excludesAllMap(Hashtable sup, Hashtable sub) \n" +
public static String generateExcludesAllMapOpCSharp() // for CSharp
{ String res =
" public static bool excludesAllMap(Hashtable sup, Hashtable sub) \n" +
" { foreach (DictionaryEntry pair in sub) \n" +
" { if (sup.ContainsKey(pair.Key)) \n" +
" { if (pair.Value.Equals(sup[pair.Key])) \n" +
" { return false; } \n" +
" } \n" +
" } \n" +
" return true; \n" +
" } \n";
return res;
}
" } \n\n";

res = res +
" public static bool excludesAll(ArrayList col1, ArrayList col2)\n" +
" {\n" +
" for (int i = 0; i < col1.Count; i++)\n" +
" {\n" +
" if (col2.Contains(col1[i]))\n" +
" { return false; }\n" +
" }\n" +
" return true;\n" +
" }\n\n";

res = res +
" public static bool excludesAll<T>(SortedSet<T> col1, SortedSet<T> col2)\n" +
" {\n" +
" foreach (T x in col1)\n" +
" {\n" +
" if (col2.Contains(x))\n" +
" { return false; }\n" +
" }\n" +
" return true;\n" +
" }\n\n";

return res;
}


public static String generateIncludingMapOpCSharp() // for CSharp
Expand Down Expand Up @@ -5363,7 +5404,30 @@ public static String generateExcludesAllMapOpCPP()
" } \n" +
" } \n" +
" return true; \n" +
" } \n";
" } \n\n";

res = res +
" static bool excludesAll(std::set<_T>* a, std::set<_T>* b)\n" +
" {\n" +
" for (auto _pos = a->begin(); _pos != a->end(); ++_pos)\n" +
" {\n" +
" if (UmlRsdsLib<_T>::isIn(*_pos, b))\n" +
" { return false; }\n" +
" }\n" +
" return true;\n" +
" }\n\n";

res = res +
" static bool excludesAll(vector<_T>* a, vector<_T>* b)\n" +
" {\n" +
" for (auto _pos = a->begin(); _pos != a->end(); ++_pos)\n" +
" {\n" +
" if (UmlRsdsLib<_T>::isIn(*_pos, b))\n" +
" { return false; }\n" +
" }\n" +
" return true;\n" +
" }\n\n";

return res;
}

Expand Down Expand Up @@ -5961,8 +6025,14 @@ public static String generateSetEqualsOpCSharp()
" }\n" +
" return res;\n" +
" }\n\n" +
" public static bool equalsSet(ArrayList a, ArrayList b)\n" +
" { return isSubset(a,b) && isSubset(b,a); }\n\n";
" public static bool equalsSet(ArrayList a, ArrayList b)\n" +
" { return isSubset(a,b) && isSubset(b,a); }\n\n";
res = res +
" public static bool isSubset<T>(SortedSet<T> a, SortedSet<T> b)\n" +
" { return a.IsSubsetOf(b); }\n\n" +
" public static bool equalsSet<T>(SortedSet<T> a, SortedSet<T> b)\n" +
" { return a.SetEquals(b); }\n\n";

return res;
}

Expand Down Expand Up @@ -6086,7 +6156,12 @@ public static String generateMaxOpCSharp() // for CSharp
res = res + " for (int i = 1; i < l.Count; i++)\n";
res = res + " { IComparable e = (IComparable) l[i];\n";
res = res + " if (res.CompareTo(e) < 0) { res = e; } }\n";
res = res + " return res; }\n";
res = res + " return res; }\n\n";

res = res +
" public static T max<T>(SortedSet<T> st)\n" +
" { return st.Max; }\n\n";

return res;
} // map

Expand Down Expand Up @@ -6152,7 +6227,13 @@ public static String generateMinOpCSharp()
res = res + " for (int i = 1; i < l.Count; i++)\n";
res = res + " { IComparable e = (IComparable) l[i];\n";
res = res + " if (res.CompareTo(e) > 0) { res = e; } }\n";
res = res + " return res; }\n";
res = res + " return res;\n" +
" }\n\n";

res = res +
" public static T min<T>(SortedSet<T> st)\n" +
" { return st.Min; }\n\n";

return res;
} // map

Expand Down Expand Up @@ -6662,7 +6743,8 @@ public static String generateUnionOpJava6()
" public static ArrayList union(ArrayList a, Collection b)\n" +
" { ArrayList res = new ArrayList(); \n" +
" res.addAll(a); res.addAll(b);\n" +
" return res; }\n\n";
" return res;\n" +
" }\n\n";
return res;
}

Expand Down Expand Up @@ -6694,10 +6776,24 @@ public static String generateUnionOpCSharp()
{ String res = " public static ArrayList union(ArrayList a, ArrayList b)\n" +
" { ArrayList res = new ArrayList(); \n" +
" for (int i = 0; i < a.Count; i++)\n" +
" { if (a[i] == null || res.Contains(a[i])) { } else { res.Add(a[i]); } }\n" +
" { if (a[i] == null || res.Contains(a[i])) { }\n" +
" else { res.Add(a[i]); }\n" +
" }\n" +
" for (int j = 0; j < b.Count; j++)\n" +
" { if (b[j] == null || res.Contains(b[j])) { } else { res.Add(b[j]); } }\n" +
" return res; }\n";
" { if (b[j] == null || res.Contains(b[j])) { }\n" +
" else { res.Add(b[j]); }\n" +
" }\n" +
" return res; }\n\n";

res = res +
" public static SortedSet<T> union<T>(SortedSet<T> a, IEnumerable<T> b)\n" +
" {\n" +
" SortedSet<T> res = new SortedSet<T>();\n" +
" res.UnionWith(a);\n" +
" res.UnionWith(b);\n" +
" return res;\n" +
" }\n\n";

return res;
} // if both are sequences, concatenate is used.

Expand Down Expand Up @@ -6968,19 +7064,43 @@ public static String generateSubtractOpCSharp()
" { if (a[i] == null || b.Contains(a[i])) {}\n" +
" else { res.Add(a[i]); }\n" +
" }\n" +
" return res; }\n\n" +
" return res;\n" +
" }\n\n" +

" public static SortedSet<T> subtract<T>(SortedSet<T> a, IEnumerable<T> b)\n" +
" {\n" +
" SortedSet<T> res = new SortedSet<T>();\n" +
" res.UnionWith(a);\n" +
" res.ExceptWith(b);\n" +
" return res;\n" +
" }\n\n" +

" public static ArrayList subtract(ArrayList a, object b)\n" +
" { ArrayList res = new ArrayList(); \n" +
" for (int i = 0; i < a.Count; i++)\n" +
" { if (a[i] == null || b == a[i]) {}\n" +
" else { res.Add(a[i]); }\n" +
" }\n" +
" return res; }\n\n" +
" return res;\n" +
" }\n\n" +

" public static SortedSet<T> subtract<T>(SortedSet<T> a, T b)\n" +
" {\n" +
" SortedSet<T> res = new SortedSet<T>();\n" +
" res.UnionWith(a);\n" +
" res.Remove(b); \n" +
" return res;\n" +
" }\n\n" +

" public static string subtract(string a, string b)\n" +
" { string res = \"\"; \n" +
" for (int i = 0; i < a.Length; i++)\n" +
" { if (b.IndexOf(a[i]) < 0) { res = res + a[i]; } }\n" +
" return res; }\n\n";
" { if (b.IndexOf(a[i]) < 0)\n" +
" { res = res + a[i]; }\n" +
" }\n" +
" return res;\n" +
" }\n\n";

return res;
}

Expand Down Expand Up @@ -7056,26 +7176,42 @@ public static String generateIntersectionOpJava7()
" { HashSet<T> res = new HashSet<T>(); \n" +
" res.addAll(a);\n" +
" res.retainAll(b);\n" +
" return res; }\n\n" +
" return res;\n" +
" }\n\n" +
" public static <T> TreeSet<T> intersection(TreeSet<T> a, Collection<T> b)\n" +
" { TreeSet<T> res = new TreeSet<T>(); \n" +
" res.addAll(a);\n" +
" res.retainAll(b);\n" +
" return res; }\n\n" +
" return res;\n" +
" }\n\n" +
" public static <T> ArrayList<T> intersection(ArrayList<T> a, Collection<T> b)\n" +
" { ArrayList<T> res = new ArrayList<T>(); \n" +
" res.addAll(a);\n" +
" res.retainAll(b);\n" +
" return res; }\n\n";
" return res;\n" +
" }\n\n";
return res; // shouldn't it always be a set?
} // TreeSet version is valid?

public static String generateIntersectionOpCSharp()
{ String res = " public static ArrayList intersection(ArrayList a, ArrayList b)\n" +
" { ArrayList res = new ArrayList(); \n" +
" for (int i = 0; i < a.Count; i++)\n" +
" { if (a[i] != null && b.Contains(a[i])) { res.Add(a[i]); } }\n" +
" return res; }\n\n";
" { if (a[i] != null && b.Contains(a[i]))\n" +
" { res.Add(a[i]); }\n" +
" }\n" +
" return res;\n" +
" }\n\n";

res = res +
" public static SortedSet<T> intersection<T>(SortedSet<T> a, IEnumerable<T> b)\n" +
" {\n" +
" SortedSet<T> res = new SortedSet<T>();\n" +
" res.UnionWith(a);\n" +
" res.IntersectWith(b); \n" +
" return res;\n" +
" }\n\n";

return res;
}

Expand Down Expand Up @@ -7160,6 +7296,18 @@ public static String generateIntersectAllOpCSharp() // for s->intersectAll(e)
" { res = SystemTypes.intersection(res,(ArrayList) se[i]); }\n" +
" return res;\n" +
" }\n\n";

res = res +
" public static SortedSet<T> intersectAllSet<T>(ArrayList se)\n" +
" {\n" +
" SortedSet<T> res = new SortedSet<T>();\n" +
" if (se.Count == 0) { return res; }\n" +
" res.UnionWith((IEnumerable<T>) se[0]);\n" +
" for (int i = 1; i < se.Count; i++)\n" +
" { res.IntersectWith((IEnumerable<T>) se[i]); }\n" +
" return res;\n" +
" }\n\n";

return res;
}

Expand Down Expand Up @@ -7281,6 +7429,16 @@ public static String generateUnionAllOpCSharp() // for s->unionAll(e)
" return res;\n" +
" }\n\n";

res = res +
" public static SortedSet<T> unionAllSet<T>(ArrayList se)\n" +
" {\n" +
" SortedSet<T> res = new SortedSet<T>();\n" +
" if (se.Count == 0) { return res; }\n" +
" for (int i = 0; i < se.Count; i++)\n" +
" { res.UnionWith((IEnumerable<T>) se[i]); }\n" +
" return res;\n" +
" }\n\n";

res = res +
" public static Hashtable unionAllMap(ArrayList se)\n" +
" { Hashtable res = new Hashtable(); \n" +
Expand Down Expand Up @@ -8889,6 +9047,16 @@ public static String symmetricDifferenceOpCSharp()
" }\n" +
" return res;\n" +
" }\n\n";

res = res +
" public static SortedSet<T> symmetricDifference<T>(SortedSet<T> a, IEnumerable<T> b)\n" +
" {\n" +
" SortedSet<T> res = new SortedSet<T>();\n" +
" res.UnionWith(a);\n" +
" res.SymmetricExceptWith(b); \n" +
" return res;\n" +
" }\n\n";

return res;
}

Expand Down Expand Up @@ -9341,10 +9509,18 @@ public static String countOpCSharp()
" { int res = 0; \n" +
" for (int _i = 0; _i < l.Count; _i++)\n" +
" { if (obj == l[_i]) { res++; } \n" +
" else if (obj != null && obj.Equals(l[_i])) { res++; } \n" +
" else if (obj != null && obj.Equals(l[_i]))\n" +
" { res++; } \n" +
" }\n" +
" return res; \n" +
" }\n\n" +
" }\n\n" +

" public static int count<T>(SortedSet<T> st, T x)\n" +
" { if (st.Contains(x))\n" +
" { return 1; }\n" +
" return 0; \n" +
" }\n\n" +

" public static int count(string s, string x)\n" +
" { int res = 0; \n" +
" if (\"\".Equals(s)) { return res; }\n" +
Expand Down
Binary file modified BinaryExpression.class
Binary file not shown.
Loading

0 comments on commit f78d15c

Please sign in to comment.