Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

A template / demonstration for using the "equals" method in Java.

Featured Replies

LAST UPDATE: MARCH 6, 2015

 

http://www.javapractices.com/topic/TopicAction.do?Id=17

 

Please note that many IDEs offer generators for both equals() and hashCode():

 

82a8de5e825adff1f1e0bf82982fe179.png

The Eclipse IDE.

package org.bjornkrols.templates;

/**
 * @author 		Bjorn Krols (Botre)
 * @version		0.0
 * @since		March 6, 2015
 */

 public final class EqualsAndHashCodeTemplate {

	public boolean significantBoolean;
	public int significantInteger;
	
	private EqualsAndHashCodeTemplate() {
		// This class should never be instantiated.
		// Do not delete or make accessible.
	}
	
	@Override
	public int hashCode() {
		
		// Create an int "result" and assign a non-zero value.
		int result = 17;
		
		// Create an int "prime" and assign a prime value.
		int prime = 34;
		
		/*
		For every field tested in the equals-Method, calculate a hash code c by:
		If the field f is a boolean: calculate (f ? 0 : 1);
		If the field f is a byte, char, short or int: calculate (int)f;
		If the field f is a long: calculate (int)(f ^ (f >>> 32));
		If the field f is a float: calculate Float.floatToIntBits(f);
		If the field f is a double: calculate Double.doubleToLongBits(f) and handle the return value like every long value;
		If the field f is an object: Use the result of the hashCode() method or 0 if f == null;
		If the field f is an array: See every field as separate element and calculate the hash value in a recursive fashion and combine the values as described next.
		Combine the hash value c with result with: result = prime * result + c
		*/
		result = prime * result + (significantBoolean ? 0 : 1);
		result = prime * result + significantInteger;
		 
		return result;
	}
	
	@Override
	public boolean equals(Object object) {
		
		// Optimization for true object equality.
		if (object == this) {
			return true;
		}
		
		// Check if object is an instance of this class (returns false if object is null).
		if (!(object instanceof EqualsAndHashCodeTemplate)) {
			return false;
		}
		
		// Cast object for comparison (safe).
		EqualsAndHashCodeTemplate castedObject = (EqualsAndHashCodeTemplate) object;
		
		// Check if all significant fields are equal.
		if (castedObject.significantBoolean != this.significantBoolean) {
			return false;
		}
		if (castedObject.significantInteger != this.significantInteger) {
			return false;
		}
		
		return true;
	}
	
}

Edited by Botre

  • 2 weeks later...

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.