/**
  * This function is used to re-run the analyser, and re-create the rows corresponding the its
  * results.
  */
 private void refreshReviewTable() {
   reviewPanel.removeAll();
   rows.clear();
   GridBagLayout gbl = new GridBagLayout();
   reviewPanel.setLayout(gbl);
   GridBagConstraints gbc = new GridBagConstraints();
   gbc.fill = GridBagConstraints.HORIZONTAL;
   gbc.gridy = 0;
   try {
     Map<String, Long> sums =
         analyser.processLogFile(config.getLogFilename(), fromDate.getDate(), toDate.getDate());
     for (Entry<String, Long> entry : sums.entrySet()) {
       String project = entry.getKey();
       double hours = 1.0 * entry.getValue() / (1000 * 3600);
       addRow(gbl, gbc, project, hours);
     }
     for (String project : main.getProjectsTree().getTopLevelProjects())
       if (!rows.containsKey(project)) addRow(gbl, gbc, project, 0);
     gbc.insets = new Insets(10, 0, 0, 0);
     addLeftLabel(gbl, gbc, "TOTAL");
     gbc.gridx = 1;
     gbc.weightx = 1;
     totalLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 3));
     gbl.setConstraints(totalLabel, gbc);
     reviewPanel.add(totalLabel);
     gbc.weightx = 0;
     addRightLabel(gbl, gbc);
   } catch (IOException e) {
     e.printStackTrace();
   }
   recomputeTotal();
   pack();
 }
  public static String buildContent(
      TestFile<String> file,
      String mediaType,
      List<Entry<Integer, Integer>> ranges,
      String boundary) {

    final StringBuilder content = new StringBuilder();

    for (Entry<Integer, Integer> range : ranges) {

      content.append("\n");
      content.append("--").append(boundary).append("\n");
      content.append("Content-Type: ").append(mediaType).append("\n");
      content
          .append("Content-Range: bytes ")
          .append(range.getKey())
          .append("-")
          .append(range.getValue())
          .append("/")
          .append(file.getSize())
          .append("\n");
      content.append("\n");
      content.append(file.getContent().substring(range.getKey(), range.getValue() + 1));
    }

    content.append("\n");
    content.append("--").append(boundary).append("--").append("\n");

    return content.toString();
  }
  @Override
  public boolean equals(final Object o) {
    if (o == this) {
      return true;
    }
    if (o == null) {
      return false;
    }

    if (o instanceof ImmutableOffsetMap) {
      final ImmutableOffsetMap<?, ?> om = (ImmutableOffsetMap<?, ?>) o;
      if (newKeys.isEmpty()
          && offsets == om.offsets()
          && Arrays.deepEquals(objects, om.objects())) {
        return true;
      }
    } else if (o instanceof MutableOffsetMap) {
      final MutableOffsetMap<?, ?> om = (MutableOffsetMap<?, ?>) o;
      if (offsets == om.offsets
          && Arrays.deepEquals(objects, om.objects)
          && newKeys.equals(om.newKeys)) {
        return true;
      }
    } else if (o instanceof Map) {
      final Map<?, ?> om = (Map<?, ?>) o;

      // Size and key sets have to match
      if (size() != om.size() || !keySet().equals(om.keySet())) {
        return false;
      }

      try {
        // Ensure all newKeys are present. Note newKeys is guaranteed to
        // not contain null value.
        for (Entry<K, V> e : newKeys.entrySet()) {
          if (!e.getValue().equals(om.get(e.getKey()))) {
            return false;
          }
        }

        // Ensure all objects are present
        for (Entry<K, Integer> e : offsets.entrySet()) {
          final Object obj = objects[e.getValue()];
          if (!NO_VALUE.equals(obj)) {
            final V v = objectToValue(e.getKey(), obj);
            if (!v.equals(om.get(e.getKey()))) {
              return false;
            }
          }
        }
      } catch (ClassCastException e) {
        // Can be thrown by om.get() and indicate we have incompatible key types
        return false;
      }

      return true;
    }

    return false;
  }
 @Override
 public boolean contains(final Object o) {
   if (!(o instanceof Entry<?>)) return false;
   final Entry<?> e = (Entry<?>) o;
   V val = get(e.key);
   return val == null ? e.getValue() == null : val.equals(e.getValue());
 }
