List of usage examples for java.lang Object hashCode
@HotSpotIntrinsicCandidate public native int hashCode();
From source file:com.redhat.rhn.domain.kickstart.KickstartPackage.java
/** * {@inheritDoc}//from ww w. j av a 2 s . c o m */ public boolean equals(final Object other) { if (!(other instanceof KickstartPackage)) { return false; } KickstartPackage that = (KickstartPackage) other; return this.hashCode() == other.hashCode(); }
From source file:org.mozilla.mozstumbler.client.subactivities.DeveloperActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_developer); if (savedInstanceState == null) { FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.frame1, new KMLFragment()); ft.add(R.id.frame2, new DeveloperOptions()); ft.commit();/* w ww . j a va 2s . c o m*/ } TextView tv = (TextView) findViewById(R.id.textViewDeveloperTitle); tv.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { final AlertDialog.Builder b = new AlertDialog.Builder(DeveloperActivity.this); final String[] menuList = { "ACRA Crash Test", "Fake no motion", "Fake motion", "Battery Low", "Battery OK" }; b.setTitle("Secret testing.. shhh."); b.setItems(menuList, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (item) { case 0: Object a = null; a.hashCode(); break; case 1: LocationChangeSensor.debugSendLocationUnchanging(); break; case 2: MotionSensor.debugMotionDetected(); break; case 3: int pct = ClientPrefs.getInstance(DeveloperActivity.this).getMinBatteryPercent(); BatteryCheckReceiver.debugSendBattery(pct - 1); break; case 4: BatteryCheckReceiver.debugSendBattery(99); break; } } }); b.create().show(); return true; } }); }
From source file:edu.vt.middleware.ldap.SearchFilter.java
/** * Returns whether the supplied object contains the same data as this filter. * Delegates to {@link #hashCode()} implementation. * * @param o to compare for equality/* w ww .ja v a 2s .c o m*/ * * @return equality result */ public boolean equals(final Object o) { if (o == null) { return false; } return o == this || (getClass() == o.getClass() && o.hashCode() == hashCode()); }
From source file:org.springframework.ldap.itest.ad.SchemaToJavaAdITest.java
@Test public void verifySchemaToJavaOnAd() throws Exception { final String className = "Person"; final String packageName = "org.springframework.ldap.odm.testclasses"; File tempFile = File.createTempFile("test-odm-syntax-to-class-map", ".txt"); FileUtils.copyInputStreamToFile(new ClassPathResource("/syntax-to-class-map.txt").getInputStream(), tempFile);/*from w ww . jav a 2s. c om*/ // Add classes dir to class path - needed for compilation System.setProperty("java.class.path", System.getProperty("java.class.path") + File.pathSeparator + "target/classes"); String[] flags = new String[] { "--url", "ldaps://127.0.0.1:" + port, "--objectclasses", "organizationalperson", "--syntaxmap", tempFile.getAbsolutePath(), "--class", className, "--package", packageName, "--outputdir", tempDir, "--username", USER_DN, "--password", PASSWORD }; // Generate the code using SchemaToJava SchemaToJava.main(flags); tempFile.delete(); // Java 5 - we'll use the Java 6 Compiler API once we can drop support for Java 5. String javaDir = calculateOutputDirectory(tempDir, packageName); CompilerInterface.compile(javaDir, className + ".java"); // Java 5 // OK it compiles so lets load our new class URL[] urls = new URL[] { new File(tempDir).toURI().toURL() }; URLClassLoader ucl = new URLClassLoader(urls, getClass().getClassLoader()); Class<?> clazz = ucl.loadClass(packageName + "." + className); // Create our OdmManager using our new class OdmManagerImpl odmManager = new OdmManagerImpl(converterManager, contextSource); odmManager.addManagedClass(clazz); // And try reading from the directory using it DistinguishedName testDn = new DistinguishedName("cn=William Hartnell,cn=Users"); Object fromDirectory = odmManager.read(clazz, testDn); LOG.debug(String.format("Read - %1$s", fromDirectory)); // Check some returned values Method getDnMethod = clazz.getMethod("getDn"); Object dn = getDnMethod.invoke(fromDirectory); assertThat(dn).isEqualTo(testDn); Method getCnIteratorMethod = clazz.getMethod("getCn"); @SuppressWarnings("unchecked") String cn = (String) getCnIteratorMethod.invoke(fromDirectory); assertThat(cn).isEqualTo("William Hartnell"); Method telephoneNumberIteratorMethod = clazz.getMethod("getTelephoneNumber"); @SuppressWarnings("unchecked") String telephoneNumber = (String) telephoneNumberIteratorMethod.invoke(fromDirectory); assertThat(telephoneNumber).isEqualTo("1"); // Reread and check whether equals and hashCode are at least sane Object fromDirectory2 = odmManager.read(clazz, testDn); assertThat(fromDirectory2).isEqualTo(fromDirectory); assertThat(fromDirectory2.hashCode()).isEqualTo(fromDirectory.hashCode()); }
From source file:com.alibaba.citrus.util.internal.apache.lang.HashCodeBuilderTests.java
public void testSuper() { Object obj = new Object(); assertEquals(17 * 37 + 19 * 41 + obj.hashCode(), new HashCodeBuilder(17, 37) .appendSuper(new HashCodeBuilder(19, 41).append(obj).toHashCode()).toHashCode()); }
From source file:ObjectIntMap.java
/** * Updates the table to map 'key' to 'value'. Any existing mapping is overwritten. * * @param key mapping key [may not be null] *//* ww w .j a v a 2s . c o m*/ public void remove(final Object key) { // index into the corresponding hash bucket: final int keyHash = key.hashCode(); final int bucketIndex = (keyHash & 0x7FFFFFFF) % m_buckets.length; // traverse the singly-linked list of entries in the bucket: Entry[] buckets = m_buckets; for (Entry entry = buckets[bucketIndex], prev = entry; entry != null;) { final Entry next = entry.m_next; if ((keyHash == entry.m_key.hashCode()) || entry.m_key.equals(key)) { if (prev == entry) buckets[bucketIndex] = next; else prev.m_next = next; --m_size; break; } prev = entry; entry = next; } }
From source file:org.gachette.spi.graphprovider.collection.CollectionGraphProvider.java
private int calculateEvaluatorKey(Object object, Method method, Object[] parameters) { int hash = 1; hash = hash * 17 + object.hashCode(); hash = hash * 31 + method.hashCode(); if (parameters != null) { hash = hash * 13 + Arrays.hashCode(parameters); }//from ww w .ja va2 s . c o m return hash; }
From source file:com.netflix.suro.sink.kafka.KafkaSinkV2.java
@Override public void writeTo(MessageContainer message) { long key = msgId++; if (!keyTopicMap.isEmpty()) { try {//from ww w .java 2 s . c om Map<String, Object> msgMap = message.getEntity(new TypeReference<Map<String, Object>>() { }); Object keyField = msgMap.get(keyTopicMap.get(message.getRoutingKey())); if (keyField != null) { key = keyField.hashCode(); } } catch (Exception e) { QueuedSink.log.error("Exception on getting key field: " + e.getMessage()); } } QueuedSink.log.trace("KafkaSink writeTo()"); receivedCount.incrementAndGet(); enqueue(new SuroKeyedMessage(key, message.getMessage())); }
From source file:org.web4thejob.web.panel.base.AbstractPanel.java
@Override public boolean equals(Object obj) { if (obj == null) return false; else if (this == obj) return true; else if (!Panel.class.isInstance(obj)) return false; return hashCode() == obj.hashCode(); }
From source file:org.seansawyer.chaturanga.model.dom.DomainObjectTestCase.java
/** * Verify that the specified property, when set to the specified value, breaks the equality * between the original and modified objects' hash codes, and when the previous value is * restored, equality of hash codes is restored as well. * /* w w w. j av a 2 s . c o m*/ * @param original the original object * @param toCompare the object that will be changed for purposes of this test * @param property the property to modify * @param newValue the new value for the property being tested * @throws Exception */ protected void verifyPropertyOnHashCode(Object original, Object toCompare, String property, Object newValue) throws Exception { Object originalValue = PropertyUtils.getProperty(toCompare, property); BeanUtils.setProperty(toCompare, property, newValue); Assert.assertFalse(original.hashCode() == toCompare.hashCode()); BeanUtils.setProperty(toCompare, property, originalValue); Assert.assertTrue(original.hashCode() == toCompare.hashCode()); }