Java Code Examples for com.intellij.openapi.util.Key.hashCode()

The following are Jave code examples for showing how to use hashCode() of the com.intellij.openapi.util.Key class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: intellij-ce-playground   File: MapBackedFMap.java   Source Code and License Vote up 6 votes
@NotNull
@Override
public KeyFMap minus(@NotNull Key<?> key) {
  int oldSize = size();
  int keyCode = key.hashCode();
  if (!containsKey(keyCode)) {
    return this;
  }
  if (oldSize == ArrayBackedFMap.ARRAY_THRESHOLD + 1) {
    int[] keys = keys();
    Object[] values = getValues();
    int i = ArrayUtil.indexOf(keys, keyCode);
    keys = ArrayUtil.remove(keys, i);
    values = ArrayUtil.remove(values, i);
    return new ArrayBackedFMap(keys, values);
  }
  return new MapBackedFMap(this, keyCode);
}
 
Example 2
Project: intellij-ce-playground   File: ArrayBackedFMap.java   Source Code and License Vote up 6 votes
@NotNull
@Override
public KeyFMap minus(@NotNull Key<?> key) {
  int oldSize = size();
  int keyCode = key.hashCode();
  for (int i = 0; i< oldSize; i++) {
    int oldKey = keys[i];
    if (keyCode == oldKey) {
      if (oldSize == 3) {
        int i1 = (2-i)/2;
        int i2 = 3 - (i+2)/2;
        Key<Object> key1 = Key.getKeyByIndex(keys[i1]);
        Key<Object> key2 = Key.getKeyByIndex(keys[i2]);
        if (key1 == null && key2 == null) return EMPTY_MAP;
        if (key1 == null) return new OneElementFMap<Object>(key2, values[i2]);
        if (key2 == null) return new OneElementFMap<Object>(key1, values[i1]);
        return new PairElementsFMap(key1, values[i1], key2, values[i2]);
      }
      int[] newKeys = ArrayUtil.remove(keys, i);
      Object[] newValues = ArrayUtil.remove(values, i, ArrayUtil.OBJECT_ARRAY_FACTORY);
      return new ArrayBackedFMap(newKeys, newValues);
    }
  }
  return this;
}
 
Example 3
Project: intellij-ce-playground   File: PairElementsFMap.java   Source Code and License Vote up 5 votes
@NotNull
@Override
public <V> KeyFMap plus(@NotNull Key<V> key, @NotNull V value) {
  if (key == key1) return new PairElementsFMap(key, value, key2, value2);
  if (key == key2) return new PairElementsFMap(key, value, key1, value1);
  return new ArrayBackedFMap(new int[]{key1.hashCode(), key2.hashCode(), key.hashCode()}, new Object[]{value1, value2, value});
}
 
Example 4
Project: intellij-ce-playground   File: ArrayBackedFMap.java   Source Code and License Vote up 5 votes
@NotNull
@Override
public <V> KeyFMap plus(@NotNull Key<V> key, @NotNull V value) {
  int oldSize = size();
  int keyCode = key.hashCode();
  int[] newKeys = null;
  Object[] newValues = null;
  int i;
  for (i = 0; i < oldSize; i++) {
    int oldKey = keys[i];
    if (keyCode == oldKey) {
      if (value == values[i]) return this;
      newKeys = new int[oldSize];
      newValues = new Object[oldSize];
      System.arraycopy(keys, 0, newKeys, 0, oldSize);
      System.arraycopy(values, 0, newValues, 0, oldSize);
      newValues[i] = value;
      break;
    }
  }
  if (i == oldSize) {
    if (oldSize == ARRAY_THRESHOLD) {
      return new MapBackedFMap(keys, keyCode, values, value);
    }
    newKeys = ArrayUtil.append(keys, keyCode);
    newValues = ArrayUtil.append(values, value, ArrayUtil.OBJECT_ARRAY_FACTORY);
  }
  return new ArrayBackedFMap(newKeys, newValues);
}
 
Example 5
Project: intellij-ce-playground   File: ArrayBackedFMap.java   Source Code and License Vote up 5 votes
@Override
public <V> V get(@NotNull Key<V> key) {
  int oldSize = size();
  int keyCode = key.hashCode();
  for (int i = 0; i < oldSize; i++) {
    int oldKey = keys[i];
    if (keyCode == oldKey) {
      //noinspection unchecked
      return (V)values[i];
    }
  }
  return null;
}