[common] Fixed some bugs detected by fb, removed obsolete SuppressWarn

This commit is contained in:
Dennis Huebner 2012-02-29 17:26:36 +01:00
parent 6fadbb2109
commit 08be34013d
3 changed files with 15 additions and 11 deletions

View file

@ -204,11 +204,13 @@ public abstract class GraphvizDotBuilder {
protected String id(Object cls) {
if (cls == null)
return null;
// Math.abs(Integer.MIN_VALUE) returns Integer.MIN_VALUE
long safeAbsInt = Math.abs(Long.valueOf(cls.hashCode()));
if (cls instanceof EPackage)
return "cluster" + Math.abs(cls.hashCode());
return "cluster" + safeAbsInt;
if (cls instanceof EObject)
return ((EObject) cls).eClass().getName().toLowerCase() + Math.abs(cls.hashCode());
return cls.getClass().getSimpleName().toLowerCase() + Math.abs(cls.hashCode());
return ((EObject) cls).eClass().getName().toLowerCase() + safeAbsInt;
return cls.getClass().getSimpleName().toLowerCase() + safeAbsInt;
}
}

View file

@ -344,6 +344,8 @@ public class MergeableManifest extends Manifest {
@Override
public boolean equals(Object obj) {
if(obj == null)
return false;
ParameterizedElement other = (ParameterizedElement) obj;
return name.equals(other.name);
}

View file

@ -12,6 +12,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.log4j.Logger;
import org.eclipse.emf.common.notify.Notification;
@ -173,14 +174,14 @@ public class OnChangeEvictingCache implements IResourceScopeCache {
private static final Object NULL = new Object();
private Map<Object, Object> values = new ConcurrentHashMap<Object, Object>(500);
private final Map<Object, Object> values = new ConcurrentHashMap<Object, Object>(500);
private Collection<Listener> listeners = Sets.newLinkedHashSet();
private final Collection<Listener> listeners = Sets.newLinkedHashSet();
@Deprecated
private volatile boolean ignoreNotifications = false;
private volatile int ignoreNotificationCounter = 0;
private final AtomicInteger ignoreNotificationCounter = new AtomicInteger(0);
private volatile boolean empty = true;
@ -207,8 +208,7 @@ public class OnChangeEvictingCache implements IResourceScopeCache {
* @since 2.1
*/
public void listenToNotifications() {
ignoreNotificationCounter--;
if (ignoreNotificationCounter < 0) {
if (ignoreNotificationCounter.decrementAndGet() < 0) {
throw new IllegalStateException("ignoreNotificationCounter may not be less than zero");
}
}
@ -217,7 +217,7 @@ public class OnChangeEvictingCache implements IResourceScopeCache {
* @since 2.1
*/
public void ignoreNotifications() {
ignoreNotificationCounter++;
ignoreNotificationCounter.incrementAndGet();
}
/**
@ -255,7 +255,7 @@ public class OnChangeEvictingCache implements IResourceScopeCache {
@Override
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
if (ignoreNotificationCounter == 0 && !ignoreNotifications && isSemanticStateChange(notification)) {
if (ignoreNotificationCounter.get() == 0 && !ignoreNotifications && isSemanticStateChange(notification)) {
clearValues();
Iterator<Listener> iter = listeners.iterator();
while(iter.hasNext()) {
@ -298,7 +298,7 @@ public class OnChangeEvictingCache implements IResourceScopeCache {
}
public boolean isIgnoreNotifications() {
return ignoreNotificationCounter > 0 || ignoreNotifications;
return ignoreNotificationCounter.get() > 0 || ignoreNotifications;
}
private IgnoreValuesMemento ignoreNewValues() {