/** * Returns true if {@code pattern} equals either "*" or {@code s}. Pattern * may be {@code null}. */ private static boolean matchesNameOrWildcard(String pattern, String s) { return "*".equals(pattern) || Objects.equal(pattern, s); } }
/** * Returns true if this map contains the specified mapping. */ private boolean containsMapping(Object key, Object value) { if (key == null) { HashMapEntry<K, V> e = entryForNullKey; return e != null && Objects.equal(value, e.value); } int hash = secondaryHash(key); HashMapEntry<K, V>[] tab = table; int index = hash & (tab.length - 1); for (HashMapEntry<K, V> e = tab[index]; e != null; e = e.next) { if (e.hash == hash && key.equals(e.key)) { return Objects.equal(value, e.value); } } return false; // No entry for key }
private int indexOfAttribute(String name) { for (int i = 0; i < attributes.size(); i++) { AttrImpl attr = attributes.get(i); if (Objects.equal(name, attr.getNodeName())) { return i; } } return -1; }
/** * Serialization helper method to maintain singletons and add any new * levels. * * @return the resolved instance. */ private Object readResolve() { synchronized (levels) { for (Level level : levels) { if (value != level.value) { continue; } if (!name.equals(level.name)) { continue; } if (Objects.equal(resourceBundleName, level.resourceBundleName)) { return level; } } // This is a new value, so add it. levels.add(this); return this; } }
@Override public boolean equals(Object other) { if (other instanceof CopyOnWriteArrayList) { return this == other || Arrays.equals(elements, ((CopyOnWriteArrayList<?>) other).elements); } else if (other instanceof List) { Object[] snapshot = elements; Iterator<?> i = ((List<?>) other).iterator(); for (Object o : snapshot) { if (!i.hasNext() || !Objects.equal(o, i.next())) { return false; } } return !i.hasNext(); } else { return false; } }
/** * Compares the specified object with this {@code Identity} for equality and * returns {@code true} if the specified object is equal, {@code false} * otherwise. {@code Identity} objects are considered equal, if they have * the same name and are in the same scope. * * @param obj * object to be compared for equality with this {@code * Identity}. * @return {@code true} if the specified object is equal to this {@code * Identity}, otherwise {@code false}. */ @Override public final boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Identity)) { return false; } Identity i = (Identity) obj; if (Objects.equal(name, i.name) && (Objects.equal(scope, i.scope))) { return true; } return identityEquals(i); }
/** * Returns this map's entry that has the same key and value as {@code * entry}, or null if this map has no such entry. * * <p>This method uses the comparator for key equality rather than {@code * equals}. If this map's comparator isn't consistent with equals (such as * {@code String.CASE_INSENSITIVE_ORDER}), then {@code remove()} and {@code * contains()} will violate the collections API. */ Node<K, V> findByEntry(Entry<?, ?> entry) { Node<K, V> mine = findByObject(entry.getKey()); boolean valuesEqual = mine != null && Objects.equal(mine.value, entry.getValue()); return valuesEqual ? mine : null; }
/** * Returns the subscribers to be notified when {@code propertyName} changes. * This includes both listeners subscribed to all property changes and * listeners subscribed to the named property only. */ public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) { List<PropertyChangeListener> result = new ArrayList<PropertyChangeListener>(); for (PropertyChangeListener p : listeners) { if (p instanceof PropertyChangeListenerProxy && Objects.equal( propertyName, ((PropertyChangeListenerProxy) p).getPropertyName())) { result.add(p); } } return result.toArray(new PropertyChangeListener[result.size()]); }
/** * Returns true if {@code a} and {@code b} have the same protocol, host, * port and file. */ protected boolean sameFile(URL a, URL b) { return Objects.equal(a.getProtocol(), b.getProtocol()) && hostsEqual(a, b) && a.getEffectivePort() == b.getEffectivePort() && Objects.equal(a.getFile(), b.getFile()); } }
/** * Returns true if {@code object} is a cookie with the same domain, name and * path. Domain and name use case-insensitive comparison; path uses a * case-sensitive comparison. */ @Override public boolean equals(Object object) { if (object == this) { return true; } if (object instanceof HttpCookie) { HttpCookie that = (HttpCookie) object; return name.equalsIgnoreCase(that.getName()) && (domain != null ? domain.equalsIgnoreCase(that.domain) : that.domain == null) && Objects.equal(path, that.path); } return false; }
/** * Returns true if there are listeners registered to the property with the * given name. * * @param propertyName * the name of the property * @return true if there are listeners registered to that property, false * otherwise. */ public boolean hasListeners(String propertyName) { for (PropertyChangeListener p : listeners) { if (!(p instanceof PropertyChangeListenerProxy) || Objects.equal( propertyName, ((PropertyChangeListenerProxy) p).getPropertyName())) { return true; } } return false; }
/** * Publishes a property change event to all listeners of that property. If * the event's old and new values are equal (but non-null), no event will be * published. */ public void firePropertyChange(PropertyChangeEvent event) { String propertyName = event.getPropertyName(); Object oldValue = event.getOldValue(); Object newValue = event.getNewValue(); if (newValue != null && oldValue != null && newValue.equals(oldValue)) { return; } notifyEachListener: for (PropertyChangeListener p : listeners) { // unwrap listener proxies until we get a mismatched name or the real listener while (p instanceof PropertyChangeListenerProxy) { PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy) p; if (!Objects.equal(proxy.getPropertyName(), propertyName)) { continue notifyEachListener; } p = (PropertyChangeListener) proxy.getListener(); } p.propertyChange(event); } } }
@Override public void getSequenceLength(ASN1Sequence sequence) { ASN1Type[] type = sequence.type; Object[] values = new Object[type.length]; int[] compLens = new int[type.length]; sequence.getValues(content, values); push(compLens, values); int seqLen = 0; for (int i = 0; i < type.length; i++) { // check optional types if (values[i] == null) { if (sequence.OPTIONAL[i]) { continue; } else { throw new RuntimeException();//FIXME type & message } } if (Objects.equal(sequence.DEFAULT[i], values[i])) { values[i] = null; continue; } content = values[i]; type[i].setEncodingContent(this); compLens[i] = length; // in case if we get content bytes while getting its length // FIXME what about remove it: need redesign values[i] = content; seqLen += type[i].getEncodedLength(this); } length = seqLen; }