|
From: <lh...@us...> - 2008-08-11 12:21:37
|
Revision: 112
http://tinytim.svn.sourceforge.net/tinytim/?rev=112&view=rev
Author: lheuer
Date: 2008-08-11 12:21:38 +0000 (Mon, 11 Aug 2008)
Log Message:
-----------
- Committed missing classes (Scope and the new CollectionFactory)
Added Paths:
-----------
tinytim/trunk/src/main/java/org/tinytim/core/Scope.java
tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java
tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java
tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java
tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java
tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java
tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java
tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java
tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java
Added: tinytim/trunk/src/main/java/org/tinytim/core/Scope.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/Scope.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-08-11 12:21:38 UTC (rev 112)
@@ -0,0 +1,154 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim.core;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.tinytim.utils.CollectionFactory;
+import org.tinytim.utils.WeakObjectRegistry;
+import org.tmapi.core.Topic;
+
+/**
+ *
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+final class Scope implements IScope {
+
+ public static final IScope UCS = new Scope();
+
+ private static final WeakObjectRegistry<IScope> _SCOPES = new WeakObjectRegistry<IScope>();
+
+ private final Set<Topic> _set;
+
+ private Scope() {
+ _set = Collections.emptySet();
+ }
+
+ private Scope(Collection<Topic> themes) {
+ _set = CollectionFactory.createIdentitySet(themes.size());
+ _set.addAll(themes);
+ }
+
+ private Scope(Set<Topic> themes) {
+ _set = themes;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ return (obj instanceof Scope) && _set.equals(((Scope)obj)._set);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return _set.hashCode();
+ }
+
+ public static synchronized IScope create(Collection<Topic> scope) {
+ if (scope.isEmpty()) {
+ return UCS;
+ }
+ Set<Topic> themes = CollectionFactory.createIdentitySet(scope.size());
+ themes.addAll(scope);
+ IScope scope_ = new Scope(themes);
+ IScope existing = _SCOPES.get(scope_);
+ if (existing != null) {
+ return existing;
+ }
+ _SCOPES.add(scope_);
+ return scope_;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IScope#asSet()
+ */
+ public Set<Topic> asSet() {
+ return Collections.unmodifiableSet(_set);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IScope#contains(org.tmapi.core.Topic)
+ */
+ public boolean contains(Topic theme) {
+ return _set.contains(theme);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IScope#add(org.tmapi.core.Topic)
+ */
+ public IScope add(Topic theme) {
+ if (_set.contains(theme)) {
+ return this;
+ }
+ Collection<Topic> themes = CollectionFactory.createIdentitySet(_set.size());
+ themes.addAll(_set);
+ themes.add(theme);
+ return create(themes);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IScope#remove(org.tmapi.core.Topic)
+ */
+ public IScope remove(Topic theme) {
+ if (!_set.contains(theme)) {
+ return this;
+ }
+ Collection<Topic> themes = CollectionFactory.createIdentitySet(_set.size());
+ themes.addAll(_set);
+ themes.remove(theme);
+ return create(themes);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<Topic> iterator(){
+ return _set.iterator();
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IScope#isUnconstrained()
+ */
+ public boolean isUnconstrained() {
+ return this == UCS;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IScope#size()
+ */
+ public int size() {
+ return _set.size();
+ }
+
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/Scope.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java 2008-08-11 12:21:38 UTC (rev 112)
@@ -0,0 +1,108 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim.utils;
+
+import java.util.Map;
+import java.util.Set;
+
+
+
+/**
+ *
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public final class CollectionFactory {
+
+ private static final String _COLL_FACTORY_TROVE = "org.tinytim.utils.TroveCollectionFactory";
+
+ private static final ICollectionFactory _COLL_FACTORY;
+
+ static {
+ ICollectionFactory collFactory;
+ try {
+ Class.forName("gnu.trove.THashSet");
+ collFactory = (ICollectionFactory) Class.forName(_COLL_FACTORY_TROVE).newInstance();
+ }
+ catch (Exception ex) {
+ collFactory = new JavaCollectionFactory();
+ }
+ _COLL_FACTORY = collFactory;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.utils.ICollectionFactory#createIdentityMap()
+ */
+ public static <K, V> Map<K, V> createIdentityMap() {
+ return _COLL_FACTORY.createIdentityMap();
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.utils.ICollectionFactory#createIdentityMap(int)
+ */
+ public static <K, V> Map<K, V> createIdentityMap(int size) {
+ return _COLL_FACTORY.createIdentityMap(size);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.utils.ICollectionFactory#createIdentitySet(int)
+ */
+ public static <E> Set<E> createIdentitySet(int size) {
+ return _COLL_FACTORY.createIdentitySet(size);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.utils.ICollectionFactory#createIdentitySet()
+ */
+ public static <E> Set<E> createIdentitySet() {
+ return _COLL_FACTORY.createIdentitySet();
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.utils.ICollectionFactory#createMap()
+ */
+ public static <K, V> Map<K, V> createMap() {
+ return _COLL_FACTORY.createMap();
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.utils.ICollectionFactory#createMap(int)
+ */
+ public static <K, V> Map<K, V> createMap(int size) {
+ return _COLL_FACTORY.createMap(size);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.utils.ICollectionFactory#createSet(int)
+ */
+ public static <E> Set<E> createSet(int size) {
+ return _COLL_FACTORY.createSet(size);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.utils.ICollectionFactory#createSet()
+ */
+ public static <E> Set<E> createSet() {
+ return _COLL_FACTORY.createSet();
+ }
+
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java 2008-08-11 12:21:38 UTC (rev 112)
@@ -0,0 +1,36 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim.utils;
+
+/**
+ *
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public interface IIntObjectMap<V> {
+
+ public V put(int key, V value);
+
+ public V get(int key);
+
+ public void clear();
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java 2008-08-11 12:21:38 UTC (rev 112)
@@ -0,0 +1,57 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim.utils;
+
+/**
+ *
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class IntObjectMap {
+
+ private static final boolean _TROVE_AVAILABLE;
+
+ static {
+ boolean available = false;
+ try {
+ // Probe if Trove is available.
+ Class.forName("gnu.trove.THashSet");
+ available = true;
+ }
+ catch (Exception ex) {
+
+ }
+ _TROVE_AVAILABLE = available;
+ }
+
+ private IntObjectMap() {
+ // noop.
+ }
+
+ public static <V> IIntObjectMap<V> create() {
+ return _TROVE_AVAILABLE ? new TroveIntObjectMap<V>() : new JavaIntObjectMap<V>();
+ }
+
+ public static <V> IIntObjectMap<V> create(int size) {
+ return _TROVE_AVAILABLE ? new TroveIntObjectMap<V>(size) : new JavaIntObjectMap<V>(size);
+ }
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java 2008-08-11 12:21:38 UTC (rev 112)
@@ -0,0 +1,160 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim.utils;
+
+import java.util.AbstractSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+
+/**
+ * {@link ICollectionFactory} which uses the standard Java collections.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev$ - $Date$
+ */
+final class JavaCollectionFactory implements ICollectionFactory {
+
+ /* (non-Javadoc)
+ * @see org.tinytim.ICollectionFactory#createMap(int)
+ */
+ public <K, V> Map<K, V> createMap(int size) {
+ return new HashMap<K, V>(size);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.ICollectionFactory#createMap()
+ */
+ public <K, V> Map<K, V> createMap() {
+ return new HashMap<K, V>();
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.ICollectionFactory#createIdentityMap()
+ */
+ public <K, V> Map<K, V> createIdentityMap() {
+ return new IdentityHashMap<K,V>();
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.ICollectionFactory#createIdentityMap(int)
+ */
+ public <K, V> Map<K, V> createIdentityMap(int size) {
+ return new IdentityHashMap<K,V>(size);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.ICollectionFactory#createSet(int)
+ */
+ public <E> Set<E> createSet(int size) {
+ return new HashSet<E>(size);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.ICollectionFactory#createSet()
+ */
+ public <E> Set<E> createSet() {
+ return new HashSet<E>();
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.ICollectionFactory#createIdentitySet()
+ */
+ public <E> Set<E> createIdentitySet() {
+ return new IdentityHashSet<E>();
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.ICollectionFactory#createIdentitySet(int)
+ */
+ public <E> Set<E> createIdentitySet(int size) {
+ return new IdentityHashSet<E>(size);
+ }
+
+ /**
+ * {@link java.util.Set} implementation that compares its elements by
+ * identity.
+ */
+ private static class IdentityHashSet<E> extends AbstractSet<E> {
+
+ private final Map<E, Boolean> _map;
+
+ public IdentityHashSet() {
+ _map = new IdentityHashMap<E, Boolean>();
+ }
+
+ public IdentityHashSet(int size) {
+ _map = new IdentityHashMap<E, Boolean>(size);
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#add(java.lang.Object)
+ */
+ @Override
+ public boolean add(E obj) {
+ return _map.put(obj, Boolean.TRUE) == null;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#remove(java.lang.Object)
+ */
+ @Override
+ public boolean remove(Object obj) {
+ return _map.remove(obj) != null;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#contains(java.lang.Object)
+ */
+ @Override
+ public boolean contains(Object obj) {
+ return _map.containsKey(obj);
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#iterator()
+ */
+ @Override
+ public Iterator<E> iterator() {
+ return _map.keySet().iterator();
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#size()
+ */
+ @Override
+ public int size() {
+ return _map.size();
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#clear()
+ */
+ @Override
+ public void clear() {
+ _map.clear();
+ }
+ }
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java 2008-08-11 12:21:38 UTC (rev 112)
@@ -0,0 +1,62 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+final class JavaIntObjectMap<V> implements IIntObjectMap<V> {
+
+ private final Map<Integer, V> _map;
+
+ JavaIntObjectMap() {
+ _map = new HashMap<Integer, V>();
+ }
+
+ JavaIntObjectMap(int size) {
+ _map = new HashMap<Integer, V>(size);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.utils.IIntObjectMap#get(int)
+ */
+ public V get(int key) {
+ return _map.get(key);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object)
+ */
+ public V put(int key, V value) {
+ return _map.put(Integer.valueOf(key), value);
+ }
+
+ public void clear() {
+ _map.clear();
+ }
+
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java 2008-08-11 12:21:38 UTC (rev 112)
@@ -0,0 +1,97 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim.utils;
+
+import gnu.trove.THashMap;
+import gnu.trove.THashSet;
+import gnu.trove.TObjectIdentityHashingStrategy;
+
+import java.util.Map;
+import java.util.Set;
+
+
+/**
+ * {@link ICollectionFactory} which uses the
+ * <a href="http://sourceforge.net/projects/trove4j/">Trove library </a>.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev$ - $Date$
+ */
+final class TroveCollectionFactory implements ICollectionFactory {
+
+ /* (non-Javadoc)
+ * @see org.tinytim.ICollectionFactory#createMap(int)
+ */
+ public <K, V> Map<K, V> createMap(int size) {
+ return new THashMap<K,V>(size);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.ICollectionFactory#createMap()
+ */
+ public <K, V> Map<K, V> createMap() {
+ return new THashMap<K, V>();
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.ICollectionFactory#createIdentityMap()
+ */
+ public <K, V> Map<K, V> createIdentityMap() {
+ return new THashMap<K, V>(new TObjectIdentityHashingStrategy<K>());
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.ICollectionFactory#createIdentityMap(int)
+ */
+ public <K, V> Map<K, V> createIdentityMap(int size) {
+ return new THashMap<K, V>(size, new TObjectIdentityHashingStrategy<K>());
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.ICollectionFactory#createSet(int)
+ */
+ public <E> Set<E> createSet(int size) {
+ return new THashSet<E>(size);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.ICollectionFactory#createSet()
+ */
+ public <E> Set<E> createSet() {
+ return new THashSet<E>();
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.ICollectionFactory#createIdentitySet()
+ */
+ public <E> Set<E> createIdentitySet() {
+ return new THashSet<E>(new TObjectIdentityHashingStrategy<E>());
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.ICollectionFactory#createIdentitySet(int)
+ */
+ public <E> Set<E> createIdentitySet(int size) {
+ return new THashSet<E>(size, new TObjectIdentityHashingStrategy<E>());
+ }
+
+
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java 2008-08-11 12:21:38 UTC (rev 112)
@@ -0,0 +1,61 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim.utils;
+
+import gnu.trove.TIntObjectHashMap;
+
+/**
+ *
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+final class TroveIntObjectMap<V> implements IIntObjectMap<V> {
+
+ private final TIntObjectHashMap<V> _map;
+
+ TroveIntObjectMap() {
+ _map = new TIntObjectHashMap<V>();
+ }
+
+ TroveIntObjectMap(int size) {
+ _map = new TIntObjectHashMap<V>(size);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.utils.IIntObjectMap#get(int)
+ */
+ public V get(int key) {
+ return _map.get(key);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object)
+ */
+ public V put(int key, V value) {
+ return _map.put(key, value);
+ }
+
+ public void clear() {
+ _map.clear();
+ }
+
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java 2008-08-11 12:21:38 UTC (rev 112)
@@ -0,0 +1,105 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim.utils;
+
+import java.lang.ref.WeakReference;
+import java.util.AbstractSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+/**
+ *
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public final class WeakObjectRegistry<E> extends AbstractSet<E> {
+
+ private final Map<E, WeakReference<E>> _obj2Ref;
+
+ public WeakObjectRegistry() {
+ super();
+ _obj2Ref = new WeakHashMap<E, WeakReference<E>>();
+ }
+
+ /**
+ *
+ *
+ * @param key
+ * @return
+ */
+ public E get(Object key) {
+ WeakReference<E> weakRef = _obj2Ref.get(key);
+ return weakRef != null ? weakRef.get() : null;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#add(java.lang.Object)
+ */
+ @Override
+ public boolean add(E obj) {
+ WeakReference<E> ref = new WeakReference<E>(obj);
+ ref = _obj2Ref.put(obj, ref);
+ return ref != null && ref.get() != null;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#remove(java.lang.Object)
+ */
+ @Override
+ public boolean remove(Object obj) {
+ WeakReference<E> ref = _obj2Ref.remove(obj);
+ return ref != null && ref.get() != null;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#clear()
+ */
+ @Override
+ public void clear() {
+ _obj2Ref.clear();
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#contains(java.lang.Object)
+ */
+ @Override
+ public boolean contains(Object obj) {
+ return get(obj) != null;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#iterator()
+ */
+ @Override
+ public Iterator<E> iterator() {
+ return _obj2Ref.keySet().iterator();
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#size()
+ */
+ @Override
+ public int size() {
+ return _obj2Ref.size();
+ }
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|