add method

Add a context to the cache and return it. If the context already exists, return that one instead and do not add a new context to the cache. Protect shared cache from unsafe thread access.

Implementation

PredictionContext add(PredictionContext ctx) {
  if (ctx == EmptyPredictionContext.Instance) return EmptyPredictionContext.Instance;
  final existing = cache[ctx];
  if (existing != null) {
//			System.out.println(name+" reuses "+existing);
    return existing;
  }
  cache[ctx] = ctx;
  return ctx;
}