You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/09/06 14:26:58 UTC
[06/18] temporarily added a patched version of javolution with fast
collections, because the released version has several bugs (see
https://java.net/jira/browse/JAVOLUTION-106 and
https://java.net/jira/browse/JAVOLUTION-105)
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/SubTableImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/SubTableImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/SubTableImpl.java
new file mode 100644
index 0000000..682a900
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/SubTableImpl.java
@@ -0,0 +1,101 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.internal.table;
+
+import javolution.util.function.Equality;
+import javolution.util.service.TableService;
+
+/**
+ * A view over a portion of a table.
+ */
+public class SubTableImpl<E> extends TableView<E> {
+
+ private static final long serialVersionUID = 0x600L; // Version.
+
+ /** Splits the specified table. */
+ @SuppressWarnings("unchecked")
+ public static <E> TableService<E>[] splitOf(TableService<E> table,
+ int n, boolean updateable) {
+ if (updateable) table = new SharedTableImpl<E>(table);
+ if (n < 1) throw new IllegalArgumentException("Invalid argument n: "
+ + n);
+ TableService<E>[] subTables = new TableService[n];
+ int minSize = table.size() / n;
+ int start = 0;
+ for (int i = 0; i < n - 1; i++) {
+ subTables[i] = new SubTableImpl<E>(table, start, start + minSize);
+ start += minSize;
+ }
+ subTables[n - 1] = new SubTableImpl<E>(table, start, table.size());
+ return subTables;
+ }
+
+ protected final int fromIndex;
+ protected int toIndex;
+
+ public SubTableImpl(TableService<E> target, int from, int to) {
+ super(target);
+ if ((from < 0) || (to > target.size()) || (from > to)) throw new IndexOutOfBoundsException(
+ "fromIndex: " + from + ", toIndex: " + to + ", size(): "
+ + target.size()); // As per List.subList contract.
+ fromIndex = from;
+ toIndex = to;
+ }
+
+ @Override
+ public boolean add(E element) {
+ target().add(toIndex++, element);
+ return true;
+ }
+
+ @Override
+ public void add(int index, E element) {
+ if ((index < 0) && (index > size())) indexError(index);
+ target().add(index + fromIndex, element);
+ toIndex++;
+ }
+
+ @Override
+ public void clear() {
+ for (int i = toIndex - 1; i >= fromIndex; i--) { // Better to do it from the end (less shift).
+ target().remove(i);
+ }
+ toIndex = fromIndex;
+ }
+
+ @Override
+ public Equality<? super E> comparator() {
+ return target().comparator();
+ }
+
+ @Override
+ public E get(int index) {
+ if ((index < 0) && (index >= size())) indexError(index);
+ return target().get(index + fromIndex);
+ }
+
+ @Override
+ public E remove(int index) {
+ if ((index < 0) && (index >= size())) indexError(index);
+ toIndex--;
+ return target().remove(index + fromIndex);
+ }
+
+ @Override
+ public E set(int index, E element) {
+ if ((index < 0) && (index >= size())) indexError(index);
+ return target().set(index + fromIndex, element);
+ }
+
+ @Override
+ public int size() {
+ return toIndex - fromIndex;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableIteratorImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableIteratorImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableIteratorImpl.java
new file mode 100644
index 0000000..913e9a0
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableIteratorImpl.java
@@ -0,0 +1,93 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.internal.table;
+
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+
+import javolution.util.service.TableService;
+
+/**
+ * A generic iterator over a table.
+ */
+public final class TableIteratorImpl<E> implements ListIterator<E> {
+
+ private int currentIndex = -1;
+ private int end;
+ private int nextIndex;
+ private final TableService<E> table;
+
+ public TableIteratorImpl(TableService<E> table, int index) {
+ this.table = table;
+ this.nextIndex = index;
+ this.end = table.size();
+ }
+
+ @Override
+ public void add(E e) {
+ table.add(nextIndex++, e);
+ end++;
+ currentIndex = -1;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return (nextIndex < end);
+ }
+
+ @Override
+ public boolean hasPrevious() {
+ return nextIndex > 0;
+ }
+
+ @Override
+ public E next() {
+ if (nextIndex >= end) throw new NoSuchElementException();
+ currentIndex = nextIndex++;
+ return table.get(currentIndex);
+ }
+
+ @Override
+ public int nextIndex() {
+ return nextIndex;
+ }
+
+ @Override
+ public E previous() {
+ if (nextIndex <= 0) throw new NoSuchElementException();
+ currentIndex = --nextIndex;
+ return table.get(currentIndex);
+ }
+
+ @Override
+ public int previousIndex() {
+ return nextIndex - 1;
+ }
+
+ @Override
+ public void remove() {
+ if (currentIndex < 0) throw new IllegalStateException();
+ table.remove(currentIndex);
+ end--;
+ if (currentIndex < nextIndex) {
+ nextIndex--;
+ }
+ currentIndex = -1;
+ }
+
+ @Override
+ public void set(E e) {
+ if (currentIndex >= 0) {
+ table.set(currentIndex, e);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableView.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableView.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableView.java
new file mode 100644
index 0000000..eaa8a4d
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableView.java
@@ -0,0 +1,259 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.internal.table;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+
+import javolution.util.function.Equality;
+import javolution.util.internal.collection.CollectionView;
+import javolution.util.service.TableService;
+
+/**
+ * Table view implementation; can be used as root class for implementations
+ * if target is {@code null}.
+ */
+public abstract class TableView<E> extends CollectionView<E> implements TableService<E> {
+
+ private static final long serialVersionUID = 0x600L; // Version.
+
+ /**
+ * The view constructor or root class constructor if target is {@code null}.
+ */
+ public TableView(TableService<E> target) {
+ super(target);
+ }
+
+ @Override
+ public abstract void add(int index, E element);
+
+ @Override
+ public boolean addAll(int index, Collection<? extends E> c) {
+ return subList(index, index).addAll(c);
+ }
+
+ @Override
+ public void addFirst(E element) {
+ add(0, element);
+ }
+
+ @Override
+ public void addLast(E element) {
+ add(size(), element);
+ }
+
+ @Override
+ public abstract void clear();
+
+ @Override
+ public final boolean contains(Object o) {
+ return indexOf(o) >= 0;
+ }
+
+ @Override
+ public Iterator<E> descendingIterator() {
+ return new ReversedTableImpl<E>(this).iterator();
+ }
+
+ @Override
+ public final E element() {
+ return getFirst();
+ }
+
+ @Override
+ public abstract E get(int index);
+
+ @Override
+ public E getFirst() {
+ if (size() == 0) emptyError();
+ return get(0);
+ }
+
+ @Override
+ public E getLast() {
+ if (size() == 0) emptyError();
+ return get(size() - 1);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public int indexOf(Object o) {
+ Equality<Object> cmp = (Equality<Object>) this.comparator();
+ for (int i = 0, n = size(); i < n; i++) {
+ if (cmp.areEqual(o, get(i))) return i;
+ }
+ return -1;
+ }
+
+ @Override
+ public final boolean isEmpty() {
+ return size() == 0;
+ }
+
+ @Override
+ public Iterator<E> iterator() {
+ return listIterator(0);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public int lastIndexOf(Object o) {
+ Equality<Object> cmp = (Equality<Object>) this.comparator();
+ for (int i = size() - 1; i >= 0; i--) {
+ if (cmp.areEqual(o, get(i))) return i;
+ }
+ return -1;
+ }
+
+ @Override
+ public final ListIterator<E> listIterator() {
+ return listIterator(0);
+ }
+
+ @Override
+ public ListIterator<E> listIterator(int index) {
+ return new TableIteratorImpl<E>(this, index);
+ }
+
+ @Override
+ public final boolean offer(E e) {
+ return offerLast(e);
+ }
+
+ @Override
+ public final boolean offerFirst(E e) {
+ addFirst(e);
+ return true;
+ }
+
+ @Override
+ public final boolean offerLast(E e) {
+ addLast(e);
+ return true;
+ }
+
+ @Override
+ public final E peek() {
+ return peekFirst();
+ }
+
+ @Override
+ public E peekFirst() {
+ return (size() == 0) ? null : getFirst();
+ }
+
+ @Override
+ public E peekLast() {
+ return (size() == 0) ? null : getLast();
+ }
+
+ @Override
+ public final E poll() {
+ return pollFirst();
+ }
+
+ @Override
+ public E pollFirst() {
+ return (size() == 0) ? null : removeFirst();
+ }
+
+ @Override
+ public E pollLast() {
+ return (size() == 0) ? null : removeLast();
+ }
+
+ @Override
+ public final E pop() {
+ return removeFirst();
+ }
+
+ @Override
+ public final void push(E e) {
+ addFirst(e);
+ }
+
+ @Override
+ public final E remove() {
+ return removeFirst();
+ }
+
+ @Override
+ public abstract E remove(int index);
+
+ @Override
+ public final boolean remove(Object o) {
+ int i = indexOf(o);
+ if (i < 0) return false;
+ remove(i);
+ return true;
+ }
+
+ @Override
+ public E removeFirst() {
+ if (size() == 0) emptyError();
+ return remove(0);
+ }
+
+ @Override
+ public boolean removeFirstOccurrence(Object o) {
+ int i = indexOf(o);
+ if (i < 0) return false;
+ remove(i);
+ return true;
+ }
+
+ @Override
+ public E removeLast() {
+ if (size() == 0) emptyError();
+ return remove(size() - 1);
+ }
+
+ @Override
+ public boolean removeLastOccurrence(Object o) {
+ int i = lastIndexOf(o);
+ if (i < 0) return false;
+ remove(i);
+ return true;
+ }
+
+ @Override
+ public abstract E set(int index, E element);
+
+ @Override
+ public abstract int size();
+
+ @Override
+ public TableService<E>[] split(int n, boolean updateable) {
+ return SubTableImpl.splitOf(this, n, updateable); // Sub-views over this.
+ }
+
+ @Override
+ public TableService<E> subList(int fromIndex, int toIndex) {
+ return new SubTableImpl<E>(this, fromIndex, toIndex);
+ }
+
+ /** Throws NoSuchElementException */
+ protected void emptyError() {
+ throw new NoSuchElementException("Empty Table");
+ }
+
+ /** Throws IndexOutOfBoundsException */
+ protected void indexError(int index) {
+ throw new IndexOutOfBoundsException("index: " + index + ", size: "
+ + size());
+ }
+
+ /** Returns the actual target */
+ @Override
+ protected TableService<E> target() {
+ return (TableService<E>) super.target();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/UnmodifiableTableImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/UnmodifiableTableImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/UnmodifiableTableImpl.java
new file mode 100644
index 0000000..138723f
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/UnmodifiableTableImpl.java
@@ -0,0 +1,84 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.internal.table;
+
+import javolution.util.function.Equality;
+import javolution.util.service.TableService;
+
+/**
+ * An unmodifiable view over a table.
+ */
+public class UnmodifiableTableImpl<E> extends TableView<E> {
+
+ private static final long serialVersionUID = 0x600L; // Version.
+
+ public UnmodifiableTableImpl(TableService<E> target) {
+ super(target);
+ }
+
+ @Override
+ public boolean add(E element) {
+ throw new UnsupportedOperationException("Read-Only Collection.");
+ }
+
+ @Override
+ public void add(int index, E element) {
+ throw new UnsupportedOperationException("Unmodifiable");
+ }
+
+ @Override
+ public void clear() {
+ throw new UnsupportedOperationException("Read-Only Collection.");
+ }
+
+ @Override
+ public Equality<? super E> comparator() {
+ return target().comparator();
+ }
+
+ @Override
+ public E get(int index) {
+ return target().get(index);
+ }
+
+ @Override
+ public int indexOf(Object o) {
+ return target().indexOf(o);
+ }
+
+ @Override
+ public int lastIndexOf(Object o) {
+ return target().lastIndexOf(o);
+ }
+
+ @Override
+ public E remove(int index) {
+ throw new UnsupportedOperationException("Read-Only Collection.");
+ }
+
+ @Override
+ public E set(int index, E element) {
+ throw new UnsupportedOperationException("Read-Only Collection.");
+ }
+
+ @Override
+ public int size() {
+ return target().size();
+ }
+
+ @Override
+ public TableService<E>[] split(int n, boolean updateable) {
+ return SubTableImpl.splitOf(this, n, false); // Sub-views over this.
+ }
+
+ @Override
+ protected TableService<E> target() {
+ return (TableService<E>) super.target();
+ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/AtomicSortedTableImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/AtomicSortedTableImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/AtomicSortedTableImpl.java
new file mode 100644
index 0000000..3e624e4
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/AtomicSortedTableImpl.java
@@ -0,0 +1,55 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.internal.table.sorted;
+
+import javolution.util.internal.table.AtomicTableImpl;
+import javolution.util.service.SortedTableService;
+import javolution.util.service.TableService;
+
+/**
+ * An atomic view over a sorted table.
+ */
+public class AtomicSortedTableImpl<E> extends AtomicTableImpl<E> implements
+ SortedTableService<E> {
+
+ private static final long serialVersionUID = 0x600L; // Version.
+
+ public AtomicSortedTableImpl(TableService<E> target) {
+ super(target);
+ }
+
+ @Override
+ public synchronized boolean addIfAbsent(E element) {
+ boolean changed = target().addIfAbsent(element);
+ if (changed && !updateInProgress()) immutable = cloneTarget();
+ return changed;
+ }
+
+ @Override
+ public int positionOf(E element) {
+ return targetView().positionOf(element);
+ }
+
+ @Override
+ public SortedTableService<E>[] split(int n, boolean updateable) {
+ return SubSortedTableImpl.splitOf(this, n, false); // Sub-views over this.
+ }
+
+ /** Returns the actual target */
+ @Override
+ protected SortedTableService<E> target() {
+ return (SortedTableService<E>) super.target();
+ }
+
+ @Override
+ protected SortedTableService<E> targetView() {
+ return (SortedTableService<E>) super.targetView();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/FastSortedTableImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/FastSortedTableImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/FastSortedTableImpl.java
new file mode 100644
index 0000000..0fbd5ef
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/FastSortedTableImpl.java
@@ -0,0 +1,67 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.internal.table.sorted;
+
+import javolution.util.function.Equality;
+import javolution.util.internal.table.FastTableImpl;
+import javolution.util.service.SortedTableService;
+
+/**
+ * The default {@link javolution.util.FastSortedTable FastSortedTable} implementation.
+ */
+public class FastSortedTableImpl<E> extends FastTableImpl<E> implements
+ SortedTableService<E> {
+
+ private static final long serialVersionUID = 0x600L; // Version.
+
+ public FastSortedTableImpl(Equality<? super E> comparator) {
+ super(comparator);
+ }
+
+ @Override
+ public boolean add(E element) {
+ add(positionOf(element), element);
+ return true;
+ }
+
+ @Override
+ public boolean addIfAbsent(E element) {
+ int i = positionOf(element);
+ if ((i < size()) && comparator().areEqual(element, get(i))) return false; // Already there.
+ add(i, element);
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public int indexOf(Object element) {
+ int i = positionOf((E) element);
+ if (i >= size() || !comparator().areEqual(get(i), (E) element)) return -1;
+ return i;
+ }
+
+ @Override
+ public int positionOf(E element) {
+ return positionOf(element, 0, size());
+ }
+
+ @Override
+ public SortedTableService<E>[] split(int n, boolean updateable) {
+ return SubSortedTableImpl.splitOf(this, n, updateable); // Sub-views over this.
+ }
+
+ private int positionOf(E element, int start, int length) {
+ if (length == 0) return start;
+ int half = length >> 1;
+ return (comparator().compare(element, get(start + half)) <= 0) ? positionOf(
+ element, start, half) : positionOf(element, start + half + 1,
+ length - half - 1);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/SharedSortedTableImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/SharedSortedTableImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/SharedSortedTableImpl.java
new file mode 100644
index 0000000..8b8ebfe
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/SharedSortedTableImpl.java
@@ -0,0 +1,57 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.internal.table.sorted;
+
+import javolution.util.internal.table.SharedTableImpl;
+import javolution.util.service.SortedTableService;
+
+/**
+ * A shared view over a sorted table allowing concurrent access and sequential updates.
+ */
+public class SharedSortedTableImpl<E> extends SharedTableImpl<E> implements
+ SortedTableService<E> {
+
+ private static final long serialVersionUID = 0x600L; // Version.
+
+ public SharedSortedTableImpl(SortedTableService<E> target) {
+ super(target);
+ }
+
+ @Override
+ public boolean addIfAbsent(E element) {
+ lock.writeLock.lock();
+ try {
+ return target().addIfAbsent(element);
+ } finally {
+ lock.writeLock.unlock();
+ }
+ }
+
+ @Override
+ public int positionOf(E element) {
+ lock.readLock.lock();
+ try {
+ return target().positionOf(element);
+ } finally {
+ lock.readLock.unlock();
+ }
+ }
+
+ @Override
+ public SortedTableService<E>[] split(int n, boolean updateable) {
+ return SubSortedTableImpl.splitOf(this, n, false); // Sub-views over this.
+ }
+
+ /** Returns the actual target */
+ @Override
+ protected SortedTableService<E> target() {
+ return (SortedTableService<E>) super.target();
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/SortedTableView.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/SortedTableView.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/SortedTableView.java
new file mode 100644
index 0000000..0c212b3
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/SortedTableView.java
@@ -0,0 +1,68 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.internal.table.sorted;
+
+import javolution.util.internal.table.TableView;
+import javolution.util.service.SortedTableService;
+
+/**
+ * Sorted table view implementation; can be used as root class for implementations
+ * if target is {@code null}.
+ */
+public abstract class SortedTableView<E> extends TableView<E> implements
+ SortedTableService<E> {
+
+ private static final long serialVersionUID = 0x600L; // Version.
+
+ /**
+ * The view constructor or root class constructor if target is {@code null}.
+ */
+ public SortedTableView(SortedTableService<E> target) {
+ super(target);
+ }
+
+ @Override
+ public boolean addIfAbsent(E element) {
+ if (!contains(element)) return add(element);
+ return false;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public int indexOf(Object o) {
+ int i = positionOf((E) o);
+ if ((i >= size()) || !comparator().areEqual((E) o, get(i))) return -1;
+ return i;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public int lastIndexOf(Object o) {
+ int i = positionOf((E) o);
+ int result = -1;
+ while ((i < size()) && comparator().areEqual((E) o, get(i))) {
+ result = i++;
+ }
+ return result;
+ }
+
+ @Override
+ public abstract int positionOf(E element);
+
+ @Override
+ public SortedTableService<E>[] split(int n, boolean updateable) {
+ return SubSortedTableImpl.splitOf(this, n, updateable); // Sub-views over this.
+ }
+
+ @Override
+ protected SortedTableService<E> target() {
+ return (SortedTableService<E>) super.target();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/SubSortedTableImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/SubSortedTableImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/SubSortedTableImpl.java
new file mode 100644
index 0000000..7bb9eba
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/SubSortedTableImpl.java
@@ -0,0 +1,87 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.internal.table.sorted;
+
+import javolution.util.internal.table.SubTableImpl;
+import javolution.util.service.SortedTableService;
+import javolution.util.service.TableService;
+
+/**
+ * A view over a portion of a sorted table.
+ */
+public class SubSortedTableImpl<E> extends SubTableImpl<E> implements SortedTableService<E> {
+
+ private static final long serialVersionUID = 0x600L; // Version.
+
+ /** Splits the specified table. */
+ @SuppressWarnings("unchecked")
+ public static <E> SortedTableService<E>[] splitOf(SortedTableService<E> table,
+ int n, boolean updateable) {
+ if (updateable) table = new SharedSortedTableImpl<E>(table);
+ if (n < 1) throw new IllegalArgumentException("Invalid argument n: "
+ + n);
+ SortedTableService<E>[] subTables = new SortedTableService[n];
+ int minSize = table.size() / n;
+ int start = 0;
+ for (int i = 0; i < n - 1; i++) {
+ subTables[i] = new SubSortedTableImpl<E>(table, start, start + minSize);
+ start += minSize;
+ }
+ subTables[n - 1] = new SubSortedTableImpl<E>(table, start, table.size());
+ return subTables;
+ }
+
+ public SubSortedTableImpl(TableService<E> target, int from, int to) {
+ super(target, from, to);
+ }
+
+ @Override
+ public boolean addIfAbsent(E element) {
+ if (!contains(element)) return add(element);
+ return false;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public int indexOf(Object o) {
+ int i = positionOf((E) o);
+ if ((i >= size()) || !comparator().areEqual((E) o, get(i))) return -1;
+ return i;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public int lastIndexOf(Object o) {
+ int i = positionOf((E) o);
+ int result = -1;
+ while ((i < size()) && comparator().areEqual((E) o, get(i))) {
+ result = i++;
+ }
+ return result;
+ }
+
+ @Override
+ public int positionOf(E element) {
+ int i = target().positionOf(element);
+ if (i < fromIndex) return 0;
+ if (i >= toIndex) return size();
+ return i - fromIndex;
+ }
+
+ @Override
+ public SortedTableService<E>[] split(int n, boolean updateable) {
+ return SubSortedTableImpl.splitOf(this, n, updateable); // Sub-views over this.
+ }
+
+ @Override
+ protected SortedTableService<E> target() {
+ return (SortedTableService<E>) super.target();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/UnmodifiableSortedTableImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/UnmodifiableSortedTableImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/UnmodifiableSortedTableImpl.java
new file mode 100644
index 0000000..7c1efff
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/sorted/UnmodifiableSortedTableImpl.java
@@ -0,0 +1,46 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.internal.table.sorted;
+
+import javolution.util.internal.table.UnmodifiableTableImpl;
+import javolution.util.service.SortedTableService;
+
+/**
+ * An unmodifiable view over a sorted table.
+ */
+public class UnmodifiableSortedTableImpl<E> extends UnmodifiableTableImpl<E>
+ implements SortedTableService<E> {
+
+ private static final long serialVersionUID = 0x600L; // Version.
+
+ public UnmodifiableSortedTableImpl(SortedTableService<E> target) {
+ super(target);
+ }
+
+ @Override
+ public boolean addIfAbsent(E element) {
+ throw new UnsupportedOperationException("Read-Only Collection.");
+ }
+
+ @Override
+ public int positionOf(E element) {
+ return target().positionOf(element);
+ }
+
+ @Override
+ public SortedTableService<E>[] split(int n, boolean updateable) {
+ return SubSortedTableImpl.splitOf(this, n, false); // Sub-views over this.
+ }
+
+ /** Returns the actual target */
+ @Override
+ protected SortedTableService<E> target() {
+ return (SortedTableService<E>) super.target();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/package-info.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/util/package-info.java
new file mode 100644
index 0000000..697f95f
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/package-info.java
@@ -0,0 +1,32 @@
+/**
+<p> High-performance collection classes with {@link javolution.lang.Realtime
+ worst case execution time behavior} documented.</p>
+<p> Whereas Java current evolution leads to more and more classes being parts of
+ the standard library; Javolution approach is quite the opposite. It aims to
+ provide only the quintessential classes from which all others can be derived.
+ </p>
+ <img src="doc-files/architecture.png" />
+
+<h2><a name="FAQ">FAQ:</a></h2>
+<ol>
+ <li><b>Does <b>J</b>avolution provide immutable collections similar to
+ the ones provided by Scala or .NET ?</b>
+ <p> Using <b>J</b>avolution you may return an {@link javolution.lang.Immutable Immutable}
+ reference (const reference) over any object which cannot be modified including collections or maps.
+[code]
+public class UnitSystem {
+ Set<Unit> units;
+ public UnitSystem(Immutable<Set<Unit>> units) {
+ this.units = units.value(); // Defensive copy unnecessary (immutable)
+ }
+}
+...
+Immutable<Set<Unit>> unitsMKSA = new FastSet<Unit>().addAll(M, K, S, A).toImmutable();
+UnitSystem MKSA = new UnitSystem(unitsMKSA);
+[/code]</p>
+ </li>
+</ol>
+
+ */
+package javolution.util;
+
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/service/BitSetService.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/service/BitSetService.java b/commons/marmotta-commons/src/ext/java/javolution/util/service/BitSetService.java
new file mode 100644
index 0000000..6c45891
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/service/BitSetService.java
@@ -0,0 +1,116 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.service;
+
+import javolution.util.FastBitSet;
+import javolution.util.FastTable;
+import javolution.util.Index;
+
+/**
+ * The set of related functionalities which can be used/reused to
+ * implement bit-sets collections.
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0, July 21, 2013
+ * @see FastTable
+ */
+public interface BitSetService extends SetService<Index> {
+
+ //
+ // Read Accessors.
+ //
+
+ /** See {@link FastBitSet#cardinality() } */
+ int cardinality();
+
+ /** See {@link FastBitSet#get(int) } */
+ boolean get(int bitIndex);
+
+ /** See {@link FastBitSet#get(int, int) } */
+ BitSetService get(int fromIndex, int toIndex);
+
+ /** See {@link FastBitSet#intersects(FastBitSet) } */
+ boolean intersects(BitSetService that);
+
+ /** See {@link FastBitSet#length() } */
+ int length();
+
+ //
+ // Iterations
+ //
+
+ /** See {@link FastBitSet#nextClearBit(int) } */
+ int nextClearBit(int fromIndex);
+
+ /** See {@link FastBitSet#nextSetBit(int) } */
+ int nextSetBit(int fromIndex);
+
+ /** See {@link FastBitSet#previousClearBit(int) } */
+ int previousClearBit(int fromIndex);
+
+ /** See {@link FastBitSet#previousSetBit(int) } */
+ int previousSetBit(int fromIndex);
+
+ //
+ // Clear/Set/Flip Operations
+ //
+
+ /** See {@link FastBitSet#clear(int) } */
+ void clear(int bitIndex);
+
+ /** See {@link FastBitSet#clear(int, int) } */
+ void clear(int fromIndex, int toIndex);
+
+ /** Clear or sets the specified bit, returns <code>true</code>
+ * if previously set; <code>false</code> otherwise. */
+ boolean getAndSet(int bitIndex, boolean value);
+
+ /** See {@link FastBitSet#set(int) } */
+ void set(int bitIndex);
+
+ /** See {@link FastBitSet#set(int, boolean) } */
+ void set(int bitIndex, boolean value);
+
+ /** See {@link FastBitSet#set(int, int) } */
+ void set(int fromIndex, int toIndex);
+
+ /** See {@link FastBitSet#set(int, int, boolean) } */
+ void set(int fromIndex, int toIndex, boolean value);
+
+ /** See {@link FastBitSet#flip(int) } */
+ void flip(int bitIndex);
+
+ /** See {@link FastBitSet#flip(int, int) } */
+ void flip(int fromIndex, int toIndex);
+
+ //
+ // Operators Operations
+ //
+
+ /** See {@link FastBitSet#and(FastBitSet) } */
+ void and(BitSetService that);
+
+ /** See {@link FastBitSet#andNot(FastBitSet) } */
+ void andNot(BitSetService that);
+
+ /** See {@link FastBitSet#or(FastBitSet) } */
+ void or(BitSetService that);
+
+ /** See {@link FastBitSet#xor(FastBitSet) } */
+ void xor(BitSetService that);
+
+ //
+ // Misc.
+ //
+
+ /** Returns the minimal length <code>long[]</code> representation of this
+ * bitset. */
+ long[] toLongArray();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/service/CollectionService.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/service/CollectionService.java b/commons/marmotta-commons/src/ext/java/javolution/util/service/CollectionService.java
new file mode 100644
index 0000000..37dbb8a
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/service/CollectionService.java
@@ -0,0 +1,39 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.service;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+import javolution.util.function.Equality;
+import javolution.util.function.Splittable;
+
+/**
+ * The fundamental set of related functionalities required to implement
+ * fast collections.
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0, July 21, 2013
+ */
+public interface CollectionService<E> extends Collection<E>,
+ Splittable<CollectionService<E>>, Serializable, Cloneable {
+
+ /**
+ * Returns a copy of this collection; updates of the copy should not
+ * impact the original.
+ */
+ CollectionService<E> clone() throws CloneNotSupportedException;
+
+ /**
+ * Returns the comparator used for element equality or order if the
+ * collection is sorted.
+ */
+ Equality<? super E> comparator();
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/service/MapService.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/service/MapService.java b/commons/marmotta-commons/src/ext/java/javolution/util/service/MapService.java
new file mode 100644
index 0000000..20090a3
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/service/MapService.java
@@ -0,0 +1,73 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.service;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+
+import javolution.util.function.Equality;
+import javolution.util.function.Splittable;
+
+/**
+ * The set of related map functionalities required to implement fast maps.
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0, July 21, 2013
+ * @see javolution.util.FastMap#FastMap()
+ */
+public interface MapService<K, V> extends
+ Map<K, V>, ConcurrentMap<K, V>, Splittable<MapService<K, V>>, Serializable, Cloneable {
+
+ /**
+ * Returns a copy of this map; updates of the copy should not
+ * impact the original.
+ */
+ MapService<K, V> clone() throws CloneNotSupportedException;
+
+
+ /**
+ * Returns a set view over the entries of this map. The set
+ * support adding/removing entries. Two entries are considered
+ * equals if they have the same key regardless of their values.
+ */
+ @Override
+ SetService<Map.Entry<K, V>> entrySet();
+
+ /**
+ * Returns an iterator over this map entries.
+ */
+ Iterator<Entry<K, V>> iterator();
+
+ /**
+ * Returns the key comparator used for key equality or order if the
+ * map is sorted.
+ */
+ Equality<? super K> keyComparator();
+
+ /**
+ * Returns a set view over the key of this map, the set support
+ * adding new key for which the value is automatically {@code null}.
+ */
+ @Override
+ SetService<K> keySet();
+
+ /**
+ * Returns the value comparator used for value equality.
+ */
+ Equality<? super V> valueComparator();
+
+ /**
+ * Returns a collection view over the values of this map, the collection
+ * support value/entry removal but not adding new values.
+ */
+ @Override
+ CollectionService<V> values();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/service/SetService.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/service/SetService.java b/commons/marmotta-commons/src/ext/java/javolution/util/service/SetService.java
new file mode 100644
index 0000000..7d2049a
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/service/SetService.java
@@ -0,0 +1,24 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.service;
+
+import java.util.Set;
+
+/**
+ * The set of related functionalities used to implement set collections.
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0, July 21, 2013
+ */
+public interface SetService<E> extends CollectionService<E>, Set<E> {
+
+ @Override
+ SetService<E>[] split(int n, boolean updateable);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/service/SortedMapService.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/service/SortedMapService.java b/commons/marmotta-commons/src/ext/java/javolution/util/service/SortedMapService.java
new file mode 100644
index 0000000..9febb73
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/service/SortedMapService.java
@@ -0,0 +1,41 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.service;
+
+import java.util.Map;
+import java.util.SortedMap;
+
+/**
+ * The set of related functionalities used to implement sorted map.
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0, July 21, 2013
+ */
+public interface SortedMapService<K, V> extends MapService<K, V>,
+ SortedMap<K, V> {
+
+ @Override
+ SortedSetService<Map.Entry<K, V>> entrySet();
+
+ @Override
+ SortedMapService<K, V> headMap(K toKey);
+
+ @Override
+ SortedSetService<K> keySet();
+
+ @Override
+ SortedMapService<K, V> subMap(K fromKey, K toKey);
+
+ @Override
+ SortedMapService<K, V> tailMap(K fromKey);
+
+ @Override
+ SortedMapService<K, V>[] split(int n, boolean updateable);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/service/SortedSetService.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/service/SortedSetService.java b/commons/marmotta-commons/src/ext/java/javolution/util/service/SortedSetService.java
new file mode 100644
index 0000000..5028ae5
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/service/SortedSetService.java
@@ -0,0 +1,33 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.service;
+
+import java.util.SortedSet;
+
+/**
+ * The set of related functionalities used to implement sorted set collections.
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0, July 21, 2013
+ */
+public interface SortedSetService<E> extends SetService<E>, SortedSet<E> {
+
+ @Override
+ SortedSetService<E> headSet(E toElement);
+
+ @Override
+ SortedSetService<E> subSet(E fromElement, E toElement);
+
+ @Override
+ SortedSetService<E> tailSet(E fromElement);
+
+ @Override
+ SortedSetService<E>[] split(int n, boolean updateable);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/service/SortedTableService.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/service/SortedTableService.java b/commons/marmotta-commons/src/ext/java/javolution/util/service/SortedTableService.java
new file mode 100644
index 0000000..74e47e2
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/service/SortedTableService.java
@@ -0,0 +1,36 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.service;
+
+/**
+ * The set of related functionalities used to implement sorted tables collections.
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0, July 21, 2013
+ */
+public interface SortedTableService<E> extends TableService<E> {
+
+ /**
+ * Adds the specified element only if not already present.
+ *
+ * @return {@code true} if the element has been added;
+ * {@code false} otherwise.
+ */
+ boolean addIfAbsent(E element);
+
+ /**
+ * Returns what would be the index of the specified element if it were
+ * to be added or the index of the specified element if already present.
+ */
+ int positionOf(E element);
+
+ @Override
+ SortedTableService<E>[] split(int n, boolean updateable);
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/service/TableService.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/service/TableService.java b/commons/marmotta-commons/src/ext/java/javolution/util/service/TableService.java
new file mode 100644
index 0000000..21af9d7
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/service/TableService.java
@@ -0,0 +1,29 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.util.service;
+
+import java.util.List;
+import java.util.Deque;
+import java.util.RandomAccess;
+
+/**
+ * The set of related functionalities used to implement tables collections.
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0, July 21, 2013
+ */
+public interface TableService<E> extends CollectionService<E>, List<E>, Deque<E>, RandomAccess {
+
+ @Override
+ TableService<E> subList(int fromIndex, int toIndex);
+
+ @Override
+ TableService<E>[] split(int n, boolean updateable);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/util/service/package-info.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/service/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/util/service/package-info.java
new file mode 100644
index 0000000..26fa4aa
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/service/package-info.java
@@ -0,0 +1,6 @@
+/**
+<p> Service interfaces to be implemented by {@code javolution.util.*}
+ collections and collections views.</p>
+ */
+package javolution.util.service;
+
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/DefaultXMLFormat.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/DefaultXMLFormat.java b/commons/marmotta-commons/src/ext/java/javolution/xml/DefaultXMLFormat.java
new file mode 100644
index 0000000..f4e894e
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/DefaultXMLFormat.java
@@ -0,0 +1,59 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.xml;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ * <p> Specifies the default xml format of a class (for xml serialization/deserialization).
+ * The default format is used by the {@link javolution.xml.XMLObjectReader}
+ * and {@link javolution.xml.XMLObjectWriter} classes. It can be locally overridden
+ * in the scope of a {@link javolution.xml.XMLContext XMLContext}.</p>
+ *
+ * [code]
+ * @DefaultXMLFormat(Complex.XML.class)
+ * public class Complex {
+ * public Complex(double real, double imaginary) { ... }
+ * public double getReal() { ... }
+ * public double getImaginary() { ... }
+ * public static class XML extends XMLFormat<Complex> {
+ * public Complex newInstance(Class<? extends Complex> cls, InputElement xml) throws XMLStreamException {
+ * return new Complex(xml.getAttribute("real", 0.0), xml.getAttribute("imaginary", 0.0));
+ * }
+ * public void read(InputElement xml, Complex c) throws XMLStreamException {
+ * // Immutable object, no further processing.
+ * }
+ * public void write(Complex c, OutputElement xml) throws XMLStreamException {
+ * xml.setAttribute("real", c.getReal());
+ * xml.setAttribute("imaginary", c.getImaginary());
+ * }
+ * };
+ * }[/code]
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0, July 21, 2013
+ */
+@Documented
+@Inherited
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface DefaultXMLFormat {
+
+ /**
+ * Returns the default xml format of the annotated class.
+ */
+ Class<? extends XMLFormat<?>> value();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/QName.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/QName.java b/commons/marmotta-commons/src/ext/java/javolution/xml/QName.java
new file mode 100644
index 0000000..0b8298a
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/QName.java
@@ -0,0 +1,233 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2007 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.xml;
+
+import java.io.ObjectStreamException;
+import java.lang.CharSequence;
+
+import javolution.lang.Immutable;
+import javolution.text.CharArray;
+import javolution.text.TextBuilder;
+import javolution.util.FastMap;
+import javolution.util.function.Equalities;
+
+/**
+ * <p> This class represents unique identifiers for XML elements (tags) or
+ * attributes (names).</p>
+ *
+ * <p> It should be noted that <code>QName.valueOf(null, "name")</code> and
+ * <code>QName.valueOf("", "name")</code> are distinct; the first one has no
+ * namespace associated with; whereas the second is associated
+ * to the root namespace.</p>
+ *
+ * <p> {@link QName} have a textual representation ({@link CharSequence}) which
+ * is either the local name (if no namespace URI) or
+ * <code>{namespaceURI}localName</code> (otherwise).</p>
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 5.3, January 14, 2007
+ * @see <a href="http://en.wikipedia.org/wiki/Qname">Wikipedia: QName</a>
+ */
+public final class QName implements XMLSerializable, Immutable<QName>, CharSequence {
+
+ /**
+ * Holds the local name.
+ */
+ private transient final CharArray _localName;
+
+ /**
+ * Holds the namespace URI reference or <code>null</code> if none.
+ */
+ private transient final CharArray _namespaceURI;
+
+ /**
+ * Holds the string representation.
+ */
+ private final String _toString;
+
+ /**
+ * Holds the full name (String) to QName mapping.
+ */
+ private static final FastMap<CharSequence, QName> FULL_NAME_TO_QNAME = new FastMap<CharSequence, QName>(
+ Equalities.LEXICAL);
+
+ /**
+ * Creates a qualified name having the specified local name and namespace
+ * reference.
+ *
+ * @param namespaceURI the URI reference or <code>null</code> if none.
+ * @param localName the local name.
+ * @param toString the string representation.
+ */
+ private QName(String namespaceURI, String localName, String toString) {
+ _namespaceURI = (namespaceURI == null) ? null : new CharArray(
+ namespaceURI);
+ _localName = new CharArray(localName);
+ _toString = toString;
+ }
+
+ /**
+ * Returns the qualified name corresponding to the specified character
+ * sequence representation (may include the "{namespaceURI}" prefix).
+ *
+ * @param name the qualified name lexical representation.
+ * @see #toString()
+ */
+ public static QName valueOf(CharSequence name) {
+ QName qName = (QName) FULL_NAME_TO_QNAME.get(name);
+ return (qName != null) ? qName : QName.createNoNamespace(name
+ .toString());
+ }
+
+ private static QName createNoNamespace(String name) {
+ String localName = name;
+ String namespaceURI = null;
+ if (name.length() > 0 && name.charAt(0) == '{') { // Namespace URI.
+ int index = name.lastIndexOf('}');
+ localName = name.substring(index + 1);
+ namespaceURI = name.substring(1, index);
+ }
+ QName qName = new QName(namespaceURI, localName, name);
+ synchronized (FULL_NAME_TO_QNAME) {
+ QName tmp = (QName) FULL_NAME_TO_QNAME.putIfAbsent(name, qName);
+ return tmp == null ? qName : tmp;
+ }
+ }
+
+ /**
+ * Equivalent to {@link #valueOf(CharSequence)} (for J2ME compatibility).
+ *
+ * @param name the qualified name lexical representation.
+ * @see #toString()
+ */
+ public static QName valueOf(String name) {
+ QName qName = (QName) FULL_NAME_TO_QNAME.get(name);
+ return (qName != null) ? qName : QName.createNoNamespace(name);
+ }
+
+ /**
+ * Returns the qualified name corresponding to the specified namespace URI
+ * and local name.
+ *
+ * @param namespaceURI the URI reference or <code>null</code> if none.
+ * @param localName the local name.
+ * @see #toString()
+ */
+ public static QName valueOf(CharSequence namespaceURI,
+ CharSequence localName) {
+ if (namespaceURI == null)
+ return QName.valueOf(localName);
+ TextBuilder tmp = new TextBuilder();
+ tmp.append('{');
+ tmp.append(namespaceURI);
+ tmp.append('}');
+ tmp.append(localName);
+ return QName.valueOf(tmp);
+ }
+
+ /**
+ * Returns the local part of this qualified name or the full qualified
+ * name if there is no namespace.
+ *
+ * @return the local name.
+ */
+ public CharSequence getLocalName() {
+ return _localName;
+ }
+
+ /**
+ * Returns the namespace URI of this qualified name or <code>null</code>
+ * if none (the local name is then the full qualified name).
+ *
+ * @return the URI reference or <code>null</code>
+ */
+ public CharSequence getNamespaceURI() {
+ return _namespaceURI;
+ }
+
+ /**
+ * Instances of this class are unique; object's equality can be
+ * replaced object identity (<code>==</code>).
+ *
+ * @return <code>this == obj</code>
+ */
+ public boolean equals(Object obj) {
+ return this == obj;
+ }
+
+ /**
+ * Returns the <code>String</code> representation of this qualified name.
+ *
+ * @return the textual representation.
+ */
+ public String toString() {
+ return _toString;
+ }
+
+ /**
+ * Returns the hash code for this qualified name.
+ *
+ * <p> Note: Returns the same hashCode as <code>java.lang.String</code>
+ * (consistent with {@link #equals})</p>
+ * @return the hash code value.
+ */
+ public int hashCode() {
+ return _toString.hashCode();
+ }
+
+ /**
+ * Returns the character at the specified index.
+ *
+ * @param index the index of the character starting at <code>0</code>.
+ * @return the character at the specified index of this character sequence.
+ * @throws IndexOutOfBoundsException if <code>((index < 0) ||
+ * (index >= length))</code>
+ */
+ public char charAt(int index) {
+ return _toString.charAt(index);
+ }
+
+ /**
+ * Returns the length of this character sequence.
+ *
+ * @return the number of characters (16-bits Unicode) composing this
+ * character sequence.
+ */
+ public int length() {
+ return _toString.length();
+ }
+
+ /**
+ * Returns a new character sequence that is a subsequence of this sequence.
+ *
+ * @param start the index of the first character inclusive.
+ * @param end the index of the last character exclusive.
+ * @return the character sequence starting at the specified
+ * <code>start</code> position and ending just before the specified
+ * <code>end</code> position.
+ * @throws IndexOutOfBoundsException if {@code (start < 0) || (end < 0) ||
+ * (start > end) || (end > this.length())}
+ */
+ public CharSequence subSequence(int start, int end) {
+ return _toString.substring(start, end);
+ }
+
+ //Maintains unicity.
+ private Object readResolve() throws ObjectStreamException {
+ return QName.valueOf(_toString);
+ }
+
+ private static final long serialVersionUID = -6126031630693748647L;
+
+ @Override
+ public QName value() {
+ return this;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/XMLBinding.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLBinding.java b/commons/marmotta-commons/src/ext/java/javolution/xml/XMLBinding.java
new file mode 100644
index 0000000..a15c002
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/XMLBinding.java
@@ -0,0 +1,298 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.xml;
+
+import javolution.util.FastMap;
+import javolution.xml.stream.XMLStreamException;
+import javolution.xml.stream.XMLStreamReader;
+import javolution.xml.stream.XMLStreamWriter;
+
+/**
+ * <p> This class represents the binding between Java classes and
+ * their XML representation ({@link XMLFormat}).</p>
+ *
+ * <p> Custom XML bindings can also be used to alias class names and
+ * ensure that the XML representation is:<ul>
+ * <li> Impervious to obfuscation.</li>
+ * <li> Unaffected by any class refactoring.</li>
+ * <li> Can be mapped to multiple implementations. For example:[code]
+ *
+ * // Creates a binding to serialize Swing components into high-level XML
+ * // and deserialize the same XML into SWT components.
+ * XMLBinding swingBinding = new XMLBinding();
+ * swingBinding.setAlias(javax.swing.JButton.class, "Button");
+ * swingBinding.setAlias(javax.swing.JTable.class, "Table");
+ * ...
+ * XMLBinding swtBinding = new XMLBinding();
+ * swtBinding.setAlias(org.eclipse.swt.widgets.Button.class, "Button");
+ * swtBinding.setAlias(org.eclipse.swt.widgets.Table.class, "Table");
+ * ...
+ *
+ * // Writes Swing Desktop to XML.
+ * XMLObjectWriter writer = new XMLObjectWriter().setBinding(swingBinding);
+ * writer.setOutput(new FileOutputStream("C:/desktop.xml"));
+ * writer.write(swingDesktop, "Desktop", SwingDesktop.class);
+ * writer.close();
+ *
+ * // Reads back high-level XML to a SWT implementation!
+ * XMLObjectReader reader = new XMLObjectReader().setXMLBinding(swtBinding);
+ * reader.setInput(new FileInputStream("C:/desktop.xml"));
+ * SWTDesktop swtDesktop = reader.read("Desktop", SWTDesktop.class);
+ * reader.close();
+ * [/code]</li>
+ * </ul></p>
+ *
+ * <p> More advanced bindings can also be created through sub-classing.[code]
+ *
+ * // XML binding using reflection.
+ * public ReflectionBinding extends XMLBinding {
+ * protected XMLFormat getFormat(Class forClass) {
+ * Field[] fields = forClass.getDeclaredFields();
+ * return new XMLReflectionFormat(fields);
+ * }
+ * }
+ *
+ * // XML binding read from DTD input source.
+ * public DTDBinding extends XMLBinding {
+ * public DTDBinding(InputStream dtd) {
+ * ...
+ * }
+ * }
+ *
+ * // XML binding overriding default formats.
+ * public MyBinding extends XMLBinding {
+ * // Non-static formats use unmapped XMLFormat instances.
+ * XMLFormat<String> myStringFormat = new XMLFormat<String>(null) {...}
+ * XMLFormat<Collection> myCollectionFormat = new XMLFormat<Collection>(null) {...}
+ * protected XMLFormat getFormat(Class forClass) throws XMLStreamException {
+ * if (String.class.equals(forClass))
+ * return myStringFormat;
+ * if (Collection.class.isAssignableFrom(forClass))
+ * return myCollectionFormat;
+ * return super.getFormat(cls);
+ * }
+ * }
+ * [/code]
+ *
+ * <p> The default XML binding implementation supports all static XML formats
+ * (static members of the classes being mapped) as well as the
+ * following types:<ul>
+ * <li><code>java.lang.Object</code> (empty element)</li>
+ * <li><code>java.lang.Class</code></li>
+ * <li><code>java.lang.String</code></li>
+ * <li><code>java.lang.Appendable</code></li>
+ * <li><code>java.util.Collection</code></li>
+ * <li><code>java.util.Map</code></li>
+ * <li><code>java.lang.Object[]</code></li>
+ * <li> all primitive types wrappers (e.g.
+ * <code>Boolean, Integer ...</code>)</li>
+ * </ul></p>
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 5.4, December 1, 2009
+ */
+public class XMLBinding implements XMLSerializable {
+
+ /**
+ * Holds the default instance used by readers/writers (thread-safe).
+ */
+ static final XMLBinding DEFAULT = new XMLBinding();
+
+ /**
+ * Holds the class attribute.
+ */
+ private QName _classAttribute = QName.valueOf("class");
+
+ /**
+ * Holds the class to alias (QName) mapping.
+ */
+ private final FastMap<Class<?>, QName> _classToAlias = new FastMap<Class<?>, QName>();
+
+ /**
+ * Holds the alias (QName) to class mapping.
+ */
+ private final FastMap<QName, Class<?>> _aliasToClass = new FastMap<QName, Class<?>>();
+
+ /**
+ * Default constructor.
+ */
+ public XMLBinding() {}
+
+ /**
+ * Sets the qualified alias for the specified class.
+ *
+ * @param cls the class being aliased.
+ * @param qName the qualified name.
+ */
+ public void setAlias(Class<?> cls, QName qName) {
+ _classToAlias.put(cls, qName);
+ _aliasToClass.put(qName, cls);
+ }
+
+ /**
+ * Convenient method equivalent to {@link #setAlias(Class, QName)
+ * setAlias(cls, QName.valueOf(alias))}.
+ *
+ * @param cls the class being aliased.
+ * @param alias the alias for the specified class.
+ */
+ public final void setAlias(Class<?> cls, String alias) {
+ setAlias(cls, QName.valueOf(alias));
+ }
+
+ /**
+ * Sets the qualified name of the attribute holding the
+ * class identifier. If the local name is <code>null</code> the class
+ * attribute is never read/written (which may prevent unmarshalling).
+ *
+ * @param classAttribute the qualified name of the class attribute or
+ * <code>null<code>.
+ */
+ public void setClassAttribute(QName classAttribute) {
+ _classAttribute = classAttribute;
+ }
+
+ /**
+ * Convenience method equivalent to {@link #setClassAttribute(QName)
+ * setClassAttribute(QName.valueOf(name))}.
+ *
+ * @param name the name of the class attribute or <code>null<code>.
+ */
+ public final void setClassAttribute(String name) {
+ setClassAttribute(name == null ? null : QName.valueOf(name));
+ }
+
+ /**
+ * Returns the XML format for the specified class/interface.
+ * The default implementation returns the {@link XMLContext#getFormat}
+ * for the specified class.
+ *
+ * @param forClass the class for which the XML format is returned.
+ * @return the XML format for the specified class (never <code>null</code>).
+ */
+ protected XMLFormat<?> getFormat(Class<?> forClass)
+ throws XMLStreamException {
+ return XMLContext.getFormat(forClass);
+ }
+
+ /**
+ * Reads the class corresponding to the current XML element.
+ *
+ * This method is called by {@link XMLFormat.InputElement#getNext()}
+ * {@link XMLFormat.InputElement#get(String)} and
+ * {@link XMLFormat.InputElement#get(String, String)} to retrieve the
+ * Java class corresponding to the current XML element.
+ *
+ * If <code>useAttributes</code> is set, the default implementation
+ * reads the class name from the class attribute; otherwise the class
+ * name (or alias) is read from the current element qualified name.
+ *
+ * @param reader the XML stream reader.
+ * @param useAttributes indicates if the element's attributes should be
+ * used to identify the class (e.g. when the element name is
+ * specified by the user then attributes have to be used).
+ * @return the corresponding class.
+ * @throws XMLStreamException
+ */
+ protected Class<?> readClass(XMLStreamReader reader, boolean useAttributes)
+ throws XMLStreamException {
+ try {
+ QName classQName;
+ if (useAttributes) {
+ if (_classAttribute == null)
+ throw new XMLStreamException(
+ "Binding has no class attribute defined, cannot retrieve class");
+ classQName = QName.valueOf(reader.getAttributeValue(
+ _classAttribute.getNamespaceURI(),
+ _classAttribute.getLocalName()));
+ if (classQName == null)
+ throw new XMLStreamException(
+ "Cannot retrieve class (class attribute not found)");
+ } else {
+ classQName = QName.valueOf(reader.getNamespaceURI(),
+ reader.getLocalName());
+ }
+
+ // Searches aliases with namespace URI.
+ Class<?> cls = _aliasToClass.get(classQName);
+ if (cls != null)
+ return cls;
+
+ // Searches aliases without namespace URI.
+ cls = _aliasToClass.get(QName.valueOf(classQName.getLocalName()));
+ if (cls != null)
+ return cls;
+
+ // Finally convert the qualified name to a class (ignoring namespace URI).
+ cls = Class.forName(classQName.getLocalName().toString());
+ if (cls == null)
+ throw new XMLStreamException(
+ "Class "
+ + classQName.getLocalName()
+ + " not found (see javolution.lang.Reflection to support additional class loader)");
+ _aliasToClass.put(classQName, cls);
+ return cls;
+ } catch (ClassNotFoundException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ /**
+ * Writes the specified class to the current XML element attributes or to
+ * a new element if the element attributes cannot be used.
+ *
+ * This method is called by
+ * {@link XMLFormat.OutputElement#add(Object)} and
+ * {@link XMLFormat.OutputElement#add(Object, String)} and
+ * {@link XMLFormat.OutputElement#add(Object, String, String)} to
+ * identify the Java class corresponding to the XML element.
+ *
+ *
+ * @param cls the class to be written.
+ * @param writer the XML stream writer.
+ * @param useAttributes indicates if the element's attributes should be
+ * used to identify the class (e.g. when the element name is
+ * specified by the user then attributes have to be used).
+ * @throws XMLStreamException
+ */
+ protected void writeClass(Class<?> cls, XMLStreamWriter writer,
+ boolean useAttributes) throws XMLStreamException {
+ QName qName = (QName) _classToAlias.get(cls);
+ String name = qName != null ? qName.toString() : cls.getName();
+ if (useAttributes) {
+ if (_classAttribute == null)
+ return;
+ if (_classAttribute.getNamespaceURI() == null) {
+ writer.writeAttribute(_classAttribute.getLocalName(), name);
+ } else {
+ writer.writeAttribute(_classAttribute.getNamespaceURI(),
+ _classAttribute.getLocalName(), name);
+ }
+ } else {
+ if (qName != null) {
+ if (qName.getNamespaceURI() == null) {
+ writer.writeStartElement(qName.getLocalName());
+ } else {
+ writer.writeStartElement(qName.getNamespaceURI(),
+ qName.getLocalName());
+ }
+ } else {
+ writer.writeStartElement(name);
+ }
+ }
+ }
+
+ public void reset() {
+ _classAttribute = QName.valueOf("class");
+ _aliasToClass.clear();
+ _classToAlias.clear();
+ }
+
+ private static final long serialVersionUID = 6611041662550083919L;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/XMLContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLContext.java b/commons/marmotta-commons/src/ext/java/javolution/xml/XMLContext.java
new file mode 100644
index 0000000..5b29017
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/XMLContext.java
@@ -0,0 +1,74 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.xml;
+
+import javolution.context.AbstractContext;
+import javolution.context.FormatContext;
+import javolution.osgi.internal.OSGiServices;
+import javolution.text.TextFormat;
+
+/**
+ * <p> A context for xml serialization/deserialization.
+ * The default xml format for any class is given by the
+ * {@link javolution.text.DefaultTextFormat Format} inheritable annotation.</p>
+ *
+ * <p> A default xml format exists for the following predefined types:
+ * <code><ul>
+ * <li>java.lang.Object (value attribute parsed/formatted using {@link TextFormat})</li>
+ * <li>java.util.Collection</li>
+ * <li>java.util.Map</li>
+ * </ul></code></p>
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0 December 12, 2012
+ */
+public abstract class XMLContext extends FormatContext {
+
+ /**
+ * Default constructor.
+ */
+ protected XMLContext() {}
+
+ /**
+ * Enters and returns a new xml context instance.
+ */
+ public static XMLContext enter() {
+ return (XMLContext) XMLContext.currentXMLContext().enterInner();
+ }
+
+ /**
+ * Returns the xml format for the specified type; if none defined
+ * the default object xml format (based on {@link TextFormat}) is returned.
+ */
+ public static <T> XMLFormat<T> getFormat(Class<? extends T> type) {
+ return XMLContext.currentXMLContext().searchFormat(type);
+ }
+
+ /**
+ * Sets the xml format for the specified type (and its sub-types).
+ */
+ public abstract <T> void setFormat(Class<? extends T> type,
+ XMLFormat<T> format);
+
+ /**
+ * Searches the xml format for the specified type.
+ */
+ protected abstract <T> XMLFormat<T> searchFormat(
+ Class<? extends T> type);
+
+ /**
+ * Returns the current xml context.
+ */
+ private static XMLContext currentXMLContext() {
+ XMLContext ctx = AbstractContext.current(XMLContext.class);
+ if (ctx != null)
+ return ctx;
+ return OSGiServices.getXMLContext();
+ }
+}
\ No newline at end of file