Example usage for java.lang Object hashCode

List of usage examples for java.lang Object hashCode

Introduction

In this page you can find the example usage for java.lang Object hashCode.

Prototype

@HotSpotIntrinsicCandidate
public native int hashCode();

Source Link

Document

Returns a hash code value for the object.

Usage

From source file:org.jabsorb.ng.JSONRPCBridge.java

/**
 * Registers an object to export all instance methods and static methods.
 * <p/>/*  www .ja v a 2s  .  c  om*/
 * The JSONBridge will export all instance methods and static methods of the
 * particular object under the name passed in as a key.
 * <p/>
 * This will make available all methods of the object as
 * <code>&lt;key&gt;.&lt;methodnames&gt;</code> to JSON-RPC clients.
 * <p/>
 * Calling registerObject for a name that already exists will replace the
 * existing entry.
 * 
 * @param key
 *            The named prefix to export the object as
 * @param o
 *            The object instance to be called upon
 */
public void registerObject(final Object key, final Object o) {

    final ObjectInstance oi = new ObjectInstance(o);
    synchronized (objectMap) {
        objectMap.put(key, oi);
    }
    if (log.isDebugEnabled()) {
        log.debug("registerObject",
                "registered object " + o.hashCode() + " of class " + o.getClass().getName() + " as " + key);
    }
}

From source file:org.jabsorb.ng.JSONRPCBridge.java

/**
 * Registers an object to export all instance methods defined by
 * interfaceClass./* ww  w  .j a v a 2  s  .com*/
 * <p/>
 * The JSONBridge will export all instance methods defined by interfaceClass
 * of the particular object under the name passed in as a key.
 * <p/>
 * This will make available these methods of the object as
 * <code>&lt;key&gt;.&lt;methodnames&gt;</code> to JSON-RPC clients.
 * 
 * @param key
 *            The named prefix to export the object as
 * @param o
 *            The object instance to be called upon
 * @param interfaceClass
 *            The type that this object should be registered as.
 *            <p/>
 *            This can be used to restrict the exported methods to the
 *            methods defined in a specific superclass or interface.
 */
public void registerObject(final Object key, final Object o, final Class<?> interfaceClass) {

    final ObjectInstance oi = new ObjectInstance(o, interfaceClass);
    synchronized (objectMap) {
        objectMap.put(key, oi);
    }
    if (log.isDebugEnabled()) {
        log.debug("registerObject",
                "registered object " + o.hashCode() + " of class " + interfaceClass.getName() + " as " + key);
    }
}

From source file:org.springframework.ldap.odm.test.TestSchemaToJava.java

@Test
public void generate() 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  ww w.j a v a 2  s  .com*/

    // 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", "ldap://127.0.0.1:" + port, "--objectclasses",
            "organizationalperson", "--syntaxmap", tempFile.getAbsolutePath(), "--class", className,
            "--package", packageName, "--outputdir", tempDir };

    // 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
    LdapName testDn = LdapUtils.newLdapName(baseName);
    testDn.addAll(LdapUtils.newLdapName("cn=William Hartnell,ou=Doctors"));
    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);
    assertEquals(testDn, dn);

    Method getCnIteratorMethod = clazz.getMethod("getCnIterator");
    @SuppressWarnings("unchecked")
    Iterator<String> cnIterator = (Iterator<String>) getCnIteratorMethod.invoke(fromDirectory);
    int cnCount = 0;
    while (cnIterator.hasNext()) {
        cnCount++;
        assertEquals("William Hartnell", cnIterator.next());
    }
    assertEquals(1, cnCount);

    Method telephoneNumberIteratorMethod = clazz.getMethod("getTelephoneNumberIterator");
    @SuppressWarnings("unchecked")
    Iterator<Integer> telephoneNumberIterator = (Iterator<Integer>) telephoneNumberIteratorMethod
            .invoke(fromDirectory);
    int telephoneNumberCount = 0;
    while (telephoneNumberIterator.hasNext()) {
        telephoneNumberCount++;
        assertEquals(Integer.valueOf(1), telephoneNumberIterator.next());
    }
    assertEquals(1, telephoneNumberCount);

    // Reread and check whether equals and hashCode are at least sane
    Object fromDirectory2 = odmManager.read(clazz, testDn);
    assertEquals(fromDirectory, fromDirectory2);
    assertEquals(fromDirectory.hashCode(), fromDirectory2.hashCode());
}

