Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 149658 Details for
Bug 292428
Internal compiler error: NullPointerException at org.eclipse.jdt.internal.compiler.ast.CastExpression.checkUnsafeCast(CastExpression.java:333)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
file that cannot be compiled
MultiValueHashMap.java (text/plain), 7.01 KB, created by
David Green
on 2009-10-15 12:42:59 EDT
(
hide
)
Description:
file that cannot be compiled
Filename:
MIME Type:
Creator:
David Green
Created:
2009-10-15 12:42:59 EDT
Size:
7.01 KB
patch
obsolete
>package com.maketechnologies.dmw.transformer.util; > >import java.io.Serializable; >import java.util.ArrayList; >import java.util.Collection; >import java.util.HashMap; >import java.util.Iterator; >import java.util.NoSuchElementException; > >/** Implements a quick and memory efficient HashMap that can has more than one > * item per key. Memory behaviour is the same as HashMap for single items. Only > * extra memory is used when multiple items are stored for the same key. > * > * Note that get returns a Collection interface > * > * Created on Mar 26, 2005 > */ >public class MultiValueHashMap<K,V> implements Serializable { > > // Inner classes > private interface Entry<V> extends Collection<V>, Serializable { > boolean isSingleEntry(); > V get( int i ); > } > > private static class NullEntry implements Entry { >// NullEntry() {} > public boolean isSingleEntry() { return false; } > public Object get( int i ) { return null; } > public int size() { return 0; } > public boolean isEmpty() { return true; } > public boolean contains( Object o ) { return false; } > public Object[] toArray() { return null; } > @SuppressWarnings("unchecked") > public Object[] toArray( Object[] a ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public boolean add( Object v ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public boolean remove( Object o ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public boolean containsAll( Collection c ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public boolean addAll( Collection c ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public boolean removeAll( Collection c ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public boolean retainAll( Collection c ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public void clear() { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public Iterator<Object> iterator() { > return new Iterator<Object>() { > public Object next() { throw new NoSuchElementException(); } > public void remove() { throw new NoSuchElementException(); } > public boolean hasNext() { return false; } > }; > } > } > > private class SingleEntry implements Entry<V> { > V value; > SingleEntry( V value ) { this.value = value; } > public boolean isSingleEntry() { return true; } > public V get( int i ) { assert i == 0; return value; } > public int size() { return 1; } > public boolean isEmpty() { return false; } > public boolean contains( Object o ) { return value == o; } > public Object[] toArray() { Object a[] = { value }; return a; } > @SuppressWarnings("hiding") > public <V> V[] toArray( V[] a ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public boolean add( V v ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public boolean remove( Object o ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public boolean containsAll( Collection c ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public boolean addAll( Collection c ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public boolean removeAll( Collection c ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public boolean retainAll( Collection c ) { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public void clear() { throw new UnsupportedOperationException( "Collection is unmutable" ); } > public Iterator<V> iterator() { > return new Iterator<V>() { > boolean done = false; > public V next() { > if (done) throw new NoSuchElementException(); > done = true; > return value; > } > public void remove() { hash.remove( this ); } > public boolean hasNext() { return !done; } > }; > } > } > > private class MultipleEntry implements Entry<V> { > ArrayList<V> values = new ArrayList<V>( 5 ); > MultipleEntry( Entry<V> se ) { values.add( ((SingleEntry)se).value ); } > public boolean isSingleEntry() { return false; } > public V get( int i ) { return values.get( i ); } > public boolean add( V v ) { return values.add( v ); } > public int size() { return values.size(); } > public boolean isEmpty() { return values.isEmpty(); } > public boolean contains( Object o ) { return values.contains( o ); } > public Iterator<V> iterator() { return values.iterator(); } > public Object[] toArray() { return values.toArray(); } > @SuppressWarnings("hiding") > public <V> V[] toArray( V[] a ) { return values.toArray( a ); } > public boolean remove( Object o ) { return values.remove( o ); } > public boolean containsAll( Collection c ) { return values.containsAll( c ); } > public boolean addAll( Collection<?extends V> c ) { return values.addAll( c ); } > public boolean removeAll( Collection c ) { return values.removeAll( c ); } > public boolean retainAll( Collection c ) { return values.retainAll( c ); } > public void clear() { values.clear(); } > } > > static NullEntry nullEntry = new NullEntry(); > >// Member variables > protected HashMap<K, Entry<V>> hash; > private int size = 0; > > public MultiValueHashMap() { > hash = new HashMap<K, Entry<V>>(); > } > > public MultiValueHashMap( int size ) { > hash = new HashMap<K, Entry<V>>( size ); > } > > /** > * Add V to the K entry > * @param k the key to add value to > * @param v the value to add > * @return the number of values associated with k > */ > public int put( K k, V v ) { > Entry<V> entry = hash.get( k ); > size++; > if (entry == null) { > hash.put( k, new SingleEntry( v ) ); > return 1; > } > else if (entry.isSingleEntry()) { > hash.put( k, new MultipleEntry( entry ) ); > return 2; > } > else { > entry.add( v ); > return entry.size(); > } > } > > @SuppressWarnings("unchecked") > public Collection<V> get( K k ) { > Entry<V> e = hash.get( k ); > if (e == null) return nullEntry; > else return e; > } > > /** > * Removes a single instance of v from key k. > * @param k the key > * @param v the value to remove > * @return v. if k is not in the map, returns null > */ > public V remove( K k, V v ) { > Entry<V> e = hash.get( k ); > if (e == null) { return null; } > size--; > if (e.isSingleEntry()) { hash.remove( k ); return v; } > else if (e.remove( v )) { return v; } > else { throw new UnsupportedOperationException( "Illegal attempt: value does not belong to key" ); } > } > > public void clear() { > size = 0; > hash.clear(); > } > > /** > * @return the number of values in the system. > */ > public int size() { > return size; > } > > /** > * @return the number of keys in the map > */ > public int keyCount() { > return hash.size(); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 292428
: 149658 |
149670