/** * Get parent context-path that consists of all the contexts of this path * except the last one. */ public TokenContextPath getParent() { if (parent == null && contexts.length > 1) { TokenContext[] parentContexts = new TokenContext[contexts.length - 1]; System.arraycopy(contexts, 0, parentContexts, 0, contexts.length - 1); parent = get(parentContexts); } return parent; }
/** Get the context path for this token-context that is derived * from the path of one of the children. */ public TokenContextPath getContextPath(TokenContextPath childPath) { if (childPath == null) { return contextPath; } TokenContextPath[] lastPair = lastContextPathPair; if (lastPair == null || lastPair[0] != childPath) { synchronized (pathCache) { lastPair = (TokenContextPath[])pathCache.get(childPath); if (lastPair == null) { // Build the array of contexts TokenContext[] origContexts = childPath.getContexts(); TokenContext[] contexts = new TokenContext[origContexts.length + 1]; System.arraycopy(origContexts, 0, contexts, 0, origContexts.length); contexts[origContexts.length] = this; TokenContextPath path = TokenContextPath.get(contexts); lastPair = new TokenContextPath[] { childPath, path }; pathCache.put(childPath, lastPair); } lastContextPathPair = lastPair; } } return lastPair[1]; }
/** * Get the context path for this token-context that is derived from the path * of one of the children. */ public TokenContextPath getContextPath(TokenContextPath childPath) { if (childPath == null) { return contextPath; } TokenContextPath[] lastPair = lastContextPathPair; if (lastPair == null || lastPair[0] != childPath) { synchronized (pathCache) { lastPair = (TokenContextPath[]) pathCache.get(childPath); if (lastPair == null) { // Build the array of contexts TokenContext[] origContexts = childPath.getContexts(); TokenContext[] contexts = new TokenContext[origContexts.length + 1]; System.arraycopy(origContexts, 0, contexts, 0, origContexts.length); contexts[origContexts.length] = this; TokenContextPath path = TokenContextPath.get(contexts); lastPair = new TokenContextPath[] { childPath, path }; pathCache.put(childPath, lastPair); } lastContextPathPair = lastPair; } } return lastPair[1]; }
/** Get parent context-path that consists of all the contexts * of this path except the last one. */ public TokenContextPath getParent() { if (parent == null && contexts.length > 1) { TokenContext[] parentContexts = new TokenContext[contexts.length - 1]; System.arraycopy(contexts, 0, parentContexts, 0, contexts.length - 1); parent = get(parentContexts); } return parent; }
/** Construct new token-context. * @param namePrefix name that will prefix all the token-ids names. * @param children child token contexts. */ public TokenContext(String namePrefix, TokenContext[] children) { if (namePrefix == null) { throw new IllegalArgumentException("Name prefix must be non-null."); // NOI18N } this.namePrefix = namePrefix.intern(); this.children = (children != null) ? children : EMPTY_CHILDREN; contextPath = TokenContextPath.get(new TokenContext[] { this }); }
/** * Construct new token-context. * * @param namePrefix * name that will prefix all the token-ids names. * @param children * child token contexts. */ public TokenContext(String namePrefix, TokenContext[] children) { if (namePrefix == null) { throw new IllegalArgumentException("Name prefix must be non-null."); } this.namePrefix = namePrefix.intern(); this.children = (children != null) ? children : EMPTY_CHILDREN; contextPath = TokenContextPath.get(new TokenContext[] { this }); }
/** Get the path which has the initial part of the path * (usually only the base path) replaced by the given path. The length * of the replaced part of the path is the same as the length * of the path that will replace it. * For better performance the method caches the [byPath, result-path] * in hashmap. * @param byPath path that will replace the initial portion * of this path. The length of the portion is the same as the length * of this parameter. * @return the path with the initial part being replaced. */ public TokenContextPath replaceStart(TokenContextPath byPath) { // Check whether byPath isn't longer than this path if (contexts.length < byPath.contexts.length) { throw new IllegalArgumentException("byPath=" + byPath + " is too long."); // NOI18N } synchronized (replaceStartCache) { TokenContextPath ret = (TokenContextPath)replaceStartCache.get(byPath); if (ret == null) { TokenContext[] targetContexts = (TokenContext[])contexts.clone(); for (int i = byPath.contexts.length - 1; i >= 0; i--) { targetContexts[i] = byPath.contexts[i]; } ret = get(targetContexts); replaceStartCache.put(byPath, ret); } return ret; } }
targetContexts[i] = byPath.contexts[i]; ret = get(targetContexts); replaceStartCache.put(byPath, ret);