From ffe31a28b131c69d4abc748a49fc007c46b09396 Mon Sep 17 00:00:00 2001 From: Dario Elyasy Date: Thu, 21 Mar 2024 09:03:02 +0200 Subject: [PATCH] removed duplicated code files from pcollections tests --- .../reduks/pcollections/PVector.java | 47 ------ .../reduks/pcollections/TreePVector.java | 150 ------------------ 2 files changed, 197 deletions(-) delete mode 100644 reduks-pcollections/src/test/java/com/beyondeye/reduks/pcollections/PVector.java delete mode 100644 reduks-pcollections/src/test/java/com/beyondeye/reduks/pcollections/TreePVector.java diff --git a/reduks-pcollections/src/test/java/com/beyondeye/reduks/pcollections/PVector.java b/reduks-pcollections/src/test/java/com/beyondeye/reduks/pcollections/PVector.java deleted file mode 100644 index 7abfd0f..0000000 --- a/reduks-pcollections/src/test/java/com/beyondeye/reduks/pcollections/PVector.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2008 Harold Cooper. All rights reserved. - * Licensed under the MIT License. - * See LICENSE file in the project root for full license information. - */ - -package com.beyondeye.reduks.pcollections; - -import java.util.Collection; - -/** - * An immutable, persistent list. - * - * @author harold - * @param - */ -public interface PVector extends PSequence { - - /** Returns a vector consisting of the elements of this with e appended. */ - // @Override - public PVector plus(E e); - - /** Returns a vector consisting of the elements of this with list appended. */ - // @Override - public PVector plusAll(Collection list); - - // @Override - public PVector with(int i, E e); - - // @Override - public PVector plus(int i, E e); - - // @Override - public PVector plusAll(int i, Collection list); - - // @Override - public PVector minus(Object e); - - // @Override - public PVector minusAll(Collection list); - - // @Override - public PVector minus(int i); - - // @Override - public PVector subList(int start, int end); -} diff --git a/reduks-pcollections/src/test/java/com/beyondeye/reduks/pcollections/TreePVector.java b/reduks-pcollections/src/test/java/com/beyondeye/reduks/pcollections/TreePVector.java deleted file mode 100644 index 2772cab..0000000 --- a/reduks-pcollections/src/test/java/com/beyondeye/reduks/pcollections/TreePVector.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2008 Harold Cooper. All rights reserved. - * Licensed under the MIT License. - * See LICENSE file in the project root for full license information. - */ - -package com.beyondeye.reduks.pcollections; - -import java.io.Serializable; -import java.util.AbstractList; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map.Entry; - -/** - * A persistent vector of non-null elements. - * - *

This implementation is backed by an IntTreePMap and supports logarithmic-time querying, - * setting, insertion, and removal. - * - *

This implementation is thread-safe (assuming Java's AbstractList is thread-safe) although its - * iterators may not be. - * - * @author harold - * @param - */ -public class TreePVector extends AbstractList implements PVector, Serializable { - - private static final long serialVersionUID = 1L; - - //// STATIC FACTORY METHODS //// - private static final TreePVector EMPTY = new TreePVector(IntTreePMap.empty()); - - /** - * @param - * @return an empty vector - */ - @SuppressWarnings("unchecked") - public static TreePVector empty() { - return (TreePVector) EMPTY; - } - - /** - * @param - * @param e - * @return empty().plus(e) - */ - public static TreePVector singleton(final E e) { - return TreePVector.empty().plus(e); - } - - /** - * @param - * @param list - * @return empty().plusAll(list) - */ - @SuppressWarnings("unchecked") - public static TreePVector from(final Collection list) { - if (list instanceof TreePVector) - return (TreePVector) list; // (actually we only know it's TreePVector) - // but that's good enough for an immutable - // (i.e. we can't mess someone else up by adding the wrong type to it) - return TreePVector.empty().plusAll(list); - } - - //// PRIVATE CONSTRUCTORS //// - private final IntTreePMap map; - - private TreePVector(final IntTreePMap map) { - this.map = map; - } - - //// REQUIRED METHODS FROM AbstractList //// - @Override - public int size() { - return map.size(); - } - - @Override - public E get(final int index) { - if (index < 0 || index >= size()) throw new IndexOutOfBoundsException(); - return map.get(index); - } - - //// OVERRIDDEN METHODS FROM AbstractList //// - @Override - public Iterator iterator() { - return map.values().iterator(); - } - - @Override - public TreePVector subList(int start, int end) { - final int size = size(); - if (start < 0 || end > size || start > end) throw new IndexOutOfBoundsException(); - if (start == 0 && end == size) return this; - if (start == end) return empty(); - - // remove from end, then remove before start: - return new TreePVector( - this.map.minusRange(end, size).minusRange(0, start).withKeysChangedAbove(start, -start)); - } - - //// IMPLEMENTED METHODS OF PVector //// - public TreePVector plus(final E e) { - return new TreePVector(map.plus(size(), e)); - } - - public TreePVector plus(final int i, final E e) { - if (i < 0 || i > size()) throw new IndexOutOfBoundsException(); - return new TreePVector(map.withKeysChangedAbove(i, 1).plus(i, e)); - } - - public TreePVector minus(final Object e) { - for (Entry entry : map.entrySet()) - if (entry.getValue().equals(e)) return minus((int) entry.getKey()); - return this; - } - - public TreePVector minus(final int i) { - if (i < 0 || i >= size()) throw new IndexOutOfBoundsException(); - return new TreePVector(map.minus(i).withKeysChangedAbove(i, -1)); - } - - public TreePVector plusAll(final Collection list) { - TreePVector result = this; - for (E e : list) result = result.plus(e); - return result; - } - - public TreePVector minusAll(final Collection list) { - TreePVector result = this; - for (Object e : list) result = result.minus(e); - return result; - } - - public TreePVector plusAll(int i, final Collection list) { - if (i < 0 || i > size()) throw new IndexOutOfBoundsException(); - if (list.size() == 0) return this; - IntTreePMap map = this.map.withKeysChangedAbove(i, list.size()); - for (E e : list) map = map.plus(i++, e); - return new TreePVector(map); - } - - public PVector with(final int i, final E e) { - if (i < 0 || i >= size()) throw new IndexOutOfBoundsException(); - IntTreePMap map = this.map.plus(i, e); - if (map == this.map) return this; - return new TreePVector(map); - } -}