From source file:iristk.flow.FlowCompiler.java

private void printEventTriggers(List<?> triggers) throws FlowCompilerException {
    code.println("@Override");
    code.println("public int onFlowEvent(Event event) throws Exception {");
    code.println("int eventResult;");
    code.println("int count;");
    for (Object trigger : triggers) {
        if (trigger instanceof Onevent) {
            printLocation(trigger);/*w w w .jav  a 2 s . c  om*/
            code.println("try {");
            code.println("count = getCount(" + trigger.hashCode() + ") + 1;");
            Onevent onEventElem = (Onevent) trigger;
            if (onEventElem.getName() != null)
                code.println("if (event.triggers(\"" + onEventElem.getName() + "\")) {");
            if (onEventElem.getCond() != null)
                code.println("if (" + formatCondExpr(onEventElem.getCond()) + ") {");

            code.println("incrCount(" + trigger.hashCode() + ");");

            code.println("eventResult = EVENT_CONSUMED;");
            code.println("EXECUTION: {");
            printActions(onEventElem.getAny(), trigger, null);
            code.println("}");
            code.println("if (eventResult != EVENT_IGNORED) return eventResult;");

            //for (int i = 0; i < onEventElem.getOtherAttributes().keySet().size(); i++) 
            //   code.println("}");
            if (onEventElem.getCond() != null)
                code.println("}");
            if (onEventElem.getName() != null)
                code.println("}");
            code.println("} catch (Exception e) {");
            code.println("throw new FlowException(e, currentState, event, "
                    + location(flowXml.getLocation(trigger)) + ");");
            code.println("}");

        } else if (trigger instanceof Ontime) {
            printLocation(trigger);
            Ontime onTimeElem = (Ontime) trigger;
            code.println("count = getCount(" + trigger.hashCode() + ") + 1;");
            code.println("if (event.triggers(\"timer_" + trigger.hashCode() + "\")) {");
            code.println("incrCount(" + trigger.hashCode() + ");");
            code.println("eventResult = EVENT_CONSUMED;");
            code.println("EXECUTION: {");
            printActions(onTimeElem.getAny(), trigger, null);
            code.println("}");
            code.println("if (eventResult != EVENT_IGNORED) return eventResult;");
            code.println("}");
        }
    }
    code.println("eventResult = super.onFlowEvent(event);");
    code.println("if (eventResult != EVENT_IGNORED) return eventResult;");
    code.println("eventResult = callerHandlers(event);");
    code.println("if (eventResult != EVENT_IGNORED) return eventResult;");
    code.println("return EVENT_IGNORED;");
    code.println("}");
}

From source file:ConcurrentReferenceHashMap.java

private int hashOf(Object key) {
    return hash(identityComparisons ? System.identityHashCode(key) : key.hashCode());
}

From source file:org.pwsafe.passwordsafeswt.PasswordSafeJFace.java

protected void addTreeView(final Composite aComposite) {
    treeViewer = new TreeViewer(aComposite, SWT.BORDER);
    treeViewer.setLabelProvider(new PasswordTreeLabelProvider());
    treeViewer.setContentProvider(new PasswordTreeContentProvider());
    treeViewer.setSorter(new ViewerSorter());
    treeViewer.addDoubleClickListener(new ViewerDoubleClickListener());
    final int operations = DND.DROP_COPY | DND.DROP_MOVE;
    final Transfer[] transferTypes = new Transfer[] { PwsEntryBeanTransfer.getInstance(),
            TextTransfer.getInstance() };
    treeViewer.addDragSupport(operations, transferTypes, new TreeDragListener(treeViewer));
    treeViewer.addDropSupport(operations, transferTypes, new TreeDropper(treeViewer));
    treeViewer.setComparer(new IElementComparer() {
        public boolean equals(final Object a, final Object b) {
            if (a instanceof PwsEntryBean && b instanceof PwsEntryBean)
                return ((PwsEntryBean) a).getStoreIndex() == (((PwsEntryBean) b).getStoreIndex());
            else//from   w  ww.ja  v  a  2s  .  c o  m
                return a.equals(b);
        }

        public int hashCode(final Object element) {
            if (element instanceof PwsEntryBean)
                return ((PwsEntryBean) element).getStoreIndex();
            else
                return element.hashCode();
        }
    });
    tree = treeViewer.getTree();
    tree.setHeaderVisible(true);
    tree.setMenu(createPopupMenu(tree));

    treeViewer.setInput(new Object());
    viewer = treeViewer;

    int column = 1;
    addTreeColumn(column, "PasswordSafeJFace.Column.Title", "tree/title");//$NON-NLS-1$

    column++;
    addTreeColumn(column, "PasswordSafeJFace.Column.UserName", "tree/userName");//$NON-NLS-1$

    final IPreferenceStore thePrefs = JFacePreferences.getPreferenceStore();
    if (thePrefs.getBoolean(JpwPreferenceConstants.SHOW_NOTES_IN_LIST)) {
        column++;
        addTreeColumn(column, "PasswordSafeJFace.Column.Notes", "tree/notes");//$NON-NLS-1$
    }

    final TreeColumn[] columns = tree.getColumns();
    for (int i = 0; i < columns.length; i++) {
        // ps.getDefaultInt("bla");
        // columns[i].setWidth(100);
        columns[i].setMoveable(true);
    }
    // treeViewer.setExpandedState(arg0, arg1)

}

