Example usage for java.lang String intern

List of usage examples for java.lang String intern

Introduction

In this page you can find the example usage for java.lang String intern.

Prototype

public native String intern();

Source Link

Document

Returns a canonical representation for the string object.

Usage

From source file:com.jaeksoft.searchlib.schema.SchemaField.java

public void setIndexAnalyzer(String indexAnalyzer) {
    this.indexAnalyzer = StringUtils.isEmpty(indexAnalyzer) ? null : indexAnalyzer.intern();
}

From source file:org.quartz.impl.jdbcjobstore.JTANonClusteredSemaphore.java

/**
 * Grants a lock on the identified resource to the calling thread (blocking
 * until it is available)./*from  www  . j a  v a 2 s.c om*/
 * 
 * @return true if the lock was obtained.
 */
public synchronized boolean obtainLock(Connection conn, String lockName) throws LockException {

    lockName = lockName.intern();

    Log log = getLog();

    if (log.isDebugEnabled()) {
        log.debug("Lock '" + lockName + "' is desired by: " + Thread.currentThread().getName());
    }

    if (!isLockOwner(conn, lockName)) {
        if (log.isDebugEnabled()) {
            log.debug("Lock '" + lockName + "' is being obtained: " + Thread.currentThread().getName());
        }

        while (locks.contains(lockName)) {
            try {
                this.wait();
            } catch (InterruptedException ie) {
                if (log.isDebugEnabled()) {
                    log.debug(
                            "Lock '" + lockName + "' was not obtained by: " + Thread.currentThread().getName());
                }
            }
        }

        // If we are in a transaction, register a callback to actually release
        // the lock when the transaction completes
        Transaction t = getTransaction();
        if (t != null) {
            try {
                t.registerSynchronization(new SemaphoreSynchronization(lockName));
            } catch (Exception e) {
                throw new LockException("Failed to register semaphore with Transaction.", e);
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("Lock '" + lockName + "' given to: " + Thread.currentThread().getName());
        }

        getThreadLocks().add(lockName);
        locks.add(lockName);
    } else if (log.isDebugEnabled()) {
        log.debug("Lock '" + lockName + "' already owned by: " + Thread.currentThread().getName()
                + " -- but not owner!", new Exception("stack-trace of wrongful returner"));
    }

    return true;
}

From source file:de.dfki.iui.mmds.dialogue.SiamErrorReporter.java

/**
 * @see ErrorReporter#onError(String, String, Object)
 *//*from  w ww .  jav a  2  s  . c o m*/
@Override
@SuppressWarnings("unchecked")
public void onError(final String errorCode, final String errDetail, final Object errCtx) {
    // Note: the if-then-else below is based on the actual usage
    // (codebase search), it has to be kept up-to-date as the code changes
    String errCode = errorCode.intern();
    StringBuffer msg = new StringBuffer();
    msg.append(errCode).append(" (");
    msg.append(errDetail).append("): ");
    if (errCode == ErrorConstants.NO_INITIAL) {
        if (errCtx instanceof SCXML) {
            // determineInitialStates
            msg.append("<SCXML>");
        } else if (errCtx instanceof State) {
            // determineInitialStates
            // determineTargetStates
            msg.append("State " + LogUtils.getTTPath((State) errCtx));
        }
    } else if (errCode == ErrorConstants.UNKNOWN_ACTION) {
        // executeActionList
        msg.append("Action: " + errCtx.getClass().getName());
    } else if (errCode == ErrorConstants.ILLEGAL_CONFIG)
        // isLegalConfig
        if (errCtx instanceof Map.Entry) { // unchecked cast below
            Map.Entry<TransitionTarget, Set<TransitionTarget>> badConfigMap = (Map.Entry<TransitionTarget, Set<TransitionTarget>>) errCtx;
            TransitionTarget tt = badConfigMap.getKey();
            Set<TransitionTarget> vals = badConfigMap.getValue();
            msg.append(LogUtils.getTTPath(tt) + " : [");
            for (Iterator<TransitionTarget> i = vals.iterator(); i.hasNext();) {
                TransitionTarget tx = i.next();
                msg.append(LogUtils.getTTPath(tx));
                if (i.hasNext()) {
                    msg.append(", ");
                }
            }
            msg.append(']');
        } else if (errCtx instanceof Set) { // unchecked cast below
            Set<TransitionTarget> vals = (Set<TransitionTarget>) errCtx;
            msg.append("<SCXML> : [");
            for (Iterator<TransitionTarget> i = vals.iterator(); i.hasNext();) {
                TransitionTarget tx = i.next();
                msg.append(LogUtils.getTTPath(tx));
                if (i.hasNext()) {
                    msg.append(", ");
                }
            }
            msg.append(']');
        }
    if (log.isWarnEnabled()) {
        log.warn(msg.toString());
    }
}

From source file:org.apache.axis.utils.NSStack.java

/**
 * Given a prefix, return the associated namespace (if any).
 *//*  w  w  w  . java2 s  . c  om*/
public String getNamespaceURI(String prefix) {
    if (prefix == null)
        prefix = "";

    prefix = prefix.intern();

    for (int cursor = top; cursor > 0; cursor--) {
        Mapping map = stack[cursor];
        if (map == null)
            continue;

        if (map.getPrefix() == prefix)
            return map.getNamespaceURI();
    }

    return null;
}

From source file:org.quartz.impl.jdbcjobstore.JTANonClusteredSemaphore.java

/**
 * Release the lock on the identified resource if it is held by the calling
 * thread, unless currently in a JTA transaction.
 * //from  w  ww  .j  a v  a 2 s  .co m
 * @param fromSynchronization True if this method is being invoked from
 *      <code>{@link Synchronization}</code> notified of the enclosing 
 *      transaction having completed.
 * 
 * @throws LockException Thrown if there was a problem accessing the JTA 
 *      <code>Transaction</code>.  Only relevant if <code>fromSynchronization</code>
 *      is false.
 */
protected synchronized void releaseLock(String lockName, boolean fromSynchronization) throws LockException {
    lockName = lockName.intern();

    if (isLockOwner(null, lockName)) {

        if (fromSynchronization == false) {
            Transaction t = getTransaction();
            if (t != null) {
                if (getLog().isDebugEnabled()) {
                    getLog().debug("Lock '" + lockName + "' is in a JTA transaction.  " + "Return deferred by: "
                            + Thread.currentThread().getName());
                }

                // If we are still in a transaction, then we don't want to 
                // actually release the lock.
                return;
            }
        }

        if (getLog().isDebugEnabled()) {
            getLog().debug("Lock '" + lockName + "' returned by: " + Thread.currentThread().getName());
        }
        getThreadLocks().remove(lockName);
        locks.remove(lockName);
        this.notify();
    } else if (getLog().isDebugEnabled()) {
        getLog().debug("Lock '" + lockName + "' attempt to return by: " + Thread.currentThread().getName()
                + " -- but not owner!", new Exception("stack-trace of wrongful returner"));
    }
}

From source file:com.thoughtworks.go.server.cache.GoCache.java

public void removeAssociations(String key, Element element) {
    if (element.getObjectValue() instanceof KeyList) {
        synchronized (key.intern()) {
            for (String subkey : (KeyList) element.getObjectValue()) {
                remove(compositeKey(key, subkey));
            }/*from  w w w.  jav  a 2s .  c om*/
        }
    } else if (key.contains(SUB_KEY_DELIMITER)) {
        String[] parts = StringUtils.splitByWholeSeparator(key, SUB_KEY_DELIMITER);
        String parentKey = parts[0];
        String childKey = parts[1];
        synchronized (parentKey.intern()) {
            Element parent = ehCache.get(parentKey);
            if (parent == null) {
                return;
            }
            KeyList subKeys = (KeyList) parent.getObjectValue();
            subKeys.remove(childKey);
        }
    }
}

From source file:com.netxforge.oss2.xml.event.Maskelement.java

/**
 * /*  w  w  w . j  a  v  a2s .  co m*/
 * 
 * @param vMevalue
 * @throws java.lang.IndexOutOfBoundsException if the index
 * given is outside the bounds of the collection
 */
public void addMevalue(final java.lang.String vMevalue) throws java.lang.IndexOutOfBoundsException {
    this._mevalueList.add(vMevalue.intern());
}

From source file:org.wso2.andes.kernel.slot.SlotManagerStandalone.java

/**
 * {@inheritDoc}/*ww  w.  ja  v  a 2  s.c  o m*/
 */
@Override
public long getSafeZoneLowerBoundId(String queueName) throws AndesException {
    long lowerBoundId = -1;
    String lockKey = queueName + SlotManagerStandalone.class;
    synchronized (lockKey.intern()) {
        TreeSet<Long> messageIDSet = slotIDMap.get(queueName);
        //set the lower bound Id for safety delete region as the safety slot count interval upper bound id + 1
        if (messageIDSet.size() >= safetySlotCount) {
            lowerBoundId = messageIDSet.toArray(new Long[messageIDSet.size()])[safetySlotCount - 1] + 1;
            // Inform the slot manager regarding the current expiry deletion range and queue.
            setDeletionTaskState(queueName, lowerBoundId);
        }
    }
    return lowerBoundId;
}

From source file:de.tudarmstadt.ukp.dkpro.core.corenlp.internal.CoreNlp2DKPro.java

private static org.apache.uima.jcas.tcas.Annotation convertConstituentTreeNode(JCas aJCas,
        TreebankLanguagePack aTreebankLanguagePack, Tree aNode, org.apache.uima.jcas.tcas.Annotation aParentFS,
        boolean internStrings, MappingProvider constituentMappingProvider, List<CoreLabel> tokens) {
    // Get node label
    String nodeLabelValue = aNode.value();

    // Extract syntactic function from node label
    String syntacticFunction = null;
    AbstractTreebankLanguagePack tlp = (AbstractTreebankLanguagePack) aTreebankLanguagePack;
    int gfIdx = nodeLabelValue.indexOf(tlp.getGfCharacter());
    if (gfIdx > 0) {
        syntacticFunction = nodeLabelValue.substring(gfIdx + 1);
        nodeLabelValue = nodeLabelValue.substring(0, gfIdx);
    }//from   w  w  w. ja va2 s . c o m

    // Check if node is a constituent node on sentence or phrase-level
    if (aNode.isPhrasal()) {
        Type constType = constituentMappingProvider.getTagType(nodeLabelValue);

        IntPair span = aNode.getSpan();
        int begin = tokens.get(span.getSource()).get(CharacterOffsetBeginAnnotation.class);
        int end = tokens.get(span.getTarget()).get(CharacterOffsetEndAnnotation.class);

        Constituent constituent = (Constituent) aJCas.getCas().createAnnotation(constType, begin, end);
        constituent.setConstituentType(internStrings ? nodeLabelValue.intern() : nodeLabelValue);
        constituent.setSyntacticFunction(
                internStrings && syntacticFunction != null ? syntacticFunction.intern() : syntacticFunction);
        constituent.setParent(aParentFS);

        // Do we have any children?
        List<org.apache.uima.jcas.tcas.Annotation> childAnnotations = new ArrayList<>();
        for (Tree child : aNode.getChildrenAsList()) {
            org.apache.uima.jcas.tcas.Annotation childAnnotation = convertConstituentTreeNode(aJCas,
                    aTreebankLanguagePack, child, constituent, internStrings, constituentMappingProvider,
                    tokens);
            if (childAnnotation != null) {
                childAnnotations.add(childAnnotation);
            }
        }

        // Now that we know how many children we have, link annotation of
        // current node with its children
        constituent.setChildren(FSCollectionFactory.createFSArray(aJCas, childAnnotations));

        constituent.addToIndexes();

        return constituent;
    }
    // Create parent link on token
    else if (aNode.isPreTerminal()) {
        // link token to its parent constituent
        List<Tree> children = aNode.getChildrenAsList();
        assert children.size() == 1;
        Tree terminal = children.get(0);
        CoreLabel label = (CoreLabel) terminal.label();
        Token token = label.get(TokenKey.class);
        token.setParent(aParentFS);
        return token;
    } else {
        throw new IllegalArgumentException("Node must be either phrasal nor pre-terminal");
    }
}

From source file:modula.executor.core.reporter.SimpleErrorReporter.java

/**
 * @see ErrorReporter#onError(String, String, Object)
 *///from   w  w  w  .  j  a v a2  s  .  co  m
@SuppressWarnings("unchecked")
public void onError(final String errorCode, final String errDetail, final Object errCtx) {
    //Note: the if-then-else below is based on the actual usage
    // (codebase search), it has to be kept up-to-date as the code changes
    String errCode = errorCode.intern();
    StringBuffer msg = new StringBuffer();
    msg.append(errCode).append(" (");
    msg.append(errDetail).append("): ");
    if (errCode == ErrorConstants.NO_INITIAL) {
        if (errCtx instanceof Modula) {
            //determineInitialStates
            msg.append("<Modula>");
        } else if (errCtx instanceof State) {
            //determineInitialStates
            //determineTargetStates
            msg.append("State " + LogUtils.getTTPath((State) errCtx));
        }
    } else if (errCode == ErrorConstants.UNKNOWN_ACTION) {
        //executeActionList
        msg.append("Action: " + errCtx.getClass().getName());
    } else if (errCode == ErrorConstants.ILLEGAL_CONFIG) {
        //isLegalConfig
        if (errCtx instanceof Map.Entry) { //unchecked cast below
            Map.Entry<EnterableState, Set<EnterableState>> badConfigMap = (Map.Entry<EnterableState, Set<EnterableState>>) errCtx;
            EnterableState es = badConfigMap.getKey();
            Set<EnterableState> vals = badConfigMap.getValue();
            msg.append(LogUtils.getTTPath(es) + " : [");
            for (Iterator<EnterableState> i = vals.iterator(); i.hasNext();) {
                EnterableState ex = i.next();
                msg.append(LogUtils.getTTPath(ex));
                if (i.hasNext()) { // reason for iterator usage
                    msg.append(", ");
                }
            }
            msg.append(']');
        } else if (errCtx instanceof Set) { //unchecked cast below
            Set<EnterableState> vals = (Set<EnterableState>) errCtx;
            msg.append("<Modula> : [");
            for (Iterator<EnterableState> i = vals.iterator(); i.hasNext();) {
                EnterableState ex = i.next();
                msg.append(LogUtils.getTTPath(ex));
                if (i.hasNext()) {
                    msg.append(", ");
                }
            }
            msg.append(']');
        }
    } else if (errCode == ErrorConstants.EXPRESSION_ERROR) {
        if (errCtx instanceof Executable) {
            TransitionTarget parent = ((Executable) errCtx).getParent();
            msg.append("Expression error inside " + LogUtils.getTTPath(parent));
        } else if (errCtx instanceof Modula) {
            // Global Script
            msg.append("Expression error inside the global script");
        }
    }
    handleErrorMessage(errorCode, errDetail, errCtx, msg);
}