Exemple #5
0
 /**
  * increments every value in the sequence by (what?).. <br>
  * you can decrement if you want to. But values below 0 will be REJECTED. As will values above 255
  *
  * @param byWhat this much!
  * @throws if you give a bogus value
  */
 public void increment(int byWhat) throws Exception {
   for (Entry e : compressedSequence) {
     e.setValue(e.getValue() + byWhat);
     if (e.getValue() > 255 || e.getValue() < 0) {
       throw new Exception("too big value");
     }
   }
 }
  @Override
  public final Map<K, V> toUnmodifiableMap() {
    if (newKeys.isEmpty() && removed == 0) {
      // Make sure next modification clones the array, as we leak it to the map we return.
      needClone = true;
      /*
       * TODO: we could track the ImmutableOffsetMap from which this one was instantiated and if we do not
       *       perform any modifications, just return the original instance. The trade-off is increased complexity
       *       and an additional field in this class.
       */
      return new ImmutableOffsetMap<>(offsets, objects);
    }

    final int s = size();
    if (s == 0) {
      return ImmutableMap.of();
    }
    if (s == 1) {
      return ImmutableMap.copyOf(this);
    }

    // Construct the set of keys
    final Collection<K> keyset = new ArrayList<>(s);
    if (removed != 0) {
      if (removed != offsets.size()) {
        for (Entry<K, Integer> e : offsets.entrySet()) {
          if (!NO_VALUE.equals(objects[e.getValue()])) {
            keyset.add(e.getKey());
          }
        }
      }
    } else {
      keyset.addAll(offsets.keySet());
    }
    keyset.addAll(newKeys.keySet());

    // Construct the values
    final Object[] values = new Object[keyset.size()];
    int i = 0;
    if (removed != 0) {
      if (removed != offsets.size()) {
        for (Entry<K, Integer> e : offsets.entrySet()) {
          final Object o = objects[e.getValue()];
          if (!NO_VALUE.equals(o)) {
            values[i++] = o;
          }
        }
      }
    } else {
      System.arraycopy(objects, 0, values, 0, offsets.size());
      i = offsets.size();
    }
    for (V v : newKeys.values()) {
      values[i++] = valueToObject(v);
    }

    return new ImmutableOffsetMap<>(OffsetMapCache.offsetsFor(keyset), values);
  }
 /**
  * Get the vertex with the maximal label.
  *
  * @param vertexLabels Map that gives a label for each vertex.
  * @return Vertex with the maximal label.
  */
 private V getMaxLabelVertex(Map<V, Integer> vertexLabels) {
   Iterator<Entry<V, Integer>> iterator = vertexLabels.entrySet().iterator();
   Entry<V, Integer> max = iterator.next();
   while (iterator.hasNext()) {
     Entry<V, Integer> e = iterator.next();
     if (e.getValue() > max.getValue()) {
       max = e;
     }
   }
   return max.getKey();
 }
 @Override
 public void putAll(Map<? extends K, ? extends V> m) {
   int m_size = m.size();
   if (m_size == 0) return;
   int max_new_size = m_size + size();
   if (array_keys == null && hashmap == null && max_new_size == 1) {
     Entry<? extends K, ? extends V> e = getFirstEntry(m);
     K key = e.getKey();
     if (key == null) throw new NullPointerException(NULL_KEY);
     singleton_key = key;
     singleton_value = e.getValue();
     return;
   }
   if (array_keys == null && hashmap == null && max_new_size <= ARRAY_SIZE) {
     if (singleton_key != null) convertSingletonToArray();
     else {
       array_keys = new Object[ARRAY_SIZE];
       array_values = new Object[ARRAY_SIZE];
       number_of_used_array_entries = 0;
     }
   }
   if (array_keys != null && max_new_size <= ARRAY_SIZE) {
     int next = 0;
     loop:
     for (Entry<? extends K, ? extends V> f : m.entrySet()) {
       K key = f.getKey();
       if (key == null) throw new NullPointerException(NULL_KEY);
       V value = f.getValue();
       for (int i = 0; i < ARRAY_SIZE; i++)
         if (array_keys[i] != null && array_keys[i].equals(key)) {
           array_values[i] = value;
           continue loop;
         }
       while (array_keys[next] != null) next++;
       array_keys[next] = key;
       array_values[next++] = value;
       number_of_used_array_entries++;
     }
     return;
   }
   for (K k : m.keySet()) if (k == null) throw new NullPointerException(NULL_KEY);
   if (array_keys != null) {
     convertArrayToHashMap();
   }
   if (hashmap == null) {
     hashmap = new HashMap<>(ARRAY_SIZE + max_new_size);
   }
   if (singleton_key != null) {
     hashmap.put(singleton_key, singleton_value);
     singleton_key = null;
     singleton_value = null;
   }
   hashmap.putAll(m);
 }
  @Override
  public Collection<V> values(Predicate predicate) {
    PagingPredicate pagingPredicate = null;
    if (predicate instanceof PagingPredicate) {
      pagingPredicate = (PagingPredicate) predicate;
      pagingPredicate.setIterationType(IterationType.VALUE);

      if (pagingPredicate.getPage() > 0 && pagingPredicate.getAnchor() == null) {
        pagingPredicate.previousPage();
        values(pagingPredicate);
        pagingPredicate.nextPage();
      }
    }
    MapQueryRequest request = new MapQueryRequest(name, predicate, IterationType.VALUE);
    QueryResultSet result = invoke(request);

    if (pagingPredicate == null) {
      final ArrayList<V> values = new ArrayList<V>(result.size());
      for (Object data : result) {
        V value = toObject(data);
        values.add(value);
      }
      return values;
    }

    List<Entry<Object, V>> valueEntryList = new ArrayList<Entry<Object, V>>(result.size());
    final Iterator<Entry> iterator = result.rawIterator();
    while (iterator.hasNext()) {
      final Entry entry = iterator.next();
      K key = toObject(entry.getKey());
      V value = toObject(entry.getValue());
      valueEntryList.add(new AbstractMap.SimpleImmutableEntry<Object, V>(key, value));
    }

    Collections.sort(
        valueEntryList,
        SortingUtil.newComparator(pagingPredicate.getComparator(), IterationType.VALUE));
    if (valueEntryList.size() > pagingPredicate.getPageSize()) {
      valueEntryList = valueEntryList.subList(0, pagingPredicate.getPageSize());
    }
    Entry anchor = null;
    if (valueEntryList.size() != 0) {
      anchor = valueEntryList.get(valueEntryList.size() - 1);
    }
    PagingPredicateAccessor.setPagingPredicateAnchor(pagingPredicate, anchor);

    final ArrayList<V> values = new ArrayList<V>(valueEntryList.size());
    for (Entry<Object, V> objectVEntry : valueEntryList) {
      values.add(objectVEntry.getValue());
    }
    return values;
  }
    @Override
    public boolean contains(final Object o) {
      if (!(o instanceof Entry)) {
        return false;
      }

      @SuppressWarnings("unchecked")
      final Entry<K, V> e = (Entry<K, V>) o;
      if (e.getValue() == null) {
        return false;
      }

      return e.getValue().equals(MutableOffsetMap.this.get(e.getKey()));
    }
 /**
  * Generates a JavaScript command to update the JavaScript agent's parameter names. Follows this
  * format: <code>agent.updateParameterNames({serial: 'XXXX', parameter: 'YYYY'});</code>
  *
  * @return A JavaScript Command.
  */
 public String generateCommand(String type, Map<String, ?> props) {
   StringBuilder buff = new StringBuilder(agentName);
   buff.append(".update").append(type).append("({");
   for (Entry<String, ?> entry : props.entrySet()) {
     if (entry.getValue() instanceof String) {
       buff.append(entry.getKey()).append(": '").append(entry.getValue()).append("',");
     } else {
       buff.append(entry.getKey()).append(": ").append(entry.getValue()).append(",");
     }
   }
   buff.deleteCharAt(buff.length() - 1);
   buff.append("});");
   return buff.toString();
 }
 /**
  * {@inheritDoc}
  *
  * <p>This implementation iterates over <tt>entrySet()</tt> searching for an entry with the
  * specified value. If such an entry is found, <tt>true</tt> is returned. If the iteration
  * terminates without finding such an entry, <tt>false</tt> is returned. Note that this
  * implementation requires linear time in the size of the map.
  *
  * @throws ClassCastException {@inheritDoc}
  * @throws NullPointerException {@inheritDoc}
  */
 public boolean containsValue(Object value) {
   Iterator<Entry<K, V>> i = entrySet().iterator();
   if (value == null) {
     while (i.hasNext()) {
       Entry<K, V> e = i.next();
       if (e.getValue() == null) return true;
     }
   } else {
     while (i.hasNext()) {
       Entry<K, V> e = i.next();
       if (value.equals(e.getValue())) return true;
     }
   }
   return false;
 }
 /**
  * {@inheritDoc}
  *
  * <p>This implementation iterates over <tt>entrySet()</tt> searching for an entry with the
  * specified key. If such an entry is found, the entry's value is returned. If the iteration
  * terminates without finding such an entry, <tt>null</tt> is returned. Note that this
  * implementation requires linear time in the size of the map; many implementations will override
  * this method.
  *
  * @throws ClassCastException {@inheritDoc}
  * @throws NullPointerException {@inheritDoc}
  */
 public V get(Object key) {
   Iterator<Entry<K, V>> i = entrySet().iterator();
   if (key == null) {
     while (i.hasNext()) {
       Entry<K, V> e = i.next();
       if (e.getKey() == null) return e.getValue();
     }
   } else {
     while (i.hasNext()) {
       Entry<K, V> e = i.next();
       if (key.equals(e.getKey())) return e.getValue();
     }
   }
   return null;
 }
 @Override
 public Map<String, Set<String>> unmarshal(List<StringSetMapAdapter.Entry> entryList)
     throws Exception {
   Map<String, Set<String>> map = new HashMap<String, Set<String>>();
   for (Entry entry : entryList) {
     if (map.containsKey(entry.getKey())) {
       map.get(entry.getKey()).add(entry.getValue());
     } else {
       Set<String> valueSet = new HashSet<String>();
       valueSet.add(entry.getValue());
       map.put(entry.getKey(), valueSet);
     }
   }
   return map;
 }
