From 814ad6b1d7221b7c64e178328c715348da9fa307 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 16 May 2008 22:16:50 +0000 Subject: [PATCH] Third time's a charm: apparently values() is problematic, so let's try using a normal HashMap. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5104 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/presents/net/Transport.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/java/com/threerings/presents/net/Transport.java b/src/java/com/threerings/presents/net/Transport.java index d326ce976..d1c13a21c 100644 --- a/src/java/com/threerings/presents/net/Transport.java +++ b/src/java/com/threerings/presents/net/Transport.java @@ -21,6 +21,8 @@ package com.threerings.presents.net; +import java.util.HashMap; + import com.samskivert.util.HashIntMap; /** @@ -139,27 +141,23 @@ public class Transport // of instances and use Transport objects as keys (as in examples of the flyweight // pattern). however, doing it this way avoids the need to create a new object on lookup if (_unordered == null) { - int length = Type.values().length; - _unordered = new Transport[length]; - @SuppressWarnings("unchecked") HashIntMap[] ordered = - (HashIntMap[])new HashIntMap[length]; - _ordered = ordered; + _unordered = new HashMap(); + _ordered = new HashMap>(); } // for unordered transport, we map on the type alone - int idx = type.ordinal(); if (!type.isOrdered()) { - Transport instance = _unordered[idx]; + Transport instance = _unordered.get(type); if (instance == null) { - _unordered[idx] = instance = new Transport(type); + _unordered.put(type, instance = new Transport(type)); } return instance; } // for ordered transport, we map on the type and channel - HashIntMap instances = _ordered[idx]; + HashIntMap instances = _ordered.get(type); if (instances == null) { - _ordered[idx] = instances = new HashIntMap(); + _ordered.put(type, instances = new HashIntMap()); } Transport instance = instances.get(channel); if (instance == null) { @@ -252,8 +250,8 @@ public class Transport /** Unordered instances mapped by type (would use {@link java.util.EnumMap}, but it doesn't * work with Retroweaver). */ - protected static Transport[] _unordered; + protected static HashMap _unordered; /** Ordered instances mapped by type and channel. */ - protected static HashIntMap[] _ordered; + protected static HashMap> _ordered; }