001 /*
002 * This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 * This file is licensed to You under the Eclipse Public License (EPL);
005 * You may not use this file except in compliance with the License. You
006 * may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 * See the COPYRIGHT.txt file distributed with this work for information
011 * regarding copyright ownership.
012 */
013 package org.jikesrvm.util;
014
015 /**
016 * A hash set with entirely immutable buckets. It doesn't correctly support
017 * remove, so use with care.
018 */
019 public final class ImmutableEntryHashSetRVM<T> extends AbstractHashSetRVM<T> {
020
021 static final class Bucket<T> extends AbstractBucket<T> {
022 private final T key;
023 private final AbstractBucket<T> next;
024
025 Bucket(T key, AbstractBucket<T> next) {
026 this.key = key;
027 this.next = next;
028 }
029
030 @Override
031 AbstractBucket<T> setNext(AbstractBucket<T> next) {
032 if (this.next == next) {
033 return this;
034 } else {
035 return new Bucket<T>(key, next);
036 }
037 }
038
039 @Override
040 AbstractBucket<T> getNext() {
041 return next;
042 }
043
044 @Override
045 T getKey() {
046 return key;
047 }
048 }
049
050 @Override
051 AbstractBucket<T> createNewBucket(T key, AbstractBucket<T> next) {
052 return new Bucket<T>(key, next);
053 }
054
055 public ImmutableEntryHashSetRVM() {
056 super(DEFAULT_SIZE);
057 }
058
059 public ImmutableEntryHashSetRVM(int size) {
060 super(size);
061 }
062
063 @Override
064 public void remove(T key) {
065 throw new UnsupportedOperationException();
066 }
067 }