Exemple #15
0
  /**
   * Returns the string representation of this {@code Hashtable}.
   *
   * @return the string representation of this {@code Hashtable}.
   */
  @Override
  public synchronized String toString() {
    StringBuilder result = new StringBuilder(CHARS_PER_ENTRY * size);
    result.append('{');
    Iterator<Entry<K, V>> i = entrySet().iterator();
    boolean hasMore = i.hasNext();
    while (hasMore) {
      Entry<K, V> entry = i.next();

      K key = entry.getKey();
      result.append(key == this ? "(this Map)" : key.toString());

      result.append('=');

      V value = entry.getValue();
      result.append(value == this ? "(this Map)" : value.toString());

      if (hasMore = i.hasNext()) {
        result.append(", ");
      }
    }

    result.append('}');
    return result.toString();
  }
 /**
  * Copies the key/value mappings in <tt>map</tt> into this map. Note that this will be a
  * <b>deep</b> copy, as storage is by primitive value.
  *
  * @param map a <code>Map</code> value
  */
 public void putAll(Map<? extends Character, ? extends Double> map) {
   Iterator<? extends Entry<? extends Character, ? extends Double>> it = map.entrySet().iterator();
   for (int i = map.size(); i-- > 0; ) {
     Entry<? extends Character, ? extends Double> e = it.next();
     this.put(e.getKey(), e.getValue());
   }
 }
