public Value get(Key key) { if (key == null) throw new NullPointerException(); for (Node x = first; x != null; x = x.next) { if (key.equals(x.key)) return x.val; } return null; }
/** * Sets a custom option. Any existing value for the key is overwritten. * * @param key The option key * @param value The option value. */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1869") public <T> CallOptions withOption(Key<T> key, T value) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(value); CallOptions newOptions = new CallOptions(this); int existingIdx = -1; for (int i = 0; i < customOptions.length; i++) { if (key.equals(customOptions[i][0])) { existingIdx = i; break; } } newOptions.customOptions = new Object[customOptions.length + (existingIdx == -1 ? 1 : 0)][2]; System.arraycopy(customOptions, 0, newOptions.customOptions, 0, customOptions.length); if (existingIdx == -1) { // Add a new option newOptions.customOptions[customOptions.length] = new Object[] {key, value}; } else { // Replace an existing option newOptions.customOptions[existingIdx][1] = value; } return newOptions; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof NodeInfo)) { return false; } NodeInfo other = (NodeInfo) obj; if (mKey == null) { if (other.mKey != null) { return false; } } else if (!mKey.equals(other.mKey)) { return false; } if (mSocketAddress == null) { if (other.mSocketAddress != null) { return false; } } else if (!mSocketAddress.equals(other.mSocketAddress)) { return false; } return true; }
// delete the key (and associated value) from the symbol table public void delete(Key key) { if (!contains(key)) return; // find position i of key int i = hash(key); while (!key.equals(keys[i])) { i = (i + 1) % M; } // delete key and associated value keys[i] = null; vals[i] = null; // rehash all keys in same cluster i = (i + 1) % M; while (keys[i] != null) { // delete keys[i] an vals[i] and reinsert Key keyToRehash = keys[i]; Value valToRehash = vals[i]; keys[i] = null; vals[i] = null; N--; put(keyToRehash, valToRehash); i = (i + 1) % M; } N--; // halves size of array if it's 12.5% full or less if (N > 0 && N <= M / 8) resize(M / 2); assert check(); }
// delete key in linked list beginning at Node x // warning: function call stack too large if table is large private Node delete(Node x, Key key) { if (x == null) return null; if (key.equals(x.key)) { N--; return x.next; } x.next = delete(x.next, key); return x; }
@Override public Value get(Key key) { if (cachedIndex != -1 && key.equals(keys[cachedIndex])) return values[cachedIndex]; int k = rank(key); if (k < N && keys[k].equals(key)) { cachedIndex = k; return values[k]; } else return null; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; UserConsentRoleEntity that = (UserConsentRoleEntity) o; Key myKey = new Key(this.userConsent, this.roleId); Key hisKey = new Key(that.userConsent, that.roleId); return myKey.equals(hisKey); }
@Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } return key.equals(((Combination) o).key); }
private Node delete(Node x, Key key) { if (x == null) return null; if (key.equals(x.key)) { N--; // 如果键值相等,总元素数减一,然后返回x.next return x.next; } x.next = delete(x.next, key); return x; }
/** Lookup the value for a key in the context inheritance chain. */ private Object lookup(Key<?> key) { for (int i = 0; i < keyValueEntries.length; i++) { if (key.equals(keyValueEntries[i][0])) { return keyValueEntries[i][1]; } } if (parent == null) { return null; } return parent.lookup(key); }
/** * Get the value for a custom option or its inherent default. * * @param key Key identifying option */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1869") @SuppressWarnings("unchecked") public <T> T getOption(Key<T> key) { Preconditions.checkNotNull(key); for (int i = 0; i < customOptions.length; i++) { if (key.equals(customOptions[i][0])) { return (T) customOptions[i][1]; } } return key.defaultValue; }
public void loadGroupTicker( String hostname, Instant from, Instant to, OnGroupLoad groupCallback) { Key newKey = new Key(hostname, from, to); if (newKey.equals(key)) { value.replay(groupCallback); } else { key = newKey; value = new Value(); MyOnGroupLoad myOnGroupLoad = new MyOnGroupLoad(groupCallback); groupTickerLoader.loadGroupTicker(hostname, from, to, myOnGroupLoad); } }
/** * If key is in the symbol table, return the value of the key; if not, return null. * * @param key the key * @return the value associated with the given key if the key is in the symbol table. */ public Value get(Key key) { for (Node x = first; x != null; x = x.next) { if (key.equals(x.key)) return x.val; } return null; /*Node tmp = first; while (tmp != null) { if (tmp.key == key) break; else tmp = tmp.next; } if (tmp != null) return tmp.val; return null;*/ }
/** * @return breakpoints of one of the category: LINE_BREAKPOINTS, EXCEPTION_BREAKPOINTS, * FIELD_BREAKPOINTS, METHOD_BREAKPOINTS */ public <T extends Breakpoint> Breakpoint[] getBreakpoints(@NotNull final Key<T> category) { ApplicationManager.getApplication().assertIsDispatchThread(); removeInvalidBreakpoints(); final ArrayList<Breakpoint> breakpoints = new ArrayList<Breakpoint>(); for (Breakpoint breakpoint : getBreakpoints()) { if (category.equals(breakpoint.getCategory())) { breakpoints.add(breakpoint); } } return breakpoints.toArray(new Breakpoint[breakpoints.size()]); }
/** @param category breakpoint category, null if the category does not matter */ @Nullable public <T extends BreakpointWithHighlighter> T findBreakpoint( final Document document, final int offset, @Nullable final Key<T> category) { for (final Breakpoint breakpoint : getBreakpoints()) { if (breakpoint instanceof BreakpointWithHighlighter && ((BreakpointWithHighlighter) breakpoint).isAt(document, offset)) { if (category == null || category.equals(breakpoint.getCategory())) { //noinspection CastConflictsWithInstanceof,unchecked return (T) breakpoint; } } } return null; }
/** * Inserts the key-value pair into the symbol table, overwriting the old value with the new value * if the key is already in the symbol table. If the value is <tt>null</tt>, this effectively * deletes the key from the symbol table. * * @param key the key * @param val the value */ public void put(Key key, Value val) { if (val == null) { delete(key); return; } for (Node x = first; x != null; x = x.next) { if (key.equals(x.key)) { x.val = val; return; } } first = new Node(key, val, first); N++; }
/** * Inserts the specified key-value pair into the symbol table, overwriting the old value with the * new value if the symbol table already contains the specified key. Deletes the specified key * (and its associated value) from this symbol table if the specified value is <tt>null</tt>. * * @param key the key * @param val the value * @throws NullPointerException if <tt>key</tt> is <tt>null</tt> */ public void put(Key key, Value val) { if (key == null) throw new NullPointerException("first argument to put() is null"); if (val == null) { delete(key); return; } for (Node x = first; x != null; x = x.next) { if (key.equals(x.key)) { x.val = val; return; } } first = new Node(key, val, first); N++; }
@Override public void delete(Key key) { int k = 0; if (cachedIndex != -1 && key.equals(keys[cachedIndex])) { k = cachedIndex; cachedIndex = -1; } else k = rank(key); if (keys[k].equals(key)) { for (int i = k; i < N - 1; i++) { keys[i] = keys[i + 1]; values[i] = values[i + 1]; } N--; if (N < capicity / 4) resize(capicity / 2); } }
protected void validateSettings(Key changedKey, String oldValue, String newValue) { if (!areSettingsEnabled()) { return; } if (changedKey != null) { if (PREF_COMPILER_TASK_TAGS.equals(changedKey)) { fTaskTagsStatus = validateTaskTags(); } else { return; } } else { fTaskTagsStatus = validateTaskTags(); } IStatus status = fTaskTagsStatus; // StatusUtil.getMostSevere(new IStatus[] { fTaskTagsStatus }); fContext.statusChanged(status); }
private Object getChildElement(Key key, Object defaultValue) { // column and query has same name if (key.equals(this.key)) { return get(qry.getCurrentrow(), defaultValue); } // get it from undefined scope PageContext pc = ThreadLocalPageContext.get(); if (pc != null) { UndefinedImpl undefined = ((UndefinedImpl) pc.undefinedScope()); boolean old = undefined.setAllowImplicidQueryCall(false); Object sister = undefined.get(this.key, null); undefined.setAllowImplicidQueryCall(old); if (sister != null) { try { return pc.get(sister, key); } catch (PageException e) { return defaultValue; } } } return defaultValue; }
/** * Returns the value associated with the given key. * * @param key the key * @return the value associated with the given key if the key is in the symbol table and * <tt>null</tt> if the key is not in the symbol table */ public Value get(Key key) { for (Node x = first; x != null; x = x.next) { if (key.equals(x.key)) return x.val; } return null; }