X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.common%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fcommon%2Finternal%2FIGECache.java;fp=bundles%2Forg.simantics.browsing.ui.common%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fcommon%2Finternal%2FIGECache.java;h=234b265549b62072dda631f0cd03b841cc9b291e;hp=0503ba13f16771576b7ede7e738d50a1321b89e6;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/internal/IGECache.java b/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/internal/IGECache.java index 0503ba13f..234b26554 100644 --- a/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/internal/IGECache.java +++ b/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/internal/IGECache.java @@ -1,122 +1,122 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.browsing.ui.common.internal; - -import gnu.trove.set.hash.THashSet; - -import java.util.Collection; -import java.util.Set; - -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.NodeContext.CacheKey; - -public interface IGECache { - - interface IGECacheEntry { - Object getValue(); - void setValue(Object value); -// Collection getDependencies(); -// void addDependency(NodeQueryUpdater caller); - NodeContext getContext(); - CacheKey getKey(); - Collection getDependencies(); - void addDependency(IGECacheEntry caller); - void reset(); - } - - class GECacheEntry implements IGECacheEntry { - - private Object result; - final private NodeContext context; - final private CacheKey key; - private Set callers = new THashSet(2); - - public GECacheEntry(NodeContext context, CacheKey key, T result) { - this.context = context; - this.key = key; - this.result = result; - } - @Override - public Collection getDependencies() { - return callers; - } - @Override - public Object getValue() { - return result; - } - @Override - public void addDependency(IGECacheEntry caller) { - assert(caller != null); - callers.add(caller); - } - @Override - public void setValue(Object value) { - result = value; - } - @Override - public NodeContext getContext() { - return context; - } - @Override - public CacheKey getKey() { - return key; - } - @Override - public void reset() { - callers = new THashSet(2); - } - - @Override - public int hashCode() { - return 31 * context.hashCode() | key.hashCode(); - } - - @Override - public boolean equals(Object object) { - - if (this == object) - return true; - else if (object == null) - return false; - else if (getClass() != object.getClass()) - return false; - - GECacheEntry i = (GECacheEntry)object; - - return key.equals(i.key) && context.equals(i.context); - - } - -// @Override -// public String toString() { -// return "GECacheEntry[" + result + ", " + context + ", " + key + "]"; -// } - - } - - IGECacheEntry getEntry(NodeContext context, CacheKey key); - - IGECacheEntry put(NodeContext context, CacheKey key, T value); - void putTreeReference(NodeContext context, CacheKey key, UIElementReference reference); - - T get(NodeContext context, CacheKey key); - Set getTreeReference(NodeContext context, CacheKey key); - - void remove(NodeContext context, CacheKey key); - Set removeTreeReference(NodeContext context, CacheKey key); - - boolean isShown(NodeContext context); - void incRef(NodeContext context); - void decRef(NodeContext context); - - void dispose(); -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.browsing.ui.common.internal; + +import gnu.trove.set.hash.THashSet; + +import java.util.Collection; +import java.util.Set; + +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.NodeContext.CacheKey; + +public interface IGECache { + + interface IGECacheEntry { + Object getValue(); + void setValue(Object value); +// Collection getDependencies(); +// void addDependency(NodeQueryUpdater caller); + NodeContext getContext(); + CacheKey getKey(); + Collection getDependencies(); + void addDependency(IGECacheEntry caller); + void reset(); + } + + class GECacheEntry implements IGECacheEntry { + + private Object result; + final private NodeContext context; + final private CacheKey key; + private Set callers = new THashSet(2); + + public GECacheEntry(NodeContext context, CacheKey key, T result) { + this.context = context; + this.key = key; + this.result = result; + } + @Override + public Collection getDependencies() { + return callers; + } + @Override + public Object getValue() { + return result; + } + @Override + public void addDependency(IGECacheEntry caller) { + assert(caller != null); + callers.add(caller); + } + @Override + public void setValue(Object value) { + result = value; + } + @Override + public NodeContext getContext() { + return context; + } + @Override + public CacheKey getKey() { + return key; + } + @Override + public void reset() { + callers = new THashSet(2); + } + + @Override + public int hashCode() { + return 31 * context.hashCode() | key.hashCode(); + } + + @Override + public boolean equals(Object object) { + + if (this == object) + return true; + else if (object == null) + return false; + else if (getClass() != object.getClass()) + return false; + + GECacheEntry i = (GECacheEntry)object; + + return key.equals(i.key) && context.equals(i.context); + + } + +// @Override +// public String toString() { +// return "GECacheEntry[" + result + ", " + context + ", " + key + "]"; +// } + + } + + IGECacheEntry getEntry(NodeContext context, CacheKey key); + + IGECacheEntry put(NodeContext context, CacheKey key, T value); + void putTreeReference(NodeContext context, CacheKey key, UIElementReference reference); + + T get(NodeContext context, CacheKey key); + Set getTreeReference(NodeContext context, CacheKey key); + + void remove(NodeContext context, CacheKey key); + Set removeTreeReference(NodeContext context, CacheKey key); + + boolean isShown(NodeContext context); + void incRef(NodeContext context); + void decRef(NodeContext context); + + void dispose(); +}