Exemple #17
0
  /**
   * Removes the fully indexed entry from the map and returns it's value.
   *
   * @param index the index in the entry data
   * @param entryIndex the index in the list of entries.
   * @return the value of the entry.
   */
  protected V removeEntry(int index, int entryIndex) {
    ++modCount;
    --size;

    Entry<K, V> entry = entryData[index].remove(entryIndex);
    return entry.getValue();
  }
 @SuppressWarnings("unchecked")
 Boolean visionallRemoveImpl(Object o) {
   if (!(o instanceof Entry<?, ?>)) {
     return false;
   }
   RootData<K, V> rootData = this.<RootData<K, V>>getRootData();
   if (rootData.isLoaded()) {
     return null;
   }
   if (!rootData.isVisionallyReadable(QueuedOperationType.DETACH)) {
     return null;
   }
   if (rootData.isLoading()) {
     throw new IllegalStateException(
         LAZY_COMMON_RESOURCE.get().visionOperationWhenDataIsBeingLoaded());
   }
   Entry<K, V> e = (Entry<K, V>) o;
   Ref<V> ref = rootData.visionallyRead(e.getKey(), null);
   if (ref != null) {
     if (ref.get() == null) {
       return false;
     }
     if (!rootData.valueUnifiedComparator().equals(ref.get(), e.getValue())) {
       return false;
     }
     rootData.visinallyRemove(e.getKey(), ref.get());
     return true;
   }
   return null;
 }
 @SuppressWarnings("unchecked")
 @Override
 public boolean containsAll(Collection<?> c, ElementMatcher<? super Entry<K, V>> matcher) {
   this.requiredEnabled();
   RootData<K, V> rootData = this.getRootData();
   if (matcher == null) {
     UnifiedComparator<? super V> valueUnifiedComparator = rootData.valueUnifiedComparator();
     for (Object o : c) {
       if (!(o instanceof Entry<?, ?>)) {
         return false;
       }
       Entry<K, V> e = (Entry<K, V>) o;
       Ref<V> ref = rootData.visionallyRead(e.getKey(), null);
       if (ref == null) {
         rootData.load();
         return this.getBase().containsAll(c, matcher);
       }
       if (ref.get() == null) {
         return false;
       }
       if (!valueUnifiedComparator.equals(ref.get(), e.getValue())) {
         return false;
       }
     }
     return true;
   }
   rootData.load();
   return this.getBase().containsAll(c, matcher);
 }
