@Override public String toString() { final StringBuilder s = new StringBuilder(); final ObjectIterator<Reference2DoubleMap.Entry<K>> i = Reference2DoubleMaps.fastIterator(this); int n = size(); Reference2DoubleMap.Entry<K> e; boolean first = true; s.append("{"); while (n-- != 0) { if (first) first = false; else s.append(", "); e = i.next(); if (this == e.getKey()) s.append("(this map)"); else s.append(String.valueOf(e.getKey())); s.append("=>"); s.append(String.valueOf(e.getDoubleValue())); } s.append("}"); return s.toString(); } }
/** * {@inheritDoc} * * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override default Double setValue(final Double value) { return Double.valueOf(setValue((value).doubleValue())); } }
/** {@inheritDoc} */ @SuppressWarnings({"unchecked", "deprecation"}) @Override public void putAll(final Map<? extends K, ? extends Double> m) { if (m instanceof Reference2DoubleMap) { ObjectIterator<Reference2DoubleMap.Entry<K>> i = Reference2DoubleMaps .fastIterator((Reference2DoubleMap<K>) m); while (i.hasNext()) { final Reference2DoubleMap.Entry<? extends K> e = i.next(); put(e.getKey(), e.getDoubleValue()); } } else { int n = m.size(); final Iterator<? extends Map.Entry<? extends K, ? extends Double>> i = m.entrySet().iterator(); Map.Entry<? extends K, ? extends Double> e; while (n-- != 0) { e = i.next(); put(e.getKey(), e.getValue()); } } } /**
/** Copies the argument internally, rescaling weights so they sum up to one. * * @param index2Weight the new map from indices to weights. * @return true. */ public synchronized boolean setWeights( final Reference2DoubleMap<Index> index2Weight ) { this.index2Weight.clear(); this.index2Weight.defaultReturnValue( 0 ); // Since we're setting up values, we must assume missing indices have weight 0. double weightSum = 0; for( DoubleIterator i = index2Weight.values().iterator(); i.hasNext(); ) weightSum += i.nextDouble(); if ( weightSum == 0 ) weightSum = 1; // No positive weights. for( ObjectIterator<Entry<Index, Double>> i = index2Weight.entrySet().iterator(); i.hasNext(); ) { Reference2DoubleMap.Entry<Index> e = (Reference2DoubleMap.Entry<Index>)i.next(); this.index2Weight.put( e.getKey(), e.getDoubleValue() / weightSum ); } this.index2Weight.trim(); LOGGER.debug( "New weight map for " + this + ": " + this.index2Weight ); return true; }
/** Copies the argument internally, rescaling weights so they sum up to one. * * @param index2Weight the new map from indices to weights. * @return true. */ public synchronized boolean setWeights( final Reference2DoubleMap<Index> index2Weight ) { this.index2Weight.clear(); this.index2Weight.defaultReturnValue( 0 ); // Since we're setting up values, we must assume missing indices have weight 0. double weightSum = 0; for( DoubleIterator i = index2Weight.values().iterator(); i.hasNext(); ) weightSum += i.nextDouble(); if ( weightSum == 0 ) weightSum = 1; // No positive weights. for( ObjectIterator<Entry<Index, Double>> i = index2Weight.entrySet().iterator(); i.hasNext(); ) { Reference2DoubleMap.Entry<Index> e = (Reference2DoubleMap.Entry<Index>)i.next(); this.index2Weight.put( e.getKey(), e.getDoubleValue() / weightSum ); } this.index2Weight.trim(); LOGGER.debug( "New weight map for " + this + ": " + this.index2Weight ); return true; }
/** Copies the argument internally, rescaling weights so they sum up to one. * * @param index2Weight the new map from indices to weights. * @return true. */ public synchronized boolean setWeights( final Reference2DoubleMap<Index> index2Weight ) { this.index2Weight.clear(); this.index2Weight.defaultReturnValue( 0 ); // Since we're setting up values, we must assume missing indices have weight 0. double weightSum = 0; for( DoubleIterator i = index2Weight.values().iterator(); i.hasNext(); ) weightSum += i.nextDouble(); if ( weightSum == 0 ) weightSum = 1; // No positive weights. for( ObjectIterator<Entry<Index, Double>> i = index2Weight.entrySet().iterator(); i.hasNext(); ) { Reference2DoubleMap.Entry<Index> e = (Reference2DoubleMap.Entry<Index>)i.next(); this.index2Weight.put( e.getKey(), e.getDoubleValue() / weightSum ); } this.index2Weight.trim(); LOGGER.debug( "New weight map for " + this + ": " + this.index2Weight ); return true; }
@SuppressWarnings("unchecked") @Override public boolean contains(final Object o) { if (!(o instanceof Map.Entry)) return false; if (o instanceof Reference2DoubleMap.Entry) { final Reference2DoubleMap.Entry<K> e = (Reference2DoubleMap.Entry<K>) o; final K k = e.getKey(); return map.containsKey(k) && (Double.doubleToLongBits(map.getDouble(k)) == Double.doubleToLongBits(e.getDoubleValue())); } final Map.Entry<?, ?> e = (Map.Entry<?, ?>) o; final Object k = e.getKey(); final Object value = e.getValue(); if (value == null || !(value instanceof Double)) return false; return map.containsKey(k) && (Double.doubleToLongBits(map.getDouble(k)) == Double .doubleToLongBits(((Double) (value)).doubleValue())); } @SuppressWarnings("unchecked")
@SuppressWarnings("unchecked") @Override public boolean equals(final Object o) { if (!(o instanceof Map.Entry)) return false; if (o instanceof Reference2DoubleMap.Entry) { final Reference2DoubleMap.Entry<K> e = (Reference2DoubleMap.Entry<K>) o; return ((key) == (e.getKey())) && (Double.doubleToLongBits(value) == Double.doubleToLongBits(e.getDoubleValue())); } final Map.Entry<?, ?> e = (Map.Entry<?, ?>) o; final Object key = e.getKey(); final Object value = e.getValue(); if (value == null || !(value instanceof Double)) return false; return ((this.key) == ((key))) && (Double.doubleToLongBits(this.value) == Double .doubleToLongBits(((Double) (value)).doubleValue())); } @Override
/** Copies the argument internally, rescaling weights so they sum up to one. * * @param index2Weight the new map from indices to weights. * @return true. */ public synchronized boolean setWeights( final Reference2DoubleMap<Index> index2Weight ) { this.index2Weight.clear(); this.index2Weight.defaultReturnValue( 0 ); // Since we're setting up values, we must assume missing indices have weight 0. double weightSum = 0; for( DoubleIterator i = index2Weight.values().iterator(); i.hasNext(); ) weightSum += i.nextDouble(); if ( weightSum == 0 ) weightSum = 1; // No positive weights. for( ObjectIterator<Entry<Index, Double>> i = index2Weight.entrySet().iterator(); i.hasNext(); ) { Reference2DoubleMap.Entry<Index> e = (Reference2DoubleMap.Entry<Index>)i.next(); this.index2Weight.put( e.getKey(), e.getDoubleValue() / weightSum ); } this.index2Weight.trim(); LOGGER.debug( "New weight map for " + this + ": " + this.index2Weight ); return true; }
@SuppressWarnings("unchecked") @Override public boolean remove(final Object o) { if (!(o instanceof Map.Entry)) return false; if (o instanceof Reference2DoubleMap.Entry) { final Reference2DoubleMap.Entry<K> e = (Reference2DoubleMap.Entry<K>) o; return map.remove(e.getKey(), e.getDoubleValue()); } Map.Entry<?, ?> e = (Map.Entry<?, ?>) o; final Object k = e.getKey(); final Object value = e.getValue(); if (value == null || !(value instanceof Double)) return false; final double v = ((Double) (value)).doubleValue(); return map.remove(k, v); } @Override
@Override public double nextDouble() { return i.next().getDoubleValue(); }; @Override
@Override public boolean containsKey(final Object k) { final ObjectIterator<Reference2DoubleMap.Entry<K>> i = reference2DoubleEntrySet().iterator(); while (i.hasNext()) if (i.next().getKey() == k) return true; return false; } @Override
/** * {@inheritDoc} * * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override default Double getValue() { return Double.valueOf(getDoubleValue()); } /**
@Override public K previous() { return i.previous().getKey(); }; @Override
@Override public K next() { return i.next().getKey(); }; @Override