From source file:eu.aniketos.spdm.ds.impl.BidiMultiHashMap.java

/**
 * Gets the hash code for the object specified. This implementation uses the
 * additional hashing routine from JDK1.4. Subclasses can override this to
 * return alternate hash codes.// w  ww . j a v a2s.  co m
 * 
 * @param obj
 *            the object to get a hash code for
 * @return the hash code
 */
protected int hash(Object obj) {
    // same as JDK 1.4
    int h = obj.hashCode();
    h += ~(h << 9);
    h ^= (h >>> 14);
    h += (h << 4);
    h ^= (h >>> 10);
    return h;
}

From source file:iristk.flow.FlowCompiler.java

private void printOnEntry(List<?> eventHandlers) throws FlowCompilerException {
    for (Object trigger : eventHandlers) {
        if (trigger instanceof Ontime) {
            String afterentry = ((Ontime) trigger).getAfterentry();
            if (afterentry != null) {
                code.println("iristk.util.DelayedEvent timer_" + trigger.hashCode() + ";");
            }/*from   w  w w. j ava 2  s.c  o m*/
        }
    }

    code.println("@Override");
    code.println("public void onentry() throws Exception {");
    code.println("int eventResult;");
    code.println("Event event = new Event(\"state.enter\");");

    for (Object trigger : eventHandlers) {
        if (trigger instanceof Ontime) {
            String afterentry = ((Ontime) trigger).getAfterentry();
            if (afterentry != null) {
                code.println("if (timer_" + trigger.hashCode() + " != null) timer_" + trigger.hashCode()
                        + ".forget();");
                code.println("timer_" + trigger.hashCode() + " = flowThread.raiseEvent(new Event(\"timer_"
                        + trigger.hashCode() + "\"), " + formatAttrExpr(afterentry)
                        + ", new FlowEventInfo(currentState, event, " + location(flowXml.getLocation(trigger))
                        + "));");
                code.println("forgetOnExit(timer_" + trigger.hashCode() + ");");
            }
        }
    }

    for (Object eventHandler : eventHandlers) {
        if (eventHandler instanceof Onentry) {
            printLocation(eventHandler);
            Onentry onentry = (Onentry) eventHandler;
            code.println("try {");
            code.println("EXECUTION: {");
            code.println("int count = getCount(" + eventHandler.hashCode() + ") + 1;");
            code.println("incrCount(" + eventHandler.hashCode() + ");");
            printActions(onentry.getAny(), onentry, null);
            code.println("}");
            code.println("} catch (Exception e) {");
            code.println("throw new FlowException(e, currentState, event, "
                    + location(flowXml.getLocation(onentry)) + ");");
            code.println("}");
            break;
        }
    }

    code.println("}");
    return;
}

From source file:org.jgap.Configuration.java

/**
 * @param a_obj the object to make a key for, must not be null
 * @return key produced for the object (hashCode() is used, so it should be
 * implemented properly!)//from  www. j a v  a2 s. co  m
 *
 * @author Klaus Meffert
 * @since 3.0
 */
protected String makeKey(final Object a_obj) {
    String key = String.valueOf(a_obj.hashCode()) + a_obj.getClass().getName();
    return key;
}

From source file:org.executequery.databaseobjects.impl.DelegatingResultSet.java

public int hashCode() {
    Object obj = getInnermostDelegate();
    if (obj == null) {
        return 0;
    }//from ww w  . j a  v  a2  s .c  o m
    return obj.hashCode();
}