~ubuntu-branches/ubuntu/quantal/commons-math/quantal

« back to all changes in this revision

Viewing changes to src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan, Torsten Werner, Damien Raude-Morvan
  • Date: 2011-03-07 21:14:46 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110307211446-4zea7og4eeyzhpai
Tags: 2.2-1
[ Torsten Werner ]
* Change maintainers into Maintainers.

[ Damien Raude-Morvan ]
* New upstream release (Closes: #617209).
* d/control: Bump Standards-Version to 3.9.1 (no changes needed).
* d/copyright: Refresh years, upgrade to DEP5 r166 and relicence my work
  under Apache-2.0.
* d/ant.properties: Set junit.jar to /usr/share/java/junit4.jar
  to ensure unit tests are launched.
* d/docs: Install upstream RELEASE-NOTES.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import org.apache.commons.math.Field;
27
27
import org.apache.commons.math.FieldElement;
28
28
import org.apache.commons.math.MathRuntimeException;
 
29
import org.apache.commons.math.exception.util.LocalizedFormats;
29
30
 
30
31
/**
31
32
 * Open addressed map from int to FieldElement.
36
37
 * <code>ConcurrentModificationException</code> when they detect the map has been
37
38
 * modified during iteration.</p>
38
39
 * @param <T> the type of the field elements
39
 
 * @version $Revision: 903047 $ $Date: 2010-01-25 21:07:42 -0500 (Mon, 25 Jan 2010) $
 
40
 * @version $Revision: 990655 $ $Date: 2010-08-29 23:49:40 +0200 (dim. 29 août 2010) $
40
41
 * @since 2.0
41
42
 */
42
43
public class OpenIntToFieldHashMap<T extends FieldElement<T>> implements Serializable {
53
54
    /** Serializable version identifier. */
54
55
    private static final long serialVersionUID = -9179080286849120720L;
55
56
 
56
 
    /** Message for map modification during iteration. */
57
 
    private static final String CONCURRENT_MODIFICATION_MESSAGE =
58
 
        "map has been modified while iterating";
59
 
 
60
 
    /** Message for exhausted iterator. */
61
 
    private static final String EXHAUSTED_ITERATOR_MESSAGE =
62
 
        "iterator exhausted";
63
 
 
64
57
    /** Load factor for the map. */
65
58
    private static final float LOAD_FACTOR = 0.5f;
66
59
 
172
165
        if (expectedSize == 0) {
173
166
            return 1;
174
167
        }
175
 
        final int capacity   = (int) Math.ceil(expectedSize / LOAD_FACTOR);
 
168
        final int capacity   = (int) FastMath.ceil(expectedSize / LOAD_FACTOR);
176
169
        final int powerOfTwo = Integer.highestOneBit(capacity);
177
170
        if (powerOfTwo == capacity) {
178
171
            return capacity;
546
539
        public int key()
547
540
            throws ConcurrentModificationException, NoSuchElementException {
548
541
            if (referenceCount != count) {
549
 
                throw MathRuntimeException.createConcurrentModificationException(
550
 
                      CONCURRENT_MODIFICATION_MESSAGE);
 
542
                throw MathRuntimeException.createConcurrentModificationException(LocalizedFormats.MAP_MODIFIED_WHILE_ITERATING);
551
543
            }
552
544
            if (current < 0) {
553
 
                throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE);
 
545
                throw MathRuntimeException.createNoSuchElementException(LocalizedFormats.ITERATOR_EXHAUSTED);
554
546
            }
555
547
            return keys[current];
556
548
        }
564
556
        public T value()
565
557
            throws ConcurrentModificationException, NoSuchElementException {
566
558
            if (referenceCount != count) {
567
 
                throw MathRuntimeException.createConcurrentModificationException(
568
 
                      CONCURRENT_MODIFICATION_MESSAGE);
 
559
                throw MathRuntimeException.createConcurrentModificationException(LocalizedFormats.MAP_MODIFIED_WHILE_ITERATING);
569
560
            }
570
561
            if (current < 0) {
571
 
                throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE);
 
562
                throw MathRuntimeException.createNoSuchElementException(LocalizedFormats.ITERATOR_EXHAUSTED);
572
563
            }
573
564
            return values[current];
574
565
        }
582
573
            throws ConcurrentModificationException, NoSuchElementException {
583
574
 
584
575
            if (referenceCount != count) {
585
 
                throw MathRuntimeException.createConcurrentModificationException(
586
 
                      CONCURRENT_MODIFICATION_MESSAGE);
 
576
                throw MathRuntimeException.createConcurrentModificationException(LocalizedFormats.MAP_MODIFIED_WHILE_ITERATING);
587
577
            }
588
578
 
589
579
            // advance on step
597
587
            } catch (ArrayIndexOutOfBoundsException e) {
598
588
                next = -2;
599
589
                if (current < 0) {
600
 
                    throw MathRuntimeException.createNoSuchElementException(EXHAUSTED_ITERATOR_MESSAGE);
 
590
                    throw MathRuntimeException.createNoSuchElementException(LocalizedFormats.ITERATOR_EXHAUSTED);
601
591
                }
602
592
            }
603
593