List of usage examples for java.lang System identityHashCode
@HotSpotIntrinsicCandidate public static native int identityHashCode(Object x);
From source file:org.dhatim.smooks.scripting.groovy.GroovyContentHandlerFactory.java
private synchronized String createClassName() { StringBuilder className = new StringBuilder(); className.append("SmooksVisitor_"); className.append(System.identityHashCode(this)); className.append("_"); className.append(classGenCount++);//w w w. j a v a 2 s .com return className.toString(); }
From source file:org.apache.axis2.description.ParameterIncludeMixin.java
/** * Debug for for property key and value. * @param key/*from ww w. ja va 2 s .c om*/ * @param value */ private void debugParameterAdd(Parameter parameter) { if (log.isDebugEnabled()) { String key = parameter.getName(); Object value = parameter.getValue(); String className = (value == null) ? "null" : value.getClass().getName(); String classloader = "null"; if (value != null) { ClassLoader cl = Utils.getObjectClassLoader(value); if (cl != null) { classloader = cl.toString(); } } String valueText = (value instanceof String) ? value.toString() : null; String identity = getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(this)); log.debug("=================="); log.debug(" Parameter add on object " + identity); log.debug(" Key =" + key); if (valueText != null) { log.debug(" Value =" + valueText); } log.debug(" Value Class = " + className); log.debug(" Value Classloader = " + classloader); log.debug("Call Stack = " + JavaUtils.callStackToString()); log.debug("=================="); } }
From source file:com.afunms.common.util.logging.LogFactory.java
/** * // ww w .ja v a2 s . co m * * <p>"classname@hashcode" <code>Object.toString()</code> * <code>toString</code> </p> * * @param o <code>null<code>. * @return string <code>classname@hashcode</code> , * <code>null<code>. */ public static String objectId(Object o) { if (o == null) { return "null"; } else { return o.getClass().getName() + "@" + System.identityHashCode(o); } }
From source file:de.ailis.midi4js.Midi4JS.java
/** * Returns MIDI IN transmitter for the specified device. A transmitter must * be closed when no longer needed./*from ww w. jav a2s . c om*/ * * @param deviceHandle * The handle of the MIDI device. * @return The handle of the transmitter. * @throws MidiUnavailableException * When MIDI device is unavailable. */ public int getTransmitter(final int deviceHandle) throws MidiUnavailableException { final MidiDevice device = resolveDeviceHandle(deviceHandle); final Transmitter transmitter = device.getTransmitter(); final int transmitterHandle = System.identityHashCode(transmitter); this.transmitterMap.put(transmitterHandle, transmitter); return transmitterHandle; }
From source file:org.openqa.selenium.htmlunit.HtmlUnitDriver.java
public Set<String> getWindowHandles() { final Set<String> allHandles = new HashSet<String>(); for (final WebWindow window : webClient.getTopLevelWindows()) { allHandles.add(String.valueOf(System.identityHashCode(window))); }//from w w w . jav a2 s. com return allHandles; }
From source file:net.minecraftforge.registries.ForgeRegistry.java
int add(int id, V value, String owner) { ResourceLocation key = value == null ? null : value.getRegistryName(); Preconditions.checkNotNull(key, "Can't use a null-name for the registry, object %s.", value); Preconditions.checkNotNull(value, "Can't add null-object to the registry, name %s.", key); int idToUse = id; if (idToUse < 0 || availabilityMap.get(idToUse)) idToUse = availabilityMap.nextClearBit(min); if (idToUse > max) throw new RuntimeException(String.format("Invalid id %d - maximum id range exceeded.", idToUse)); V oldEntry = getRaw(key);/*w w w .j a va 2 s . c o m*/ if (oldEntry == value) // already registered, return prev registration's id { FMLLog.bigWarning("Registry {}: The object {} has been registered twice for the same name {}.", this.superType.getSimpleName(), value, key); return this.getID(value); } if (oldEntry != null) // duplicate name { if (!this.allowOverrides) throw new IllegalArgumentException(String .format("The name %s has been registered twice, for %s and %s.", key, getRaw(key), value)); if (owner == null) throw new IllegalStateException( String.format("Could not determine owner for the override on %s. Value: %s", key, value)); if (DEBUG) FMLLog.log.debug("Registry {} Override: {} {} -> {}", this.superType.getSimpleName(), key, oldEntry, value); idToUse = this.getID(oldEntry); } Integer foundId = this.ids.inverse().get(value); //Is this ever possible to trigger with otherThing being different? if (foundId != null) { V otherThing = this.ids.get(foundId); throw new IllegalArgumentException(String.format( "The object %s{%x} has been registered twice, using the names %s and %s. (Other object at this id is %s{%x})", value, System.identityHashCode(value), getKey(value), key, otherThing, System.identityHashCode(otherThing))); } if (isLocked()) throw new IllegalStateException( String.format("The object %s (name %s) is being added too late.", value, key)); if (defaultKey != null && defaultKey.equals(key)) { if (this.defaultValue != null) throw new IllegalStateException(String.format( "Attemped to override already set default value. This is not allowed: The object %s (name %s)", value, key)); this.defaultValue = value; } this.names.put(key, value); this.ids.put(idToUse, value); this.availabilityMap.set(idToUse); this.owners.put(new OverrideOwner(owner == null ? key.getResourceDomain() : owner, key), value); if (isDelegated) { getDelegate(value).setName(key); if (oldEntry != null) { if (!this.overrides.get(key).contains(oldEntry)) this.overrides.put(key, oldEntry); this.overrides.get(key).remove(value); if (this.stage == RegistryManager.ACTIVE) getDelegate(oldEntry).changeReference(value); } } if (this.add != null) this.add.onAdd(this, this.stage, idToUse, value, oldEntry); if (this.dummies.remove(key) && DEBUG) FMLLog.log.debug("Registry {} Dummy Remove: {}", this.superType.getSimpleName(), key); if (DEBUG) FMLLog.log.trace("Registry {} add: {} {} {} (req. id {})", this.superType.getSimpleName(), key, idToUse, value, id); return idToUse; }
From source file:org.diorite.scheduler.TaskBuilder.java
/** * @return name of task./*from w ww .ja va2 s . c o m*/ */ public String getName() { if ((this.name == null)) { return this.runnable.getClass().getName() + "@" + System.identityHashCode(this.runnable); } return this.name; }
From source file:org.openqa.selenium.htmlunit.HtmlUnitDriver.java
public String getWindowHandle() { return String.valueOf(System.identityHashCode(currentWindow.getTopWindow())); }
From source file:edu.umd.cs.eclipse.courseProjectManager.TurninProjectAction.java
public void run(IAction action) { // TODO Refactor: Should the places where we raise a dialog and return // could throw an exception instead? String timeOfSubmission = "t" + System.currentTimeMillis(); // Make sure we can get the workbench... IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench == null) { Dialogs.errorDialog(null, "Warning: project submission failed", "Could not submit project", "Internal error: Can't get workbench", IStatus.ERROR); return;/* ww w .ja v a 2s.c o m*/ } // ...and the workbenchWindow IWorkbenchWindow wwin = workbench.getActiveWorkbenchWindow(); if (wwin == null) { Dialogs.errorDialog(null, "Error submitting project", "Could not submit project", "Internal error: Can't get workbench window", IStatus.ERROR); return; } // Shell to use as parent of dialogs. Shell parent = wwin.getShell(); // Sanity check. if (!(selection instanceof IStructuredSelection)) { Dialogs.errorDialog(parent, "Warning: Selection is Invalid", "Invalid turnin action: You have selected an object that is not a Project. Please select a Project and try again.", "Object selected is not a Project", IStatus.WARNING); return; } IStructuredSelection structured = (IStructuredSelection) selection; Object obj = structured.getFirstElement(); Debug.print("Selection object is a " + obj.getClass().getName() + " @" + System.identityHashCode(obj)); IProject project; if (obj instanceof IProject) { project = (IProject) obj; } else if (obj instanceof IProjectNature) { project = ((IProjectNature) obj).getProject(); } else { Dialogs.errorDialog(null, "Warning: Selection is Invalid", "Invalid turnin action: You have selected an object that is not a Project. Please select a Project and try again.", "Object selected is not a Project", IStatus.WARNING); return; } Debug.print("Got the IProject for the turnin action @" + System.identityHashCode(project)); // ================================= save dirty editors // ======================================== // save dirty editors try { if (!saveDirtyEditors(project, workbench)) { Dialogs.errorDialog(parent, "Submit not performed", "Projects cannot be submitted unless all open files are saved", "Unsaved files prevent submission", IStatus.WARNING); return; } } catch (CoreException e) { Dialogs.errorDialog(parent, "Submit not performed", "Could not turn on cvs management for all project files", e); return; } // ========================= Add all non-ignored files in the project // ========================= IResource[] files; try { Set<IResource> resourceSet = getProjectResources(project); ArrayList<IFile> addedFiles = new ArrayList<IFile>(); for (Iterator<IResource> iter = resourceSet.iterator(); iter.hasNext();) { IResource resource = iter.next(); if (resource instanceof IFile) { IFile file = (IFile) resource; if (!AutoCVSPlugin.isCVSIgnored(file) && !AutoCVSPlugin.isCVSManaged(file)) { addedFiles.add(file); } } } files = (IResource[]) addedFiles.toArray(new IResource[addedFiles.size()]); } catch (CoreException e) { Dialogs.errorDialog(parent, "Submit not performed", "Could not perform submit; unable to find non-ignored resources", e); return; // TODO what to do here? } // ================================= perform CVS commit // ======================================== // TODO Somehow move this into the previous try block // This forces add/commit operations when AutoSync was shut off // Would it just be easier to enable autoSync and then trigger // a resource changed delta, since this method appears to enable // autoSync anyway? // String cvsStatus = "Not performed"; try { cvsStatus = forceCommit(project, files); } catch (Exception e) { Dialogs.errorDialog(parent, "CVS commit not performed as part of submission due to unexpected exception", e.getClass().getName() + " " + e.getMessage(), e); } // ================================= perform CVS tag // ======================================== try { CVSOperations.tagProject(project, timeOfSubmission, CVSOperations.SYNC); } catch (Exception e) { AutoCVSPlugin.getPlugin().getEventLog() .logError("Error tagging submission; submission via the web unlikely to work", e); } // ================================= find properties // ======================================== // find the .submitProject file IResource submitProjectFile = project.findMember(AutoCVSPlugin.SUBMITPROJECT); if (submitProjectFile == null) { Dialogs.errorDialog(parent, "Warning: Project submission not enabled", "Submission is not enabled", "There is no " + AutoCVSPlugin.SUBMITPROJECT + " file for the project", IStatus.ERROR); return; } // Get the properties from the .submit file, and the .submitUser file, // if it exists // or can be fetched from the server Properties allSubmissionProps = null; try { allSubmissionProps = getAllProperties(timeOfSubmission, parent, project, submitProjectFile); } catch (IOException e) { String message = "IOException finding " + AutoCVSPlugin.SUBMITPROJECT + " and " + AutoCVSPlugin.SUBMITUSER + " files; " + cvsStatus; AutoCVSPlugin.getPlugin().getEventLog().logError(message, e); Dialogs.errorDialog(parent, "Submission failed", message, e.getMessage(), IStatus.ERROR); Debug.print("IOException: " + e); return; } catch (CoreException e) { String message = "IOException finding " + AutoCVSPlugin.SUBMITPROJECT + " and " + AutoCVSPlugin.SUBMITUSER + " files; " + cvsStatus; AutoCVSPlugin.getPlugin().getEventLog().logError(message, e); Dialogs.errorDialog(parent, "Submission failed", message, e.getMessage(), IStatus.ERROR); Debug.print("CoreException: " + e); return; } // // THE ACTUAL SUBMIT HAPPENS HERE // try { // ============================== find files to submit // ==================================== Collection<IFile> cvsFiles = findFilesForSubmission(project); // ========================== assemble zip file in byte array // ============================== ByteArrayOutputStream bytes = new ByteArrayOutputStream(4096); ZipOutputStream zipfile = new ZipOutputStream(bytes); zipfile.setComment("zipfile for submission created by CourseProjectManager version " + AutoCVSPlugin.getPlugin().getVersion()); try { byte[] buf = new byte[4096]; for (IFile file : cvsFiles) { if (!file.exists()) { Debug.print("Resource " + file.getName() + " being ignored because it doesn't exist"); continue; } ZipEntry entry = new ZipEntry(file.getProjectRelativePath().toString()); entry.setTime(file.getModificationStamp()); zipfile.putNextEntry(entry); // Copy file data to zip file InputStream in = file.getContents(); try { while (true) { int n = in.read(buf); if (n < 0) break; zipfile.write(buf, 0, n); } } finally { in.close(); } zipfile.closeEntry(); } } catch (IOException e1) { Dialogs.errorDialog(parent, "Warning: Project submission failed", "Unable to zip files for submission\n" + cvsStatus, e1); return; } finally { if (zipfile != null) zipfile.close(); } // ============================== Post to submit server // ==================================== String version = System.getProperties().getProperty("java.runtime.version"); boolean useEasyHttps = version.startsWith("1.3") || version.startsWith("1.2") || version.startsWith("1.4.0") || version.startsWith("1.4.1") || version.startsWith("1.4.2_0") && version.charAt(7) < '5'; if (useEasyHttps) { String submitURL = allSubmissionProps.getProperty("submitURL"); if (submitURL.startsWith("https")) submitURL = "easy" + submitURL; allSubmissionProps.setProperty("submitURL", submitURL); } // prepare multipart post method MultipartPostMethod filePost = new MultipartPostMethod(allSubmissionProps.getProperty("submitURL")); // add properties addAllPropertiesButSubmitURL(allSubmissionProps, filePost); // add filepart byte[] allInput = bytes.toByteArray(); filePost.addPart(new FilePart("submittedFiles", new ByteArrayPartSource("submit.zip", allInput))); // prepare httpclient HttpClient client = new HttpClient(); client.setConnectionTimeout(5000); int status = client.executeMethod(filePost); // Piggy-back uploading the launch events onto submitting. EclipseLaunchEventLog.postEventLogToServer(project); if (status == HttpStatus.SC_OK) { Dialogs.okDialog(parent, "Project submission successful", "Project " + allSubmissionProps.getProperty("projectNumber") + " was submitted successfully\n" + filePost.getResponseBodyAsString()); } else { Dialogs.errorDialog(parent, "Warning: Project submission failed", "Project submission failed", filePost.getStatusText() + "\n " + cvsStatus, IStatus.CANCEL); AutoCVSPlugin.getPlugin().getEventLog().logMessage(filePost.getResponseBodyAsString()); } } catch (CoreException e) { Dialogs.errorDialog(parent, "Warning: Project submission failed", "Project submissions via https failed\n" + cvsStatus, e); } catch (HttpConnection.ConnectionTimeoutException e) { Dialogs.errorDialog(parent, "Warning: Project submission failed", "Project submissions failed", "Connection timeout while trying to connect to submit server\n " + cvsStatus, IStatus.ERROR); } catch (IOException e) { Dialogs.errorDialog(parent, "Warning: Project submission failed", "Project submissions failed\n " + cvsStatus, e); } }
From source file:IdentityHashMap.java
/** * Associates the specified value with the specified key in this map. * If the map previously contained a mapping for this key, the old * value is replaced./*ww w .j a v a 2s. c om*/ * * @param key key with which the specified value is to be associated. * @param value value to be associated with the specified key. * @return previous value associated with specified key, or <tt>null</tt> * if there was no mapping for key. A <tt>null</tt> return can * also indicate that the IdentityHashMap previously associated * <tt>null</tt> with the specified key. */ public Object put(Object key, Object value) { // Makes sure the key is not already in the IdentityHashMap. Entry tab[] = table; int hash = 0; int index = 0; if (key != null) { // hash = key.hashCode(); hash = System.identityHashCode(key); index = (hash & 0x7FFFFFFF) % tab.length; for (Entry e = tab[index]; e != null; e = e.next) { // if ((e.hash == hash) && key.equals(e.key)) { if ((e.hash == hash) && (key == e.key)) { Object old = e.value; e.value = value; return old; } } } else { for (Entry e = tab[0]; e != null; e = e.next) { if (e.key == null) { Object old = e.value; e.value = value; return old; } } } modCount++; if (count >= threshold) { // Rehash the table if the threshold is exceeded rehash(); tab = table; index = (hash & 0x7FFFFFFF) % tab.length; } // Creates the new entry. Entry e = new Entry(hash, key, value, tab[index]); tab[index] = e; count++; return null; }