Exemple #20
0
 @Override
 public void remove(K key) {
   Entry<V> entry = this.entries.remove(key);
   if (entry != null) {
     this.factory.destroyInstance(entry.getValue());
   }
 }
  /**
   * {@inheritDoc}
   *
   * <p>This implementation first checks the structure of {@code object}. If it is not a map or of a
   * different size, this returns false. Otherwise it iterates its own entry set, looking up each
   * entry's key in {@code object}. If any value does not equal the other map's value for the same
   * key, this returns false. Otherwise it returns true.
   */
  @Override
  public boolean equals(Object object) {
    if (this == object) {
      return true;
    }
    if (object instanceof Map) {
      Map<?, ?> map = (Map<?, ?>) object;
      if (size() != map.size()) {
        return false;
      }

      try {
        for (Entry<K, V> entry : entrySet()) {
          K key = entry.getKey();
          V mine = entry.getValue();
          Object theirs = map.get(key);
          if (mine == null) {
            if (theirs != null || !map.containsKey(key)) {
              return false;
            }
          } else if (!mine.equals(theirs)) {
            return false;
          }
        }
      } catch (NullPointerException ignored) {
        return false;
      } catch (ClassCastException ignored) {
        return false;
      }
      return true;
    }
    return false;
  }
  @SuppressWarnings("unchecked")
  public boolean equals(Object o) {
    if (o == this) return true;

    if (!(o instanceof Map)) return false;
    Map<K, V> m = (Map<K, V>) o;
    if (m.size() != size()) return false;

    try {
      for (Entry<K, V> e : entrySet()) {
        K key = e.getKey();
        V value = e.getValue();
        if (value == null) {
          if (!(m.get(key) == null && m.containsKey(key))) return false;
        } else {
          if (!valueEq.equals(value, m.get(key))) return false;
        }
      }
    } catch (ClassCastException unused) {
      return false;
    } catch (NullPointerException unused) {
      return false;
    }

    return true;
  }
