diff options
author | Noel Grandin <noel@peralex.com> | 2012-06-28 11:27:57 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-06-29 22:03:03 +0200 |
commit | 7af400558072e2f328f078e39a121a95bb928804 (patch) | |
tree | 464515102ce5d6cad3b5a304e77737532d206e83 /jurt/com/sun/star/lib | |
parent | 9def9b4674b9610004e915635578d26a48d98300 (diff) |
Java5 update - convert code to use generics
Change-Id: Iff078cea287d0c508d2442d65cd9314ec3231c15
Diffstat (limited to 'jurt/com/sun/star/lib')
11 files changed, 63 insertions, 65 deletions
diff --git a/jurt/com/sun/star/lib/connections/pipe/PipeConnection.java b/jurt/com/sun/star/lib/connections/pipe/PipeConnection.java index d4d6bdb83322..679359dea52f 100644 --- a/jurt/com/sun/star/lib/connections/pipe/PipeConnection.java +++ b/jurt/com/sun/star/lib/connections/pipe/PipeConnection.java @@ -51,7 +51,7 @@ public class PipeConnection implements XConnection, XConnectionBroadcaster { protected String _aDescription; protected long _nPipeHandle; - protected ArrayList _aListeners; + protected ArrayList<XStreamListener> _aListeners; protected boolean _bFirstRead; /** @@ -65,7 +65,7 @@ public class PipeConnection implements XConnection, XConnectionBroadcaster { { if (DEBUG) System.err.println("##### " + getClass().getName() + " - instantiated " + description ); - _aListeners = new ArrayList(); + _aListeners = new ArrayList<XStreamListener>(); _bFirstRead = true; // get pipe name from pipe descriptor @@ -105,25 +105,25 @@ public class PipeConnection implements XConnection, XConnectionBroadcaster { } private void notifyListeners_open() { - Iterator elements = _aListeners.iterator(); + Iterator<XStreamListener> elements = _aListeners.iterator(); while(elements.hasNext()) { - XStreamListener xStreamListener = (XStreamListener)elements.next(); + XStreamListener xStreamListener = elements.next(); xStreamListener.started(); } } private void notifyListeners_close() { - Iterator elements = _aListeners.iterator(); + Iterator<XStreamListener> elements = _aListeners.iterator(); while(elements.hasNext()) { - XStreamListener xStreamListener = (XStreamListener)elements.next(); + XStreamListener xStreamListener = elements.next(); xStreamListener.closed(); } } private void notifyListeners_error(com.sun.star.uno.Exception exception) { - Iterator elements = _aListeners.iterator(); + Iterator<XStreamListener> elements = _aListeners.iterator(); while(elements.hasNext()) { - XStreamListener xStreamListener = (XStreamListener)elements.next(); + XStreamListener xStreamListener = elements.next(); xStreamListener.error(exception); } } diff --git a/jurt/com/sun/star/lib/connections/socket/SocketConnection.java b/jurt/com/sun/star/lib/connections/socket/SocketConnection.java index 5207bade57ef..9809f0eeaba0 100644 --- a/jurt/com/sun/star/lib/connections/socket/SocketConnection.java +++ b/jurt/com/sun/star/lib/connections/socket/SocketConnection.java @@ -52,7 +52,7 @@ public class SocketConnection implements XConnection, XConnectionBroadcaster { protected Socket _socket; protected InputStream _inputStream; protected OutputStream _outputStream; - protected ArrayList _listeners; + protected ArrayList<XStreamListener> _listeners; protected boolean _firstRead; /** @@ -74,7 +74,7 @@ public class SocketConnection implements XConnection, XConnectionBroadcaster { _inputStream = new BufferedInputStream(socket.getInputStream()); _outputStream = new BufferedOutputStream(socket.getOutputStream()); - _listeners = new ArrayList(); + _listeners = new ArrayList<XStreamListener>(); _firstRead = true; } @@ -90,25 +90,25 @@ public class SocketConnection implements XConnection, XConnectionBroadcaster { } private void notifyListeners_open() { - Iterator elements = _listeners.iterator(); + Iterator<XStreamListener> elements = _listeners.iterator(); while(elements.hasNext()) { - XStreamListener xStreamListener = (XStreamListener)elements.next(); + XStreamListener xStreamListener = elements.next(); xStreamListener.started(); } } private void notifyListeners_close() { - Iterator elements = _listeners.iterator(); + Iterator<XStreamListener> elements = _listeners.iterator(); while(elements.hasNext()) { - XStreamListener xStreamListener = (XStreamListener)elements.next(); + XStreamListener xStreamListener = elements.next(); xStreamListener.closed(); } } private void notifyListeners_error(com.sun.star.uno.Exception exception) { - Iterator elements = _listeners.iterator(); + Iterator<XStreamListener> elements = _listeners.iterator(); while(elements.hasNext()) { - XStreamListener xStreamListener = (XStreamListener)elements.next(); + XStreamListener xStreamListener = elements.next(); xStreamListener.error(exception); } } diff --git a/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java b/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java index 36c66ffe66e7..7b57e87c0687 100644 --- a/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java +++ b/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java @@ -24,12 +24,10 @@ import java.io.OutputStream; import java.util.ArrayList; -import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; -import java.util.Vector; import com.sun.star.lib.util.DisposeListener; import com.sun.star.lib.util.DisposeNotifier; @@ -167,7 +165,7 @@ public class java_remote_bridge protected MessageDispatcher _messageDispatcher; protected int _life_count = 0; // determines if this bridge is alife, which is controlled by acquire and release calls - private final ArrayList _listeners = new ArrayList(); + private final ArrayList<XEventListener> _listeners = new ArrayList<XEventListener>(); protected IThreadPool _iThreadPool; @@ -215,15 +213,15 @@ public class java_remote_bridge private int count = 1; } - private final HashMap refHolders = new HashMap(); + private final HashMap<String, LinkedList<RefHolder>> refHolders = new HashMap<String, LinkedList<RefHolder>>(); // from OID (String) to LinkedList of RefHolder private boolean hasRefHolder(String oid, Type type) { synchronized (refHolders) { - LinkedList l = (LinkedList) refHolders.get(oid); + LinkedList<RefHolder> l = refHolders.get(oid); if (l != null) { - for (Iterator i = l.iterator(); i.hasNext();) { - RefHolder rh = (RefHolder) i.next(); + for (Iterator<RefHolder> i = l.iterator(); i.hasNext();) { + RefHolder rh = i.next(); if (type.isSupertypeOf(rh.getType())) { return true; } @@ -235,14 +233,14 @@ public class java_remote_bridge final void addRefHolder(Object obj, Type type, String oid) { synchronized (refHolders) { - LinkedList l = (LinkedList) refHolders.get(oid); + LinkedList<RefHolder> l = refHolders.get(oid); if (l == null) { - l = new LinkedList(); + l = new LinkedList<RefHolder>(); refHolders.put(oid, l); } boolean found = false; - for (Iterator i = l.iterator(); !found && i.hasNext();) { - RefHolder rh = (RefHolder) i.next(); + for (Iterator<RefHolder> i = l.iterator(); !found && i.hasNext();) { + RefHolder rh = i.next(); if (rh.getType().equals(type)) { found = true; rh.acquire(); @@ -257,10 +255,10 @@ public class java_remote_bridge final void remRefHolder(Type type, String oid) { synchronized (refHolders) { - LinkedList l = (LinkedList) refHolders.get(oid); + LinkedList<RefHolder> l = refHolders.get(oid); if (l != null) { - for (Iterator i = l.iterator(); i.hasNext();) { - RefHolder rh = (RefHolder) i.next(); + for (Iterator<RefHolder> i = l.iterator(); i.hasNext();) { + RefHolder rh = i.next(); if (rh.getType().equals(type)) { try { if (rh.release()) { @@ -281,13 +279,13 @@ public class java_remote_bridge final void freeHolders() { synchronized (refHolders) { - for (Iterator i1 = refHolders.entrySet().iterator(); i1.hasNext();) + for (Iterator<Map.Entry<String,LinkedList<RefHolder>>> i1 = refHolders.entrySet().iterator(); i1.hasNext();) { - Map.Entry e = (Map.Entry) i1.next(); - String oid = (String) e.getKey(); - LinkedList l = (LinkedList) e.getValue(); - for (Iterator i2 = l.iterator(); i2.hasNext();) { - RefHolder rh = (RefHolder) i2.next(); + Map.Entry<String,LinkedList<RefHolder>> e = i1.next(); + String oid = e.getKey(); + LinkedList<RefHolder> l = e.getValue(); + for (Iterator<RefHolder> i2 = l.iterator(); i2.hasNext();) { + RefHolder rh = i2.next(); for (boolean done = false; !done;) { done = rh.release(); _java_environment.revokeInterface(oid, rh.getType()); @@ -341,9 +339,9 @@ public class java_remote_bridge private void notifyListeners() { EventObject eventObject = new EventObject(this); - Iterator elements = _listeners.iterator(); + Iterator<XEventListener> elements = _listeners.iterator(); while(elements.hasNext()) { - XEventListener xEventListener = (XEventListener)elements.next(); + XEventListener xEventListener = elements.next(); try { xEventListener.disposing(eventObject); @@ -485,8 +483,8 @@ public class java_remote_bridge } notifyListeners(); - for (Iterator i = disposeListeners.iterator(); i.hasNext();) { - ((DisposeListener) i.next()).notifyDispose(this); + for (Iterator<DisposeListener> i = disposeListeners.iterator(); i.hasNext();) { + i.next().notifyDispose(this); } _iProtocol.terminate(); @@ -698,5 +696,5 @@ public class java_remote_bridge private final ProxyFactory proxyFactory; // Access to disposeListeners must be synchronized on <CODE>this</CODE>: - private final ArrayList disposeListeners = new ArrayList(); + private final ArrayList<DisposeListener> disposeListeners = new ArrayList<DisposeListener>(); } diff --git a/jurt/com/sun/star/lib/uno/environments/java/java_environment.java b/jurt/com/sun/star/lib/uno/environments/java/java_environment.java index 427f24d7d36a..1fdfdf9e3d9b 100644 --- a/jurt/com/sun/star/lib/uno/environments/java/java_environment.java +++ b/jurt/com/sun/star/lib/uno/environments/java/java_environment.java @@ -263,7 +263,7 @@ public final class java_environment implements IEnvironment { private static final class Level2Entry extends WeakReference<Object> { public Level2Entry( - String oid, Type type, Object object, ReferenceQueue queue) + String oid, Type type, Object object, ReferenceQueue<Object> queue) { super(object, queue); this.oid = oid; @@ -288,7 +288,7 @@ public final class java_environment implements IEnvironment { private final HashMap<String, Level1Entry> level1map = new HashMap<String, Level1Entry>(); - private final ReferenceQueue queue = new ReferenceQueue(); + private final ReferenceQueue<Object> queue = new ReferenceQueue<Object>(); } private boolean isProxy(Object object) { diff --git a/jurt/com/sun/star/lib/uno/environments/remote/JavaThreadPoolFactory.java b/jurt/com/sun/star/lib/uno/environments/remote/JavaThreadPoolFactory.java index 6e9ea465b7fb..9d5fc2c6334b 100644 --- a/jurt/com/sun/star/lib/uno/environments/remote/JavaThreadPoolFactory.java +++ b/jurt/com/sun/star/lib/uno/environments/remote/JavaThreadPoolFactory.java @@ -43,7 +43,7 @@ final class JavaThreadPoolFactory { public JobQueue getJobQueue(ThreadId threadId) { synchronized (jobQueues) { - return (JobQueue) jobQueues.get(threadId); + return jobQueues.get(threadId); } } @@ -55,8 +55,8 @@ final class JavaThreadPoolFactory { public void dispose(Object disposeId, Throwable throwable) { JobQueue[] qs; synchronized (jobQueues) { - Collection c = jobQueues.values(); - qs = (JobQueue[]) c.toArray(new JobQueue[c.size()]); + Collection<JobQueue> c = jobQueues.values(); + qs = c.toArray(new JobQueue[c.size()]); } for (int i = 0; i < qs.length; ++i) { qs[i].dispose(disposeId, throwable); @@ -70,7 +70,7 @@ final class JavaThreadPoolFactory { } else { ThreadId id; synchronized (threadIdMap) { - id = (ThreadId) threadIdMap.get(t); + id = threadIdMap.get(t); if (id == null) { id = ThreadId.createFresh(); threadIdMap.put(t, id); @@ -80,6 +80,6 @@ final class JavaThreadPoolFactory { } } - private static final WeakHashMap threadIdMap = new WeakHashMap(); - private final HashMap jobQueues = new HashMap(); + private static final WeakHashMap<Thread, ThreadId> threadIdMap = new WeakHashMap<Thread, ThreadId>(); + private final HashMap<ThreadId, JobQueue> jobQueues = new HashMap<ThreadId, JobQueue>(); } diff --git a/jurt/com/sun/star/lib/uno/environments/remote/Job.java b/jurt/com/sun/star/lib/uno/environments/remote/Job.java index df1f49d7d525..cc8d142ed68f 100644 --- a/jurt/com/sun/star/lib/uno/environments/remote/Job.java +++ b/jurt/com/sun/star/lib/uno/environments/remote/Job.java @@ -67,7 +67,7 @@ public class Job { * @param o_out_sig the out signature as an out parameter */ protected Object dispatch_queryInterface(Type type) { - Class zInterface = type.getTypeDescription().getZClass(); + Class<?> zInterface = type.getTypeDescription().getZClass(); Object result = null; diff --git a/jurt/com/sun/star/lib/uno/protocols/urp/Cache.java b/jurt/com/sun/star/lib/uno/protocols/urp/Cache.java index 5a2670e50b7f..14affb5bd974 100644 --- a/jurt/com/sun/star/lib/uno/protocols/urp/Cache.java +++ b/jurt/com/sun/star/lib/uno/protocols/urp/Cache.java @@ -38,7 +38,7 @@ final class Cache { } public int add(boolean[] found, Object content) { - Entry e = (Entry) map.get(content); + Entry e = map.get(content); found[0] = e != null; if (e == null) { if (map.size() < maxSize) { @@ -105,7 +105,7 @@ final class Cache { // map contains the same entries; each entry has a unique index in the range // 0 to maxSize - 1 private final int maxSize; - private final HashMap map = new HashMap(); // from Object to Entry + private final HashMap<Object, Entry> map = new HashMap<Object, Entry>(); // from Object to Entry private Entry first = null; private Entry last = null; } diff --git a/jurt/com/sun/star/lib/uno/protocols/urp/PendingRequests.java b/jurt/com/sun/star/lib/uno/protocols/urp/PendingRequests.java index 72a72dab3815..18005bd817c7 100644 --- a/jurt/com/sun/star/lib/uno/protocols/urp/PendingRequests.java +++ b/jurt/com/sun/star/lib/uno/protocols/urp/PendingRequests.java @@ -27,17 +27,17 @@ final class PendingRequests { public PendingRequests() {} public synchronized void push(ThreadId tid, Item item) { - Stack s = (Stack) map.get(tid); + Stack<Item> s = map.get(tid); if (s == null) { - s = new Stack(); + s = new Stack<Item>(); map.put(tid, s); } s.push(item); } public synchronized Item pop(ThreadId tid) { - Stack s = (Stack) map.get(tid); - Item i = (Item) s.pop(); + Stack<Item> s = map.get(tid); + Item i = s.pop(); if (s.empty()) { map.remove(tid); } @@ -58,5 +58,5 @@ final class PendingRequests { public final Object[] arguments; } - private final HashMap map = new HashMap(); // from ThreadId to Stack of Item + private final HashMap<ThreadId, Stack<Item>> map = new HashMap<ThreadId, Stack<Item>>(); // from ThreadId to Stack of Item } diff --git a/jurt/com/sun/star/lib/uno/protocols/urp/urp.java b/jurt/com/sun/star/lib/uno/protocols/urp/urp.java index c9af603478fd..aac00536db92 100644 --- a/jurt/com/sun/star/lib/uno/protocols/urp/urp.java +++ b/jurt/com/sun/star/lib/uno/protocols/urp/urp.java @@ -602,7 +602,7 @@ public final class urp implements IProtocol { private void writeQueuedReleases() throws IOException { for (int i = releaseQueue.size(); i > 0;) { --i; - QueuedRelease r = (QueuedRelease) releaseQueue.get(i); + QueuedRelease r = releaseQueue.get(i); writeRequest( r.internal, r.objectId, r.type, r.method, r.threadId, null, false); @@ -733,5 +733,5 @@ public final class urp implements IProtocol { private String outL1Oid = null; private ITypeDescription outL1Type = null; - private final ArrayList releaseQueue = new ArrayList(); // of QueuedRelease + private final ArrayList<QueuedRelease> releaseQueue = new ArrayList<QueuedRelease>(); // of QueuedRelease } diff --git a/jurt/com/sun/star/lib/util/AsynchronousFinalizer.java b/jurt/com/sun/star/lib/util/AsynchronousFinalizer.java index 2608f3734da3..8839b1194255 100644 --- a/jurt/com/sun/star/lib/util/AsynchronousFinalizer.java +++ b/jurt/com/sun/star/lib/util/AsynchronousFinalizer.java @@ -64,7 +64,7 @@ public final class AsynchronousFinalizer { void run() throws Throwable; } - private static final LinkedList queue = new LinkedList(); + private static final LinkedList<Job> queue = new LinkedList<Job>(); static { Thread t = new Thread() { @@ -77,7 +77,7 @@ public final class AsynchronousFinalizer { queue.wait(); } catch (InterruptedException e) {} } - j = (Job) queue.remove(0); + j = queue.remove(0); } try { j.run(); diff --git a/jurt/com/sun/star/lib/util/UrlToFileMapper.java b/jurt/com/sun/star/lib/util/UrlToFileMapper.java index 57cc19ea04a9..252021c3064e 100644 --- a/jurt/com/sun/star/lib/util/UrlToFileMapper.java +++ b/jurt/com/sun/star/lib/util/UrlToFileMapper.java @@ -35,13 +35,13 @@ public final class UrlToFileMapper { // java.net.URLEncoder.encode(String, String) and java.net.URI are only // available since Java 1.4: private static Method urlEncoderEncode; - private static Constructor uriConstructor; - private static Constructor fileConstructor; + private static Constructor<?> uriConstructor; + private static Constructor<File> fileConstructor; static { try { urlEncoderEncode = URLEncoder.class.getMethod( "encode", new Class[] { String.class, String.class }); - Class uriClass = Class.forName("java.net.URI"); + Class<?> uriClass = Class.forName("java.net.URI"); uriConstructor = uriClass.getConstructor( new Class[] { String.class }); fileConstructor = File.class.getConstructor( @@ -90,7 +90,7 @@ public final class UrlToFileMapper { Object uri = uriConstructor.newInstance( new Object[] { encodedUrl }); try { - return (File) fileConstructor.newInstance( + return fileConstructor.newInstance( new Object[] { uri }); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof |