http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/JsoView.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/JsoView.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/JsoView.java deleted file mode 100644 index f7f14dc..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/JsoView.java +++ /dev/null @@ -1,298 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import com.google.gwt.core.client.JavaScriptObject; - -import org.waveprotocol.wave.model.util.ReadableStringMap.ProcV; - -/** - * Presents a raw, direct view on a javascript object. Useful for exposing - * properties that are not possible to modify with existing APIs. Also used as a - * backend for browser-optimised data structures. - * - * @author [email protected] (Daniel Danilatos) - */ -public final class JsoView extends JavaScriptObject { - - // As required by GWT - protected JsoView() {} - - /** Construct an empty Jso */ - public static native JsoView create() /*-{ - return {}; - }-*/; - - /** - * Unsafely cast any jso to a JsoView, exposing its internals. - * - * @param jso - * @return a JsoView of the input javascript object - */ - public static JsoView as(JavaScriptObject jso) { - return jso.cast(); - } - - /** - * @param key - * @return true if a value indexed by the given key is in the map - */ - public native boolean containsKey(String key) /*-{ - return this[key] !== undefined; - }-*/; - - /** - * @param key - * @return true if the given key exists in the map and is null - */ - public native boolean isNull(String key) /*-{ - return this[key] === null; - }-*/; - - /** - * @param key - * @return The value with the given key, or null if not present. The value is - * assumed to be a boolean. The method may fail at runtime if the type - * is not correct. - */ - public native boolean getBoolean(String key) /*-{ - return this[key]; - }-*/; - - /** - * @param key - * @return The value with the given key, or null if not present. The value is - * assumed to be a string. The method may fail at runtime if the type - * is not correct. - */ - public native String getString(String key) /*-{ - return this[key]; - }-*/; - - /** - * @param key - * @return The value with the given key, or null if not present. The value is - * assumed to be a string. The method may fail at runtime if the type - * is not correct. - */ - public native String getString(int key) /*-{ - return this[key]; - }-*/; - - /** - * @param key - * @return The value with the given key, or null if not present. The value is - * assumed to be a primitive number. The method may fail at runtime if - * the type is not correct. - */ - public native double getNumber(String key) /*-{ - return this[key]; - }-*/; - - /** - * @param key - * @return The value with the given key, or null if not present. The value is - * assumed to be a JSO. The method may fail at runtime if the type - * is not correct. - */ - public native JavaScriptObject getJso(String key) /*-{ - return this[key]; - }-*/; - - /** - * @param key - * @return The value with the given key, or null if not present. The value is - * assumed to be a JSO. The method may fail at runtime if the type - * is not correct. - */ - public native JavaScriptObject getJso(int key) /*-{ - return this[key]; - }-*/; - - /** - * @param key - * @return The value with the given key, or null if not present. The value is - * assumed to be a JSO. The method may fail at runtime if the type - * is not correct. - */ - public JsoView getJsoView(String key) { - JavaScriptObject jso = getJso(key); - return jso == null ? null : JsoView.as(jso); - } - - /** - * @param key - * @return The value with the given key, or null if not present. The value is - * assumed to be a JSO. The method may fail at runtime if the type - * is not correct. - */ - public JsoView getJsoView(int key) { - JavaScriptObject jso = getJso(key); - return jso == null ? null : JsoView.as(jso); - } - - /** - * @param key - * @return The value with the given key, or null if not present. The value is - * assumed to be a "java" object. The method may fail at runtime if - * the type is not correct. - */ - public native Object getObject(String key) /*-{ - return this[key]; - }-*/; - - /** - * Same as {@link #getObject(String)} but does not require casting of the - * return value - */ - public native <V> V getObjectUnsafe(String key) /*-{ - return this[key]; - }-*/; - - /** - * Removes the given key from the map - * @param key - */ - public native void remove(String key) /*-{ - delete this[key]; - }-*/; - - /** - * Sets the value for the given key to null (does not remove it from the map) - * @param key - */ - public native void setNull(String key) /*-{ - this[key] = null; - }-*/; - - /** - * Sets the value for the key - * @param key - * @param value - */ - public native void setBoolean(String key, boolean value) /*-{ - this[key] = value; - }-*/; - - /** - * Sets the value for the key - * @param key - * @param value - */ - public native void setString(String key, String value) /*-{ - this[key] = value; - }-*/; - - /** - * Sets the value for the key - * @param key - * @param value - */ - public native void setNumber(String key, double value) /*-{ - this[key] = value; - }-*/; - - /** - * Sets the value for the key - * @param key - * @param value - */ - public native void setJso(String key, JavaScriptObject value) /*-{ - this[key] = value; - }-*/; - - /** - * Sets the value for the key - * @param key - * @param value - */ - public native void setObject(String key, Object value) /*-{ - this[key] = value; - }-*/; - - /** - * Removes all entries from this jso. - */ - public final native void clear() /*-{ - for (var key in this) { - delete this[key]; - } - }-*/; - - /** - * Tests whether this jso is empty. - * - * @return true if this map has no entries. - */ - public final native boolean isEmpty() /*-{ - for (var k in this) { - return false; - } - return true; - }-*/; - - /** - * Counts the number of entries in this jso. This is a linear time operation. - */ - public final native int countEntries() /*-{ - var n = 0; - for (var k in this) { - n++; - } - return n; - }-*/; - - /** - * @return the first key in the iteration order, or null if the object is empty - */ - public final native String firstKey() /*-{ - for (var k in this) { - return k; - } - return null; - }-*/; - - /** - * Ruby/prototype.js style iterating idiom, using a callback. Equivalent to a - * for-each loop. - * - * @param <T> The value type. It is up to the caller to make sure only values - * of type T have been put into the Jso in the first place - * @param proc - */ - public final native <T> void each(ProcV<T> proc) /*-{ - for (var k in this) { - proc. - @org.waveprotocol.wave.model.util.ReadableStringMap.ProcV::apply(Ljava/lang/String;Ljava/lang/Object;) - (k, this[k]); - } - }-*/; - - /** - * Add all key value pairs from the source to the current map - * - * @param source - */ - public final native void putAll(JsoView source) /*-{ - for (var k in source) { - this[k] = source[k]; - } - }-*/; -}
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/KeyCombo.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/KeyCombo.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/KeyCombo.java deleted file mode 100644 index 919cdf0..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/KeyCombo.java +++ /dev/null @@ -1,255 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -public enum KeyCombo { - - /** These names are self-explanatory... */ - SPACE, - - /***/ - SHIFT_SPACE, - - /***/ - CTRL_SPACE, - - /***/ - CTRL_SHIFT_SPACE, - - /***/ - TAB, - - /***/ - SHIFT_TAB, - - /***/ - UP, - - /***/ - DOWN, - - /***/ - LEFT, - - /***/ - RIGHT, - - /***/ - HOME, - - /***/ - END, - - /***/ - PAGE_UP, - - /***/ - PAGE_DOWN, - - /***/ - ESC, - - /***/ - ENTER, - - /***/ - SHIFT_ENTER, - - /***/ - CTRL_ENTER, - - /***/ - CTRL_EQUALS, - - /***/ - CTRL_R, - - /***/ - CTRL_E, - - /***/ - BACKSPACE, - - /***/ - SHIFT_BACKSPACE, - - /***/ - DELETE, - - /***/ - SHIFT_DELETE, - - /***/ - INSERT, - - /***/ - SHIFT_INSERT, - - /***/ - CTRL_INSERT, - - /***/ - CTRL_B, - - /***/ - CTRL_D, - - /***/ - CTRL_H, - - /***/ - CTRL_I, - - /***/ - CTRL_G, - - /***/ - CTRL_K, - - /***/ - CTRL_U, - - /***/ - CTRL_A, - - /***/ - CTRL_L, - - /***/ - CTRL_W, - - /***/ - CTRL_SHIFT_L, - - /***/ - CTRL_ALT_F, - - /***/ - CTRL_ALT_D, - - /***/ - ORDER_C, - - /***/ - ORDER_X, - - /***/ - ORDER_V, - - /***/ - ORDER_Z, - - /***/ - CTRL_F, - - /***/ - META_LEFT, - - /***/ - META_RIGHT, - - /***/ - META_HOME, - - /***/ - ORDER_O, - - /***/ - ORDER_R, - - /***/ - ORDER_SHIFT_R, - - /***/ - ORDER_SHIFT_V, - - /***/ - ORDER_ALT_SHIFT_V, - - /***/ - ORDER_FULLSTOP, - - /***/ - ORDER_F, - - /***/ - ORDER_G, - - /***/ - ORDER_D, - - /***/ - ORDER_N, - - /***/ - CTRL_O, - - /***/ - ORDER_T, - - /***/ - ORDER_A, - - /***/ - ORDER_P, - - /***/ - CTRL_ALT_G, - - /***/ - CTRL_ALT_S, - - /***/ - ORDER_W, - - /***/ - ORDER_Q, - - /***/ - ORDER_L, - - /***/ - ORDER_K, - - /***/ - ORDER_SHIFT_K, - - /** Formatting combos */ - ORDER_B, - - /***/ - ORDER_U, - - /***/ - ORDER_I, - - /** Shortcuts for Canned response insertion */ - CTRL_SHIFT_1, - /***/ - CTRL_SHIFT_2, - /***/ - CTRL_SHIFT_3, - /***/ - CTRL_SHIFT_5, - /***/ - ORDER_SHIFT_5, - - OTHER, -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/KeySignalListener.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/KeySignalListener.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/KeySignalListener.java deleted file mode 100644 index ab9e773..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/KeySignalListener.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import com.google.gwt.user.client.ui.Widget; - -/** - * A listener to key signals. - * Signal equivalent of a keyboard listener. - * - * @author [email protected] (Daniel Danilatos) - */ -public interface KeySignalListener { - - /** - * @param sender - * @param signal - * @return true if the event was "handled" for some meaning of handled - * Usually this means the caller won't handle it themselves. - */ - boolean onKeySignal(Widget sender, SignalEvent signal); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/LinkedPruningSequenceMap.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/LinkedPruningSequenceMap.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/LinkedPruningSequenceMap.java deleted file mode 100644 index 3f08d52..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/LinkedPruningSequenceMap.java +++ /dev/null @@ -1,319 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import org.waveprotocol.wave.model.util.CollectionUtils; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -/** - * Implements a PruningSequenceMap using a doubly-linked list. - * - * @author [email protected] (Daniel Danilatos) - */ -public final class LinkedPruningSequenceMap<K extends VolatileComparable<? super K>, V> - implements PruningSequenceMap<K, V> { - private final Comparator<K> cmp; - private Node first = null; - private Node last = null; - private Node recent = null; - private int size = 0; - - private class Node implements SequenceElement<V> { - Node next; - Node prev; - K key; - V value; - - private Node(K key, V value) { - this.key = key; - this.value = value; - } - - @Override - public Node getNext() { - while (next != null && !next.key.isComparable()) { - remove(next); - } - return next; - } - - @Override - public Node getPrev() { - while (prev != null && !prev.key.isComparable()) { - remove(prev); - } - return prev; - } - - @Override - public V value() { - return value; - } - } - - /** - * Factory method for when the key type is Comparable - * - * @return instance with comparator automatically supplied - */ - public static <K extends VolatileComparable<K>, V> LinkedPruningSequenceMap<K, V> create() { - return new LinkedPruningSequenceMap<K, V>(new Comparator<K>() { - public int compare(K o1, K o2) { - return o1.compareTo(o2); - } - }); - } - - @Override - public void clear() { - // Use getFirst() to ensure pruning of invalid nodes - while (getFirst() != null) { - remove(first.key); - } - } - - /** - * Constructor - * - * @param cmp - * Comparator to use - */ - public LinkedPruningSequenceMap(Comparator<K> cmp) { - this.cmp = cmp; - } - - @Override - public V get(K key) { - SequenceElement<V> node = getElement(key); - return node == null ? null : node.value(); - } - - @Override - public boolean isEmpty() { - return size == 0; - } - - @Override - public V put(K key, V value) { - V old = null; - if (size == 0) { - emptyPut(key, value); - } else { - Node prev = findBefore(key); - // findBefore might have emptied the map, so check again - if (size == 0) { - emptyPut(key, value); - } else { - if (prev == null || cmp.compare(key, prev.key) != 0) { - Node node = new Node(key, value); - - // goes after last - if (prev == last) { - last = node; - } - - // goes before first - if (prev == null) { - prev = last; - first = node; - } - - insertAfter(prev, node); - size++; - } else { - old = prev.value; - prev.value = value; - } - } - } - return old; - } - - @Override - public V remove(K key) { - V val = null; - if (!key.isComparable()) { - // Key is already gone. If it is still in the node structure, it will get - // cleaned up eventually and transparently. Logically, the entry is gone - // the instant the key becomes non-comparable. - return null; - } - Node node = findBefore(key); - if (node != null && cmp.compare(key, node.key) == 0) { - val = node.value; - - remove(node); - } - return val; - } - - @Override - public int size() { - return size; - } - - @Override - public SequenceElement<V> getElement(K key) { - Node prev = findBefore(key); - if (prev == null) { - return first; - } - return cmp.compare(prev.key, key) == 0 ? prev : null; - } - - @Override - public boolean isFirst(SequenceElement<V> elt) { - return elt == first; - } - - @Override - public boolean isLast(SequenceElement<V> elt) { - return elt == last; - } - - @Override - public Node getFirst() { - return getUsable(first); - } - - @Override - public Node getLast() { - return getUsable(last); - } - - @Override - public Iterable<K> copyKeys() { - Node first = getFirst(); - if (first != null) { - List<K> keys = CollectionUtils.newArrayList(); - Node node = first; - do { - keys.add(node.key); - node = node.getNext(); - } while (node != first); - return keys; - } else { - return Collections.emptyList(); - } - } - - @Override - public Node findBefore(K key) { - if (key == null) { - throw new IllegalArgumentException("key is null"); - } - Node search = getUsable(recent); - if (search == null) { - return null; - } - while (true) { - int cmpPrev = cmp.compare(search.key, key); - if (cmpPrev <= 0) { - if (last == search || cmpPrev == 0) { - return search; - } - Node next = search.getNext(); - int cmpNext = cmp.compare(next.key, key); - if (cmpNext > 0) { - return search; - } - search = search.getNext(); - } else { - if (first == search) { - return null; - } - search = search.getPrev(); - } - } - } - - /** - * put, when the map is empty. - */ - private void emptyPut(K key, V value) { - Node node = new Node(key, value); - first = last = recent = node; - recent.next = recent; - recent.prev = recent; - size++; - } - - /** - * Place node in the doubly linked list after prev - * - * @param prev - * @param node - */ - private void insertAfter(Node prev, Node node) { - Node next = prev.getNext(); - node.prev = prev; - node.next = next; - prev.next = node; - next.prev = node; - } - - private void remove(Node node) { - Node prev = node.prev, next = node.next; - prev.next = next; - next.prev = prev; - - node.next = node.prev = null; // cleanup node, in case of external use - if (recent == node) { - recent = prev; - } - if (first == node && last == node) { - first = null; - last = null; - recent = null; - } else { - if (first == node) { - first = next; - } - if (last == node) { - last = prev; - } - } - size--; - } - - /** - * @param node A node that may or may not be currently comparable - * @return The input if usable, otherwise a nearby usable node, or null if none - */ - private Node getUsable(Node node) { - if (node != null && !node.key.isComparable()) { - if (isLast(node)) { - node = node.getNext(); - if (node != null) { - node = node.getPrev(); - } - } else { - node = node.getPrev(); - if (node != null) { - node = node.getNext(); - } - } - } - return node; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/LinkedSequence.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/LinkedSequence.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/LinkedSequence.java deleted file mode 100644 index 2201742..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/LinkedSequence.java +++ /dev/null @@ -1,275 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import org.waveprotocol.wave.model.util.CollectionUtils; -import org.waveprotocol.wave.model.util.IdentityMap; -import org.waveprotocol.wave.model.util.Preconditions; - -import java.util.Iterator; - -/** - * An implementation of {@link Sequence} that uses linked nodes to provide - * constant-time implementations of all queries. - * - * @param <T> type of block in this sequence. - */ -public final class LinkedSequence<T> implements Sequence<T>, Iterable<T> { - - /** - * Node in the linked structure. - */ - private final static class Node<T> { - private final T target; - private Node<T> next; - private Node<T> prev; - - Node(T target) { - this.target = target; - } - - @Override - public String toString() { - return target.toString(); - } - } - - /** Maps objects to their sequence nodes. */ - private final IdentityMap<T, Node<T>> items = CollectionUtils.createIdentityMap(); - - /** First item in this sequence. */ - private Node<T> first; - - /** Last item in this sequence. */ - private Node<T> last; - - private LinkedSequence() { - } - - /** - * Creates a linked sequence. - */ - public static <T> LinkedSequence<T> create() { - return new LinkedSequence<T>(); - } - - /** - * Creates a linked sequence, initialized by a given order. - */ - public static <T> LinkedSequence<T> create(Iterable<T> source) { - LinkedSequence<T> sequence = new LinkedSequence<T>(); - for (T x : source) { - sequence.append(x); - } - return sequence; - } - - /** - * Appends an object to the end of this sequence. - * - * @param x object to append - */ - public void append(T x) { - Preconditions.checkArgument(x != null, "Item is null"); - Node<T> item = new Node<T>(x); - if (first == null) { - first = last = item; - } else { - last.next = item; - item.prev = last; - last = item; - } - items.put(x, item); - } - - /** - * Prepends an object to the start of this sequence. - * - * @param x object to prepend - */ - public void prepend(T x) { - Preconditions.checkArgument(x != null, "Item is null"); - Node<T> item = new Node<T>(x); - if (first == null) { - first = last = item; - } else { - first.prev = item; - item.next = first; - first = item; - } - items.put(x, item); - } - - /** - * Inserts an object before a reference x in this sequence. - * - * @param reference object before which {@code x} is to be inserted (or - * {@code null} to append) - * @param x object to insert - */ - public void insertBefore(T reference, T x) { - if (reference == null) { - append(x); - return; - } - Preconditions.checkArgument(x != null, "Item is null"); - Node<T> refNode = items.get(reference); - Preconditions.checkArgument(refNode != null, "Reference not in this sequence"); - Node<T> item = new Node<T>(x); - - if (first == refNode) { - first = item; - } else { - refNode.prev.next = item; - item.prev = refNode.prev; - } - item.next = refNode; - refNode.prev = item; - items.put(x, item); - } - - /** - * Inserts an object after a reference x in this sequence. - * - * @param reference object after which {@code x} is to be inserted (or {@code - * null} to prepend) - * @param x object to insert - */ - public void insertAfter(T reference, T x) { - if (reference == null) { - prepend(x); - return; - } - Preconditions.checkArgument(x != null, "Item is null"); - Node<T> refNode = items.get(reference); - Preconditions.checkArgument(refNode != null, "Reference not in this sequence"); - Node<T> item = new Node<T>(x); - - if (last == refNode) { - last = item; - } else { - refNode.next.prev = item; - item.next = refNode.next; - } - item.prev = refNode; - refNode.next = item; - items.put(x, item); - } - - /** - * Removes an object from this sequence. - * - * @param x object to remove - * @throws IllegalArgumentException if {@code x} is not in this sequence. - */ - public void remove(T x) { - Preconditions.checkArgument(x != null, "Item is null"); - Node<T> item = items.removeAndReturn(x); - Preconditions.checkArgument(item != null, "Reference not in this sequence"); - - if (first == item) { - first = item.next; - } else { - item.prev.next = item.next; - } - - if (last == item) { - last = item.prev; - } else { - item.next.prev = item.prev; - } - } - - /** - * Clears this sequence. - */ - public void clear() { - first = last = null; - items.clear(); - } - - @Override - public boolean isEmpty() { - return items.isEmpty(); - } - - @Override - public boolean contains(T x) { - return x != null && items.has(x); - } - - @Override - public T getFirst() { - return targetOf(first); - } - - @Override - public T getLast() { - return targetOf(last); - } - - @Override - public T getNext(T block) { - return targetOf(nextOf(nodeOf(block))); - } - - @Override - public T getPrevious(T block) { - return targetOf(prevOf(nodeOf(block))); - } - - @Override - public Iterator<T> iterator() { - return SequenceIterator.create(this); - } - - private T targetOf(Node<T> node) { - return node != null ? node.target : null; - } - - private Node<T> nodeOf(T node) { - return items.get(node); - } - - private Node<T> nextOf(Node<T> node) { - return node != null ? node.next : first; - } - - private Node<T> prevOf(Node<T> node) { - return node != null ? node.prev : last; - } - - @Override - public String toString() { - return CollectionUtils.newArrayList(this).toString(); -// StringBuilder s = new StringBuilder(); -// s.append("["); -// Node<T> item = first; -// while (item != null) { -// s.append(item.target); -// if (item != last) { -// s.append(", "); -// } -// item = item.next; -// } -// s.append("]"); -// return s.toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/LogicalPanel.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/LogicalPanel.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/LogicalPanel.java deleted file mode 100644 index 96b0ab9..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/LogicalPanel.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import com.google.gwt.user.client.ui.ComplexPanel; -import com.google.gwt.user.client.ui.Widget; - -import org.waveprotocol.wave.model.util.Preconditions; - -/** - * A panel that can adopt and orphan widgets that attach and detach themselves - * from existing elements. - * - */ -public interface LogicalPanel { - // - // These names are intentionally different from Panel's adopt() and orphan() - // methods, because those methods are protected. - // - - /** - * Logically attaches a widget to this panel, without any physical DOM change. - * No assumptions are made about the physical location of {@code child}. - * - * @param child widget to adopt - */ - void doAdopt(Widget child); - - /** - * Logically detaches a child from this panel, without any physical DOM - * change. No assumptions are made about the physical location of {@code child}. - * - * @param child widget to orphan - */ - void doOrphan(Widget child); - - /** Canonical implementation */ - public abstract class Impl extends ComplexPanel implements LogicalPanel { - @Override - public void doAdopt(Widget child) { - Preconditions.checkArgument(child != null && child.getParent() == null, "Not an orphan"); - getChildren().add(child); - adopt(child); - } - - @Override - public void doOrphan(Widget child) { - Preconditions.checkArgument(child != null && child.getParent() == this, "Not a child"); - orphan(child); - getChildren().remove(child); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/MathUtil.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/MathUtil.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/MathUtil.java deleted file mode 100644 index f502ad6..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/MathUtil.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -/** - * General maths utility functions that don't have anywhere else to live. - * - */ -public final class MathUtil { - - private MathUtil() { - } - - /** - * Rounds a double to an int. - * - * @param x value to round - * @return closest int value to x. - */ - public static int roundToInt(double x) { - return (int) Math.floor(x + 0.5); - } - - /** - * Clips a value within a range. - * - * @param lower lower bound - * @param upper upper bound - * @param x value to clip - * @return clipped value of {@code x} - */ - public static int clip(int lower, int upper, int x) { - return Math.min(Math.max(x, lower), upper); - } - - /** - * Clips a value within a range. - * - * @param lower lower bound - * @param upper upper bound - * @param x value to clip - * @return clipped value of {@code x} - */ - public static double clip(double lower, double upper, double x) { - return Math.min(Math.max(x, lower), upper); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/Measurer.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/Measurer.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/Measurer.java deleted file mode 100644 index c3a1a5e..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/Measurer.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import com.google.gwt.dom.client.Element; - -/** - * Provides layout properties of elements. In particular, reveals such - * properties in fractional units, on browsers that have sub-pixel rendering. - * - */ -public interface Measurer { - /** - * Gets the position of the top of an element's offset box, either relative to - * the top of another element, or relative to the viewport. - * - * @param base element whose top defines the origin, or {@code null} for the - * top of the viewport being the origin - * @param e element to measure - * @return the top position of {@code e}, relative to the top of {@code base}. - */ - double top(Element base, Element e); - - /** - * Gets the position of the left of an element's offset box, either relative to - * the left of another element, or relative to the viewport. - * - * @param base element whose top defines the origin, or {@code null} for the - * left of the viewport being the origin - * @param e element to measure - * @return the left position of {@code e}, relative to the left of {@code base}. - */ - double left(Element base, Element e); - - /** - * Gets the position of the bottom of an element's offset box, either relative - * to the top of another element, or relative to the viewport. - * - * @param base element whose top defines the origin, or {@code null} for the - * top of the viewport being the origin - * @param e element to measure - * @return the bottom position of {@code e}, relative to the top of {@code - * base}. - */ - double bottom(Element base, Element e); - - /** @return the (offset) height of an element. */ - double height(Element e); - - /** @return the top of an element relative to its offset parent. */ - double offsetTop(Element e); - - /** @return the bottom of an element relative to its offset parent. */ - double offsetBottom(Element e); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/MeasurerInstance.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/MeasurerInstance.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/MeasurerInstance.java deleted file mode 100644 index 240ad8f..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/MeasurerInstance.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import com.google.gwt.dom.client.Element; - -/** - * Provides layout properties of elements. In particular, reveals such - * properties in fractional units, on browsers that have sub-pixel rendering. - * - */ -public final class MeasurerInstance { - /** Measuring strategy. */ - private static final Measurer instance = - UserAgent.isFirefox() ? new BoundingClientRectMeasurer() : new GwtMeasurer(); - - /** - * @return the singleton measuring strategy. - */ - public static Measurer get() { - return instance; - } - - /** - * GWT's default measuring logic. - */ - static final class GwtMeasurer implements Measurer { - @Override - public double bottom(Element base, Element e) { - return e.getAbsoluteBottom() - (base != null ? base.getAbsoluteTop() : 0); - } - - @Override - public double top(Element base, Element e) { - return e.getAbsoluteTop() - (base != null ? base.getAbsoluteTop() : 0); - } - - @Override - public double left(Element base, Element e) { - return e.getAbsoluteLeft() - (base != null ? base.getAbsoluteLeft() : 0); - } - - @Override - public double height(Element e) { - return e.getOffsetHeight(); - } - - @Override - public double offsetTop(Element e) { - return e.getOffsetTop(); - } - - @Override - public double offsetBottom(Element e) { - return e.getOffsetTop() + e.getOffsetHeight(); - } - } - - /** - * A Measurer that uses getBoundingClientRect(). - */ - public static final class BoundingClientRectMeasurer implements Measurer { - @Override - public native double top(Element base, Element elem) /*-{ - return elem.getBoundingClientRect().top - (base ? base.getBoundingClientRect().top : 0); - }-*/; - - @Override - public native double left(Element base, Element elem) /*-{ - return elem.getBoundingClientRect().left - (base ? base.getBoundingClientRect().left : 0); - }-*/; - - @Override - public native double bottom(Element base, Element elem) /*-{ - return elem.getBoundingClientRect().bottom - (base ? base.getBoundingClientRect().top : 0); - }-*/; - - @Override - public native double height(Element elem) /*-{ - var rect = elem.getBoundingClientRect(); - return rect.bottom - rect.top; - }-*/; - - @Override - public double offsetBottom(Element e) { - return bottom(e.getOffsetParent(), e); - } - - @Override - public double offsetTop(Element e) { - return top(e.getOffsetParent(), e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/NumberMapJsoView.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/NumberMapJsoView.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/NumberMapJsoView.java deleted file mode 100644 index e982dee..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/NumberMapJsoView.java +++ /dev/null @@ -1,204 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import org.waveprotocol.wave.model.util.ReadableNumberMap.ProcV; - -import java.util.HashMap; -import java.util.Map; - -/** - * A super fast and memory efficient map (directly uses a js object as the map, - * and requires only 1 object). Only allows double keys, thus taking advantage - * of the "perfect hashing" of doubles with respect to javascript. - * - * NOTE(danilatos): Does not use hasOwnProperty semantics. So it's possible for - * spurious entries to appear in the map if we're not careful. Easily fixable, - * but would incur a slight performance hit (I'm now just handwaving). - * - * TODO(dan): Use a different version from the GWT team once it is available - * - * @author [email protected] (Daniel Danilatos) - * @param <T> Type of values in the map. Keys are always doubles. - * - * @deprecated use {@link org.waveprotocol.wave.model.util.NumberMap} or - * {@link JsoView} instead, depending on use case - */ -@Deprecated -public final class NumberMapJsoView<T> extends JsoMapBase { - - /** - * A function that accepts an accumulated value, a key and the corresponding - * item from the map and returns the new accumulated value. - * - * @see NumberMapJsoView#reduce(Object, NumberMapJsoView.Reduce) - * @param <E> - * double map's type parameter - * @param <R> - * The type of the value being accumulated - */ - public interface Reduce<E, R> { - /** The function */ - public R apply(R soFar, double key, E item); - } - - /** Construct an empty NumberMap */ - public static native <T> NumberMapJsoView<T> create() /*-{ - return {}; - }-*/; - - /** Construct a NumberMap from a java Map */ - public static <T> NumberMapJsoView<T> fromMap(Map<Double, T> map) { - NumberMapJsoView<T> doubleMap = create(); - for (double key : map.keySet()) { - doubleMap.put(key, map.get(key)); - } - return doubleMap; - } - - protected NumberMapJsoView() { - } - - /** - * @param key - * @return true if a value indexed by the given key is in the map - */ - public native boolean has(double key) /*-{ - return this[key] !== undefined; - }-*/; - - /** - * @param key - * @return The value with the given key, or null if not present - */ - public native T get(double key) /*-{ - return this[key]; - }-*/; - - /** - * Put the value in the map at the given key. Note: Does not return the old - * value. - * - * @param key - * @param value - */ - public native void put(double key, T value) /*-{ - this[key] = value; - }-*/; - - /** - * Remove the value with the given key from the map. Note: does not return the - * old value. - * - * @param key - */ - public native void remove(double key) /*-{ - delete this[key]; - }-*/; - - /** - * Same as {@link #remove(double)}, but returns what was previously there, if - * anything. - * - * @param key - * @return what was previously there or null - */ - public final T removeAndReturn(double key) { - T val = get(key); - remove(key); - return val; - } - - /** - * Ruby/prototype.js style iterating idiom, using a callbak. Equivalent to a - * for-each loop. TODO(danilatos): Implement break and through a la - * prototype.js if needed. - * - * @param proc - */ - public final native void each(ProcV<? super T> proc) /*-{ - for (var k in this) { - proc. - @org.waveprotocol.wave.model.util.ReadableNumberMap.ProcV::apply(DLjava/lang/Object;) - (parseFloat(k), this[k]); - } - }-*/; - - /** - * Same as ruby/prototype reduce. Same as functional foldl. Apply a function - * to an accumulator and key/value in the map. The function returns the new - * accumulated value. TODO(danilatos): Implement break and through a la - * prototype.js if needed. - * - * @param initial - * @param proc - * @return The accumulated value - * @param <R> - * The accumulating type - */ - public final native <R> R reduce(R initial, Reduce<T, R> proc) /*-{ - var reduction = initial; - for (var k in this) { - reduction = proc. - @org.waveprotocol.wave.client.common.util.NumberMapJsoView.Reduce::apply(Ljava/lang/Object;DLjava/lang/Object;) - (reduction, parseFloat(k), this[k]); - } - return reduction; - }-*/; - - /** - * Convert to a java Map - */ - public final Map<Double, T> toMap() { - return addToMap(new HashMap<Double, T>()); - } - - /** - * Add all values to a java map. - * - * @param map - * The map to add values to - * @return The same map, for convenience. - */ - public final Map<Double, T> addToMap(final Map<Double, T> map) { - each(new ProcV<T>() { - public void apply(double key, T item) { - map.put(key, item); - } - }); - return map; - } - - /** - * Add all values to a NumberMap. - * - * @param map - * The map to add values to - * @return The same map, for convenience. - */ - public final NumberMapJsoView<T> addToMap(final NumberMapJsoView<T> map) { - each(new ProcV<T>() { - public void apply(double key, T item) { - map.put(key, item); - } - }); - return map; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/NumberPriorityQueue.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/NumberPriorityQueue.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/NumberPriorityQueue.java deleted file mode 100644 index bda2cb2..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/NumberPriorityQueue.java +++ /dev/null @@ -1,139 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import com.google.gwt.core.client.JsArrayNumber; - -import java.util.NoSuchElementException; - -/** - * An unbounded priority queue based on a priority heap. <a - * href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/PriorityQueue.html">[Sun - * docs]</a> - * - * Specialized version copied from com/google/gwt/emul/java/util/PriorityQueue.java - * so it doesn't require box/unbox. - * - */ -public class NumberPriorityQueue implements org.waveprotocol.wave.model.util.NumberPriorityQueue { - public interface Comparator { - int compare(double a, double b); - } - - /** - * A heap held in an array. heap[0] is the root of the heap (the smallest - * element), the subtrees of node i are 2*i+1 (left) and 2*i+2 (right). Node i - * is a leaf node if 2*i>=n. Node i's parent, if i>0, is floor((i-1)/2). - */ - private final JsArrayNumber heap; - private final Comparator comparator; - - public NumberPriorityQueue() { - this(new Comparator() { - @Override - public int compare(double a, double b) { - return Double.compare(a, b); - } - }); - } - - public NumberPriorityQueue(Comparator comparator) { - heap = (JsArrayNumber)JsArrayNumber.createArray(); - this.comparator = comparator; - } - - @Override - public boolean offer(double e) { - int node = heap.length(); - heap.push(e); - while (node > 0) { - int childNode = node; - node = (node - 1) / 2; // get parent of current node - if (comparator.compare(heap.get(node), e) <= 0) { - // parent is smaller, so we have a valid heap - heap.set(childNode, e); - return true; - } - // exchange with parent and try again - heap.set(childNode, heap.get(node)); - } - heap.set(node, e); - return true; - } - - @Override - public double peek() { - if (heap.length() == 0) { - throw new NoSuchElementException("Empty queue"); - } - return heap.get(0); - } - - @Override - public double poll() { - if (heap.length() == 0) { - throw new NoSuchElementException("Empty queue"); - } - double value = heap.get(0); - if (heap.length() > 1) { - heap.set(0, pop(heap)); // move last element to root - mergeHeaps(0); // make it back into a heap - } else { - pop(heap); - } - return value; - } - - private static native double pop(JsArrayNumber arr) /*-{ - return arr.pop(); - }-*/; - - @Override - public int size() { - return heap.length(); - } - - /** - * Merge two subheaps into a single heap. O(log n) time - * - * PRECONDITION: both children of <code>node</code> are heaps - * - * @param node the parent of the two subtrees to merge - */ - protected void mergeHeaps(int node) { - int n = heap.length(); - double value = heap.get(node); - while (node * 2 + 1 < n) { - int childNode = 2 * node + 1; // start with left child - if ((childNode + 1 < n) - && (comparator.compare(heap.get(childNode + 1), heap.get(childNode)) < 0)) { - childNode++; // right child is smaller, go down that path - } - // if the current element is smaller than the children, stop - if (comparator.compare(value, heap.get(childNode)) <= 0) { - break; - } - heap.set(node, heap.get(childNode)); - node = childNode; - } - heap.set(node, value); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/OffsetPosition.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/OffsetPosition.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/OffsetPosition.java deleted file mode 100644 index 65e5534..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/OffsetPosition.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import com.google.gwt.dom.client.Document; -import com.google.gwt.dom.client.Element; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.Window; - -/** - * Represents an x, y position relative to an offsetParent. - * - * If offsetParent is null, then interpret left and top as absolute positions on - * the browser. - * - */ -public final class OffsetPosition { - public final int left; - public final int top; - public final Element offsetParent; - - public OffsetPosition(int left, int top, Element offsetParent) { - this.left = left; - this.top = top; - this.offsetParent = offsetParent; - } - - /** - * Create a offset position base on the event's client X, Y. The return offset - * position is relative to the Document body coordinate. - * - * @param event - */ - public OffsetPosition(Event event) { - // convert the event's client coordinate system, which is client area base, to the - // body position coordinate system. - - this.left = event.getClientX() + Window.getScrollLeft() - Document.get().getBodyOffsetLeft(); - this.top = event.getClientY() + Window.getScrollTop() - Document.get().getBodyOffsetTop(); - - this.offsetParent = null; - } - - /** - * Gets the position of target relative to a specified element. - * @param target - * @param relative - */ - public static OffsetPosition getRelativePosition(OffsetPosition target, Element relative) { - int parentLeft = 0; - int parentTop = 0; - if (target.offsetParent != null) { - parentLeft = target.offsetParent.getAbsoluteLeft(); - parentTop = target.offsetParent.getAbsoluteTop(); - } - int left = parentLeft + target.left - relative.getAbsoluteLeft(); - int top = parentTop + target.top - relative.getAbsoluteTop(); - return new OffsetPosition(left, top, relative); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/PruningMap.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/PruningMap.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/PruningMap.java deleted file mode 100644 index 2788fcb..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/PruningMap.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import org.waveprotocol.wave.model.util.SimpleMap; - -/** - * A map that automatically removes values whose keys are no longer comparable - * - * @author [email protected] (Daniel Danilatos) - * - * @param <K> - * @param <V> - */ -public interface PruningMap<K extends VolatileComparable<? super K>, V> extends SimpleMap<K, V> { -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/PruningSequenceMap.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/PruningSequenceMap.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/PruningSequenceMap.java deleted file mode 100644 index 21f7e18..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/PruningSequenceMap.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -/** - * Combines two interfaces - * - * @author [email protected] (Daniel Danilatos) - * - * @param <K> Key (must implement {@link VolatileComparable}) - * @param <V> Value - */ -public interface PruningSequenceMap<K extends VolatileComparable<? super K>, V> extends - PruningMap<K, V>, SequenceMap<K, V> { -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/QuirksConstants.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/QuirksConstants.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/QuirksConstants.java deleted file mode 100644 index f699150..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/QuirksConstants.java +++ /dev/null @@ -1,410 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import com.google.gwt.core.client.GWT; - - -/** - * Collection of constants defining various browser quirky behaviours. - * - * Each constant should be accompanied by a detailed comment, and a "Tested:" - * section detailing which browsers and operating systems the quirk has been - * tested on, so that it's easy to know what's untested as new browser versions - * come out, etc. - * - * Sometimes an "Untested exceptions:" field is appropriate, to note exceptions - * to the "Tested:" field, in particular if they are concerning and represent a - * reasonable doubt as to the correctness of the field's value. - * - * It is preferable to use the constants in this class than to have logic that - * switches on explicit browser checks. - * - * @author [email protected] (Daniel Danilatos) - */ -public final class QuirksConstants { - - /** - * Whether we get DOM Mutation events - * - * Tested: - * Safari 3-4, Firefox 3-3.5, Chrome 1-2, IE7, IE8 - * - * Will IE9 give us mutation events? probably not. - */ - public static final boolean PROVIDES_MUTATION_EVENTS = - UserAgent.isFirefox() || UserAgent.isWebkit(); - - /** - * Whether the browser left normalises the caret in most cases (There are - * exceptions, usually to do with links). - * - * Tested: - * Safari 3*, Safari 4 beta, Firefox 3.0, IE7, IE8 - */ - public static final boolean USUALLY_LEFT_NORMALISES = - UserAgent.isWebkit() || UserAgent.isWebkit(); - - /** - * Certain versions of webkit have a specific hack implemented in them, where - * they go against the regular left-normalised behaviour at the end of an - * anchor boundary, if it has an href. They still report the cursor as being - * left-normalised, but if the user types, text goes to the right, outside the - * link. - * - * Tested: - * All OS: Safari 3.2.1, Safari 4 beta, Chrome 1.0, Chrome 2.0 special sauce - */ - public static final boolean LIES_ABOUT_CARET_AT_LINK_END_BOUNDARY = - UserAgent.isWebkit() && UserAgent.isAtLeastVersion(528, 0); - - /** - * Similar to {@link #LIES_ABOUT_CARET_AT_LINK_END_BOUNDARY}, but does not - * actually lie, just doesn't like reporting carets as being inside link - * boundaries, and typing occurs outside as well. - * - * Tested: IE8 beta - * - * TODO(danilatos): check IE7 - */ - public static final boolean DOES_NOT_LEFT_NORMALISE_AT_LINK_END_BOUNDARY = - UserAgent.isIE(); - - /** - * If the user is typing, we always get a key event before the browser changes - * the dom. - * - * Tested: - * All OS: Safari 3.2.1, 4 beta, Chrome 1, 2, Firefox 3, IE7, IE8 - * - * Untested exceptions: Any IME on Linux! - */ - public static final boolean ALWAYS_GIVES_KEY_EVENT_BEFORE_CHANGING_DOM = - UserAgent.isFirefox() || UserAgent.isIE7(); - - /** - * Whether we get the magic 229 keycode for IME key events, at least for the - * first one (sometimes we don't get key events for subsequent mutations). - * - * Tested: - * All OS: Safari 3.2.1, 4 beta, Chrome 1, 2, Firefox 3.0 - * - * Untested exceptions: Any IME on Linux! - */ - public static final boolean CAN_TELL_WHEN_FIRST_KEY_EVENT_IS_IME = - UserAgent.isIE() || UserAgent.isWebkit() || UserAgent.isWin(); - - /** - * Whether the old school Ctrl+Insert, Shift+Delete, Shift+Insert shortcuts - * for Copy, Cut, Paste work. - * - * Tested: All OS: Firefox 3, IE 7/8, Safari 3, Chrome 2 - * - * Untested exceptions: Safari on Windows - */ - public static final boolean HAS_OLD_SCHOOL_CLIPBOARD_SHORTCUTS = - UserAgent.isWin() || UserAgent.isLinux(); - - // NOTE(danilatos): These selection constants, unless mentioned otherwise, - // refer to selection boundaries (e.g. the start, or end, of a ranged - // selection, or a collapsed selection). - - /** - * Whether the selection is either cleared or correctly transformed by the - * browser in at least the following scenarios: - * - textNode.insertData adds to the cursor location, if it is after the - * deletion point - * - textNode.deleteData subtracts from the cursor location, if it is after - * the deletion point - * - * Tested: Safari 3.2.1, FF 3.0, 3.5, Chrome 1, IE7, IE8 - */ - public static final boolean OK_SELECTION_ACROSS_TEXT_NODE_DATA_CHANGES = - UserAgent.isFirefox() || UserAgent.isIE(); - - /** - * Whether the selection is either cleared or correctly transformed by the - * browser when text nodes are deleted. - * - * Gecko/IE preserve, Webkit clears selection. Both OK behaviours. - * - * Tested: Safari 3.2.1, FF 3.0, 3.5, Chrome 1, IE7, IE8 - */ - public static final boolean OK_SELECTION_ACROSS_NODE_REMOVALS = true; - - /** - * Whether the browser moves the selection into the neighbouring text node - * after a text node split before the selection point, or at least clears the - * selection. - * - * Tested: Safari 3.2.1, FF 3.0, 3.5, Chrome 1, IE7, IE8 - */ - public static final boolean OK_SELECTION_ACROSS_TEXT_NODE_SPLITS = - UserAgent.isIE(); - - /** - * In this case, only clearing occurs by Webkit. Other two browsers move the - * selection to the point where the moved node was. Which is BAD for wrapping! - * - * Tested: Safari 3.2.1, FF 3.0, 3.5, Chrome 1, IE7, IE8 - * - * @see #PRESERVES_SEMANTIC_SELECTION_ACROSS_MUTATIONS_OR_CLEARS_IT - */ - public static final boolean OK_SELECTION_ACROSS_MOVES = - UserAgent.isWebkit(); - - /** - * Preserves changes to text nodes made by calling methods on the text nodes - * directly (i.e. not moving or deleting the text nodes). - */ - public static final boolean PRESERVES_SEMANTIC_SELECTION_ACROSS_INTRINSIC_TEXT_NODE_CHANGES = - OK_SELECTION_ACROSS_TEXT_NODE_DATA_CHANGES && - OK_SELECTION_ACROSS_TEXT_NODE_SPLITS; - - /** - * Whether the selection preservation is completely reliable across mutations - * in terms of correctness. It might get cleared in some circumstances, but - * that's OK, we can just check if the selection is gone and restore it. We - * don't need to transform it for correctness. - * - * The biggest problem here is wrap. Currently implemented with insertBefore, - * it breaks selections in all browsers, even IE, AND IE doesn't clear the - * selection, just moves it. Damn! Anyway, there might be a smarter way to - * implement wrap - perhaps using an exec command to apply a styling to a - * region and using the resulting wrapper nodes... but that's a long way off. - * - * Tested: Safari 3.2.1, FF 3.0, 3.5, Chrome 1, IE7, IE8 - */ - public static final boolean PRESERVES_SEMANTIC_SELECTION_ACROSS_MUTATIONS_OR_CLEARS_IT = - OK_SELECTION_ACROSS_TEXT_NODE_DATA_CHANGES && - OK_SELECTION_ACROSS_TEXT_NODE_SPLITS && - OK_SELECTION_ACROSS_MOVES; - - /** - * Whether changing stuff in the middle of a ranged selection (that doesn't - * affect the selection end points in any way), such as splitting some - * entirely contained text node, affects the ranged selection. With firefox, - * it appears that the selection is still "correct", but visually new text - * nodes inserted don't get highlighted as selected, which is bad. - * - * Tested: Safari 3.2.1, FF 3.0, IE8 - */ - public static final boolean RANGED_SELECTION_AFFECTED_BY_INTERNAL_CHANGED = - UserAgent.isFirefox(); - - /** - * True if IME input in not totally munged by adjacent text node mutations - * - * Tested: - * Safari 3.2.1, FF 3.0, 3.5, Chrome 1, IE7, IE8 - */ - public static final boolean PRESERVES_IME_STATE_ACROSS_ADJACENT_CHANGES = - UserAgent.isIE(); - - /** - * True if we can do the __proto__ override trick to remove defaults method - * in a JSO. - * WARNING(dnailatos/reuben) Should be kept as static constant for - * speed reasons in string map implementation. - * - * Tested: Safari 4, FF 3.0, 3.5, Chrome 3-4, IE8 - */ - public static final boolean DOES_NOT_SUPPORT_JSO_PROTO_FIELD = UserAgent.isIE(); - - /** - * It appears that in some browsers, if you stopPropagation() an IME - * composition or contextmenu event, the default action for the event is not - * executed (as if you had cancelled it) - * - * TODO(danilatos): File a bug - * - * Tested: - * FF 3.0 - * - * Untested: - * Everything else (at time of writing, nothing else has composition - * events...) - */ - public static final boolean CANCEL_BUBBLING_CANCELS_IME_COMPOSITION_AND_CONTEXTMENU = - UserAgent.isFirefox(); - - /** - * True if mouse events have rangeParent and rangeOffset fields. - * - * Tested: - * FF 3.0, 3.6 - * Safari 4 - * Chrome 5 - */ - public static final boolean SUPPORTS_EVENT_GET_RANGE_METHODS = - UserAgent.isFirefox(); - - /** - * True if preventDefault stops a native context menu from being shown. In - * firefox this is not the case when dom.event.contextmenu.enabled is set. - * - * Tested: - * FF 3.0, 3.6 - */ - public static final boolean PREVENT_DEFAULT_STOPS_CONTEXTMENT = - !UserAgent.isFirefox(); - - /** - * True if displaying a context menu updates the current selection. Safari selects - * the word clicked unless you click on the current selection, Firefox does not - * change the selection and Chrome and IE clears the selection unless you click - * on the current selection. - * - * The selection that is active on mousedown will, in all browsers, be the - * original selection and the selection on the contextmenu event will be the new - * one. - * - * Tested: - * FF 3.0, 3.5 - * Chrome 5 - * Safari 4 - * IE 8 - */ - public static final boolean CONTEXTMENU_SETS_SELECTION = - !UserAgent.isFirefox(); - - /** - * True if the browser has the setBaseAndExtent JS method to allow better setting of - * the selection within the browser. - * - * So far, only webkit browsers have this in their API, and documentation is scarce. See: - * http://developer.apple.com/DOCUMENTATION/AppleApplications/Reference/WebKitDOMRef - * /DOMSelection_idl/Classes/DOMSelection/index.html#//apple_ref/idl/instm - * /DOMSelection/setBaseAndExtent/void/(inNode,inlong,inNode,inlong) - */ - public static final boolean HAS_BASE_AND_EXTENT = - UserAgent.isWebkit(); - - /** - * Chrome on Mac generates doesn't keypress for command combos, only keydown. - * - * In general, it makes sense to only fire the keypress event if the combo - * generates content. https://bugs.webkit.org/show_bug.cgi?id=30397 - * - * However since it is the odd one out here, it is listed as a - * quirk. - */ - public static final boolean COMMAND_COMBO_DOESNT_GIVE_KEYPRESS = - UserAgent.isMac() && UserAgent.isChrome(); - - /** - * True if the browser has native support for getElementsByClassName. - * - * Tested: - * Chrome, Safari 3.1, Firefox 3.0 - */ - public static final boolean SUPPORTS_GET_ELEMENTS_BY_CLASSNAME = - GWT.isScript() && checkGetElementsByClassNameSupport(); - - /** - * True if the browser supports composition events. - * - * (This does not differentiate between the per-browser composition event quirks, - * such as whether they provide a text vs a compositionupdate event, or other - * glitches). - * - * Tested: - * Chrome 3.0, 4.0; Safari 4; FF 3.0, 3.5; IE 7,8 - */ - public static final boolean SUPPORTS_COMPOSITION_EVENTS = - UserAgent.isFirefox() || (UserAgent.isWebkit() - && UserAgent.isAtLeastVersion(532, 5)); - - /** - * True if the browser does an extra modification of the DOM after the - * compositionend event, and also fires a text input event if the composition - * was not cancelled. - * - * Tested: Chrome 4.0; FF 3.0, 3.5; - */ - public static final boolean MODIFIES_DOM_AND_FIRES_TEXTINPUT_AFTER_COMPOSITION = - UserAgent.isWebkit(); // Put an upper bound on the version here when it's fixed... - - - /** - * True if the browser keeps the selection in an empty span after the - * app has programmatically set it there. - * - * Tested: - * Chrome 3.0, 4.0; Safari 3, 4; FF 3.0, 3.5; IE 7,8 - */ - public static final boolean SUPPORTS_CARET_IN_EMPTY_SPAN = - UserAgent.isFirefox(); - - /** - * True if the browser automatically scrolls a contentEditable element - * into view when we set focus on the element - * - * Tested: - * Chrome 5.0.307.11 beta / linux, Safari 4.0.4 / mac, Firefox 3.0.7 + 3.6 / linux - */ - public static final boolean ADJUSTS_SCROLL_TOP_WHEN_FOCUSING = - UserAgent.isWebkit(); - - /** - * True if the browser does not emit a paste event for plaintext paste. - * This was a bug on Webkit and has been fixed and pushed to Chrome 4+ - * - * Tested: - * Chrome 4.0.302.3; Safari 4.05 Mac - */ - public static final boolean PLAINTEXT_PASTE_DOES_NOT_EMIT_PASTE_EVENT = - UserAgent.isSafari(); - - /** - * True if the browser supports input type 'search'. - * - * Tested: - * Chrome 9.0, Chrome 4.0 - */ - public static final boolean SUPPORTS_SEARCH_INPUT = - UserAgent.isWebkit(); - - /** - * True if the browser sanitizes pasted content to contenteditable to - * prevent script execution. - * - * Tested: - * Chrome 9.0, Safari 5, FF 3.5, FF 4.0 - */ - public static final boolean SANITIZES_PASTED_CONTENT = - (UserAgent.isWebkit() && UserAgent.isAtLeastVersion(533, 16)) || - (UserAgent.isFirefox() && UserAgent.isAtLeastVersion(4, 0)); - - /** - * True if the browser is firefox >= 15 - * - * Tested: - * FF 13, FF 14, FF 15 - */ - public static final boolean FIREFOX_GREATER_THAN_VER_15 = - (UserAgent.isFirefox() && UserAgent.isAtLeastVersion(15, 0)); - - private static native boolean checkGetElementsByClassNameSupport() /*-{ - return !!document.body.getElementsByClassName; - }-*/; - - private QuirksConstants(){} -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/RegExp.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/RegExp.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/RegExp.java deleted file mode 100644 index c094d7e..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/RegExp.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import com.google.gwt.core.client.GWT; - -import java.util.List; - -/** - * Interface representing a regular expression. GWT does not support the - * java.util.regex library and the JS implementation does not have the same - * support. Using this to have Java/GWT regex support agree on a similar - * interface for both runtime and testing implementations. - * - */ -public interface RegExp { - - interface Factory { - RegExp create(String regex); - } - - Factory FACTORY = GWT.create(RegExp.Factory.class); - - /** - * Tests if the given string matches the regexp, and returns true if matching, - * false if not. - * - * @param test the string to test against. - * @return true if match was found, otherwise false. - */ - public boolean test(String test); - - /** - * Searches a string for a specified value. Returns all strings that matched. - * - * @param test the string to test against. - * @return list of matches or empty list is non-found. - */ - public List<String> getMatches(String test); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/Sequence.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/Sequence.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/Sequence.java deleted file mode 100644 index 1efe1ee..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/Sequence.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -/** - * A sequence maintains an ordering of objects defined via successor and - * predecessor relationships. - * - * This interface is intended to provide read-only access. It is up to each - * implementation to define whether it can reflect live changes to the - * underlying state. - * - * @param <T> type of item in this sequence. - */ -public interface Sequence<T> { - - /** - * @return true iff this sequence is empty. - */ - boolean isEmpty(); - - /** @return first object in this sequence. */ - T getFirst(); - - /** @return the last object in this sequence. */ - T getLast(); - - /** - * @return the object after {@code x}, or {@code null} if {@code x} is the - * last item. - */ - T getNext(T x); - - /** - * @return the object before {@code x}, or {@code null} if {@code x} is the - * first item. - */ - T getPrevious(T x); - - /** - * @return true if and only if {@code x} is in this sequence. - */ - boolean contains(T x); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/SequenceElement.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/SequenceElement.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/SequenceElement.java deleted file mode 100644 index c6b710a..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/SequenceElement.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -/** - * Wrapper for an element in a sequence - * <p> - * Implementations must enforce the contract that - * element.getNext().getPrev() == element.getPrev().getNext() == element - * - * @author [email protected] (Daniel Danilatos) - * @param <T> - */ -public interface SequenceElement<T> { - - /** - * @return Next element in the sequence (wraps) - */ - SequenceElement<T> getNext(); - - /** - * @return Previous element in the sequence (wraps) - */ - SequenceElement<T> getPrev(); - - /** - * @return Boxed value - */ - T value(); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/SequenceIterator.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/SequenceIterator.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/SequenceIterator.java deleted file mode 100644 index 16b55fe..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/SequenceIterator.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import java.util.Iterator; - -/** - * An iterator over a {@link Sequence}. - * - */ -public final class SequenceIterator<T> implements Iterator<T> { - private final Sequence<T> sequence; - private T next; - - private SequenceIterator(Sequence<T> sequence, T next) { - this.sequence = sequence; - this.next = next; - } - - public static <T> SequenceIterator<T> create(Sequence<T> sequence) { - return new SequenceIterator<T>(sequence, sequence.getFirst()); - } - - @Override - public boolean hasNext() { - return next != null; - } - - @Override - public T next() { - T toReturn = next; - next = sequence.getNext(next); - return toReturn; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/SequenceMap.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/SequenceMap.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/SequenceMap.java deleted file mode 100644 index f82bf22..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/SequenceMap.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.wave.client.common.util; - -import org.waveprotocol.wave.model.util.SimpleMap; - -/** - * A partial ordered map interface - * - * @author [email protected] (Daniel Danilatos) - * - * @param <K> - * @param <V> - */ -public interface SequenceMap<K, V> extends SimpleMap<K, V> { - - /** - * @param key - * @return a SeqElement for the given key, allowing left/right traversal - * thereafter - */ - SequenceElement<V> getElement(K key); - - /** - * @return First one, null if empty - */ - SequenceElement<V> getFirst(); - - /** - * @return Last one, null if empty - */ - SequenceElement<V> getLast(); - - /** - * SeqElements wrap, so this method is needed to tell if we are at the start - * of a sequence - * - * @param elt - * @return true if first - */ - boolean isFirst(SequenceElement<V> elt); - - /** - * SeqElements wrap, so this method is needed to tell if we are at the end of - * a sequence - * - * @param elt - * @return true if last - */ - boolean isLast(SequenceElement<V> elt); - - /** - * @param key - * @return node at or just before the key, or null if none before it. Note: if - * none before it, the last node would be its predecessor, but we use - * null to distinguish "before first" as opposed to "after last" - */ - SequenceElement<V> findBefore(K key); -}