Exemple #23
0
  private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
    objectOutputStream.defaultWriteObject();

    if (entryData == null) {
      objectOutputStream.writeInt(0);
    } else {
      // Write the capacity and the size.
      //
      objectOutputStream.writeInt(entryData.length);
      objectOutputStream.writeInt(size);

      // Write all the entryData; there will be size of them.
      //
      for (int i = 0; i < entryData.length; ++i) {
        BasicEList<Entry<K, V>> eList = entryData[i];
        if (eList != null) {
          Object[] entries = eList.data;
          int size = eList.size;
          for (int j = 0; j < size; ++j) {
            @SuppressWarnings("unchecked")
            Entry<K, V> entry = (Entry<K, V>) entries[j];
            objectOutputStream.writeObject(entry.getKey());
            objectOutputStream.writeObject(entry.getValue());
          }
        }
      }
    }
  }
 @Override
 public Map<K, V> getAll(Set<K> keys) {
   Set<Data> keySet = new HashSet(keys.size());
   Map<K, V> result = new HashMap<K, V>();
   for (Object key : keys) {
     keySet.add(toData(key));
   }
   if (nearCache != null) {
     final Iterator<Data> iterator = keySet.iterator();
     while (iterator.hasNext()) {
       Data key = iterator.next();
       Object cached = nearCache.get(key);
       if (cached != null && !ClientNearCache.NULL_OBJECT.equals(cached)) {
         result.put((K) toObject(key), (V) cached);
         iterator.remove();
       }
     }
   }
   if (keys.isEmpty()) {
     return result;
   }
   MapGetAllRequest request = new MapGetAllRequest(name, keySet);
   MapEntrySet mapEntrySet = invoke(request);
   Set<Entry<Data, Data>> entrySet = mapEntrySet.getEntrySet();
   for (Entry<Data, Data> dataEntry : entrySet) {
     final V value = (V) toObject(dataEntry.getValue());
     final K key = (K) toObject(dataEntry.getKey());
     result.put(key, value);
     if (nearCache != null) {
       nearCache.put(dataEntry.getKey(), value);
     }
   }
   return result;
 }
  /**
   * Compares the specified object with this map for equality. Returns <tt>true</tt> if the given
   * object is also a map and the two maps represent the same mappings. More formally, two maps
   * <tt>t1</tt> and <tt>t2</tt> represent the same mappings if
   * <tt>t1.keySet().equals(t2.keySet())</tt> and for every key <tt>k</tt> in <tt>t1.keySet()</tt>,
   * <tt> (t1.get(k)==null ? t2.get(k)==null : t1.get(k).equals(t2.get(k))) </tt>. This ensures that
   * the <tt>equals</tt> method works properly across different implementations of the map
   * interface.
   *
   * <p>This implementation first checks if the specified object is this map; if so it returns
   * <tt>true</tt>. Then, it checks if the specified object is a map whose size is identical to the
   * size of this set; if not, it it returns <tt>false</tt>. If so, it iterates over this map's
   * <tt>entrySet</tt> collection, and checks that the specified map contains each mapping that this
   * map contains. If the specified map fails to contain such a mapping, <tt>false</tt> is returned.
   * If the iteration completes, <tt>true</tt> is returned.
   *
   * @param o object to be compared for equality with this map.
   * @return <tt>true</tt> if the specified object is equal to this map.
   */
  public boolean equals(Object o) {
    if (o == this) return true;

    if (!(o instanceof Map)) return false;
    Map t = (Map) o;
    if (t.size() != size()) return false;

    try {
      Iterator i = entrySet().iterator();
      while (i.hasNext()) {
        Entry e = (Entry) i.next();
        Object key = e.getKey();
        Object value = e.getValue();
        if (value == null) {
          if (!(t.get(key) == null && t.containsKey(key))) return false;
        } else {
          if (!value.equals(t.get(key))) return false;
        }
      }
    } catch (ClassCastException unused) {
      return false;
    } catch (NullPointerException unused) {
      return false;
    }

    return true;
  }
 /**
  * Copies all of the mappings from the specified map to this map (optional operation). These
  * mappings will replace any mappings that this map had for any of the keys currently in the
  * specified map.
  *
  * <p>This implementation iterates over the specified map's <tt>entrySet()</tt> collection, and
  * calls this map's <tt>put</tt> operation once for each entry returned by the iteration.
  *
  * <p>Note that this implementation throws an <tt>UnsupportedOperationException</tt> if this map
  * does not support the <tt>put</tt> operation and the specified map is nonempty.
  *
  * @param t mappings to be stored in this map.
  * @throws UnsupportedOperationException if the <tt>putAll</tt> operation is not supported by this
  *     map.
  * @throws ClassCastException if the class of a key or value in the specified map prevents it from
  *     being stored in this map.
  * @throws IllegalArgumentException if some aspect of a key or value in the specified map prevents
  *     it from being stored in this map.
  * @throws NullPointerException the specified map is <tt>null</tt>, or if this map does not permit
  *     <tt>null</tt> keys or values, and the specified map contains <tt>null</tt> keys or values.
  */
 public void putAll(Map t) {
   Iterator i = t.entrySet().iterator();
   while (i.hasNext()) {
     Entry e = (Entry) i.next();
     put(e.getKey(), e.getValue());
   }
 }
  /**
   * Compares the specified object with this map for equality. Returns <tt>true</tt> if the given
   * object is also a map and the two maps represent the same mappings. More formally, two maps
   * <tt>m1</tt> and <tt>m2</tt> represent the same mappings if
   * <tt>m1.entrySet().equals(m2.entrySet())</tt>. This ensures that the <tt>equals</tt> method
   * works properly across different implementations of the <tt>Map</tt> interface.
   *
   * <p>This implementation first checks if the specified object is this map; if so it returns
   * <tt>true</tt>. Then, it checks if the specified object is a map whose size is identical to the
   * size of this map; if not, it returns <tt>false</tt>. If so, it iterates over this map's
   * <tt>entrySet</tt> collection, and checks that the specified map contains each mapping that this
   * map contains. If the specified map fails to contain such a mapping, <tt>false</tt> is returned.
   * If the iteration completes, <tt>true</tt> is returned.
   *
   * @param o object to be compared for equality with this map
   * @return <tt>true</tt> if the specified object is equal to this map
   */
  public boolean equals(Object o) {
    if (o == this) return true;

    if (!(o instanceof Map)) return false;
    Map<K, V> m = (Map<K, V>) o;
    if (m.size() != size()) return false;

    try {
      Iterator<Entry<K, V>> i = entrySet().iterator();
      while (i.hasNext()) {
        Entry<K, V> e = i.next();
        K key = e.getKey();
        V value = e.getValue();
        if (value == null) {
          if (!(m.get(key) == null && m.containsKey(key))) return false;
        } else {
          if (!value.equals(m.get(key))) return false;
        }
      }
    } catch (ClassCastException unused) {
      return false;
    } catch (NullPointerException unused) {
      return false;
    }

    return true;
  }
  /**
   * Returns an immutable map containing the same entries as {@code map}. If {@code map} somehow
   * contains entries with duplicate keys (for example, if it is a {@code SortedMap} whose
   * comparator is not <i>consistent with equals</i>), the results of this method are undefined.
   *
   * <p>Despite the method name, this method attempts to avoid actually copying the data when it is
   * safe to do so. The exact circumstances under which a copy will or will not be performed are
   * undocumented and subject to change.
   *
   * @throws NullPointerException if any key or value in {@code map} is null
   */
  public static <K, V> ImmutableMap<K, V> copyOf(Map<? extends K, ? extends V> map) {
    if ((map instanceof ImmutableMap) && !(map instanceof ImmutableSortedMap)) {
      // TODO(user): Make ImmutableMap.copyOf(immutableBiMap) call copyOf()
      // on the ImmutableMap delegate(), rather than the bimap itself

      @SuppressWarnings("unchecked") // safe since map is not writable
      ImmutableMap<K, V> kvMap = (ImmutableMap<K, V>) map;
      if (!kvMap.isPartialView()) {
        return kvMap;
      }
    } else if (map instanceof EnumMap) {
      return copyOfEnumMapUnsafe(map);
    }
    Entry<?, ?>[] entries = map.entrySet().toArray(EMPTY_ENTRY_ARRAY);
    switch (entries.length) {
      case 0:
        return of();
      case 1:
        @SuppressWarnings("unchecked") // all entries will be Entry<K, V>'s
        Entry<K, V> onlyEntry = (Entry<K, V>) entries[0];
        return of(onlyEntry.getKey(), onlyEntry.getValue());
      default:
        return new RegularImmutableMap<K, V>(entries);
    }
  }
  @Override
  public AbstractLongList getRawNeighborhood(AtomicQuery query, InternalTitanTransaction tx) {
    Preconditions.checkArgument(
        QueryUtil.queryCoveredByDiskIndexes(query),
        "Raw retrieval is currently does not support in-memory filtering");
    List<Entry> entries = queryForEntries(query, tx.getTxHandle());

    InternalTitanVertex node = query.getNode();
    TitanType titanType = null;
    if (query.hasEdgeTypeCondition()) titanType = query.getTypeCondition();

    AbstractLongList result = new LongArrayList();

    for (Entry entry : entries) {
      if (!query.hasEdgeTypeCondition()) {
        long etid = IDHandler.readEdgeType(entry.getColumn(), idManager);
        if (titanType == null || titanType.getID() != etid) {
          titanType = getTypeFromID(etid, tx);
        }
      }
      if (titanType.isPropertyKey() || (!titanType.isModifiable() && !query.queryUnmodifiable())) {
        continue; // Skip since it does not match query
      }
      // Get neighboring node id
      long iddiff = VariableLong.read(entry.getValue());
      long nghid = iddiff + node.getID();
      result.add(nghid);

      if (result.size() >= query.getLimit()) break;
    }
    return result;
  }
Exemple #30
0
  @Nullable
  public InstanceFactory findInstanceFactory(@Nonnull Type mockedType) {
    InstanceFactory instanceFactory = mockedTypesAndInstances.get(mockedType);

    if (instanceFactory != null) {
      return instanceFactory;
    }

    Class<?> mockedClass = getClassType(mockedType);
    //noinspection ReuseOfLocalVariable
    instanceFactory = mockedTypesAndInstances.get(mockedClass);

    if (instanceFactory != null) {
      return instanceFactory;
    }

    boolean abstractType = mockedClass.isInterface() || isAbstract(mockedClass.getModifiers());

    for (Entry<Type, InstanceFactory> entry : mockedTypesAndInstances.entrySet()) {
      Type registeredMockedType = entry.getKey();
      Class<?> registeredMockedClass = getClassType(registeredMockedType);

      if (abstractType) {
        registeredMockedClass = getMockedClassOrInterfaceType(registeredMockedClass);
      }

      if (mockedClass.isAssignableFrom(registeredMockedClass)) {
        instanceFactory = entry.getValue();
        break;
      }
    }

    return instanceFactory;
  }