public static JList <T> operator-(JList <T> listA, JList <T> listB) { JList <T> output = new JList <T>(); int indexFound = listA.Find(listB); if (indexFound != -1) { int indexFoundEnd = indexFound + listB.Count - 1; for (int i = 0; i < listA.Count; i++) { if (i < indexFound || i > indexFoundEnd) { output.Add(listA[i]); } } } else { for (int i = 0; i < listA.Count; i++) { output.Add(listA[i]); } } return(output); }
public int Find(JList <T> findJList) { int index = -2; int searchFromIndex = 0; do { int foundIndex = Find(findJList[0], searchFromIndex); if (foundIndex != -1 && foundIndex + findJList.count - 1 < count) { int findJListIndex = 1; for (int i = foundIndex + 1; i < foundIndex + findJList.Count; i++, findJListIndex++) { index = foundIndex; if (!data[i].Equals(findJList[findJListIndex])) { searchFromIndex = foundIndex + 1; index = -2; break; } } } else { index = -1; } } while (index == -2); return(index); }
public static JList <T> Zip(JList <T> listA, JList <T> listB) { var output = new JList <T>(); int smallestCount = listA.Count < listB.Count ? listA.Count : listB.Count; for (int i = 0; i < smallestCount; i++) { output.Add(listA[i]); output.Add(listB[i]); } return(output); }
public static JList <T> operator+(JList <T> listA, JList <T> listB) { JList <JList <T> > jlists = new JList <JList <T> >(); JList <T> output = new JList <T>(); jlists.Add(listA); jlists.Add(listB); for (int i = 0; i < jlists.Count; i++) { for (int j = 0; j < jlists[i].Count; j++) { output.Add(jlists[i][j]); } } return(output); }
public static JList <U> Sort <U>(JList <U> list) where U : IComparable { bool didSwap = false; for (int i = 0; i < list.Count - 1; i++) { if (list[i].CompareTo(list[i + 1]) > 0) { didSwap = true; U temporary = list[i]; list[i] = list[i + 1]; list[i + 1] = temporary; } } if (didSwap) { return(JList <U> .Sort <U>(list)); } else { return(list); } }