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:org.nuxeo.ecm.core.storage.State.java

protected void putEvenIfNull(String key, Serializable value) {
    if (map != null) {
        map.put(key.intern(), value);
    } else {//from  www .  j a va 2s . c  o m
        int i = keys.indexOf(key);
        if (i >= 0) {
            // existing key
            values.set(i, value);
        } else {
            // new key
            if (keys.size() < ARRAY_MAX) {
                keys.add(key.intern());
                values.add(value);
            } else {
                // upgrade to a full HashMap
                map = new HashMap<>(initialCapacity(keys.size() + 1));
                for (int j = 0; j < keys.size(); j++) {
                    map.put(keys.get(j), values.get(j));
                }
                map.put(key.intern(), value);
                keys = null;
                values = null;
            }
        }
    }
}

From source file:edu.cornell.med.icb.pca.RotationReaderWriter.java

/**
 * Check if a table has been saved to the cache.
 *
 * @param datasetEndpointName the dataset to find a table for
 * @param pathwayId          the pathwayId to find a table for
 * @return true if table a table with the specified paramters has been cached
 *//* ww  w .jav  a  2 s  . co  m*/
public boolean isTableCached(final CharSequence datasetEndpointName, final MutableString pathwayId) {
    final boolean result;
    final String cachedTableFile = getRotationFile(datasetEndpointName, pathwayId);
    if (LOG.isTraceEnabled()) {
        LOG.trace(Thread.currentThread().getName() + " entering synchronized block on "
                + cachedTableFile.intern());
    }

    synchronized (cachedTableFile.intern()) {
        result = cfr.containsFile(cachedTableFile);
        if (LOG.isTraceEnabled()) {
            LOG.trace("Checked for existance of table " + cachedTableFile + " : " + result);
        }
    }

    if (LOG.isTraceEnabled()) {
        LOG.trace(Thread.currentThread().getName() + " left synchronized block on " + cachedTableFile.intern());
    }
    return result;
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.lif.internal.Lif2DKPro.java

public void convert(Container aContainer, JCas aJCas) {
    aJCas.setDocumentLanguage(aContainer.getLanguage());
    aJCas.setDocumentText(aContainer.getText());

    View view = aContainer.getView(0);

    // Paragraph/* w ww.ja va  2s . co m*/
    view.getAnnotations().stream().filter(a -> Discriminators.Uri.PARAGRAPH.equals(a.getAtType()))
            .forEach(para -> {
                Paragraph paraAnno = new Paragraph(aJCas, para.getStart().intValue(), para.getEnd().intValue());
                paraAnno.addToIndexes();
            });

    // Sentence
    view.getAnnotations().stream().filter(a -> Discriminators.Uri.SENTENCE.equals(a.getAtType()))
            .forEach(sent -> {
                Sentence sentAnno = new Sentence(aJCas, sent.getStart().intValue(), sent.getEnd().intValue());
                sentAnno.addToIndexes();
            });

    Map<String, Token> tokenIdx = new HashMap<>();

    // Token, POS, Lemma
    view.getAnnotations().stream().filter(a -> Discriminators.Uri.TOKEN.equals(a.getAtType()))
            .forEach(token -> {
                Token tokenAnno = new Token(aJCas, token.getStart().intValue(), token.getEnd().intValue());
                String pos = token.getFeature(Features.Token.POS);
                String lemma = token.getFeature(Features.Token.LEMMA);

                if (isNotEmpty(pos)) {
                    POS posAnno = new POS(aJCas, tokenAnno.getBegin(), tokenAnno.getEnd());
                    posAnno.setPosValue(pos.intern());
                    posAnno.setCoarseValue(posAnno.getClass().equals(POS.class) ? null
                            : posAnno.getType().getShortName().intern());
                    posAnno.addToIndexes();
                    tokenAnno.setPos(posAnno);
                }

                if (isNotEmpty(lemma)) {
                    Lemma lemmaAnno = new Lemma(aJCas, tokenAnno.getBegin(), tokenAnno.getEnd());
                    lemmaAnno.setValue(lemma);
                    lemmaAnno.addToIndexes();
                    tokenAnno.setLemma(lemmaAnno);
                }

                tokenAnno.addToIndexes();
                tokenIdx.put(token.getId(), tokenAnno);
            });

    // NamedEntity
    view.getAnnotations().stream().filter(a -> Discriminators.Uri.NE.equals(a.getAtType())).forEach(ne -> {
        NamedEntity neAnno = new NamedEntity(aJCas, ne.getStart().intValue(), ne.getEnd().intValue());
        neAnno.setValue(ne.getLabel());
        neAnno.addToIndexes();
    });

    // Dependencies
    view.getAnnotations().stream().filter(a -> Discriminators.Uri.DEPENDENCY.equals(a.getAtType()))
            .forEach(dep -> {
                String dependent = dep.getFeature(Features.Dependency.DEPENDENT);
                String governor = dep.getFeature(Features.Dependency.GOVERNOR);

                if (isEmpty(governor) || governor.equals(dependent)) {
                    ROOT depAnno = new ROOT(aJCas);
                    depAnno.setDependencyType(dep.getLabel());
                    depAnno.setDependent(tokenIdx.get(dependent));
                    depAnno.setGovernor(tokenIdx.get(dependent));
                    depAnno.setBegin(depAnno.getDependent().getBegin());
                    depAnno.setEnd(depAnno.getDependent().getEnd());
                    depAnno.addToIndexes();
                } else {
                    Dependency depAnno = new Dependency(aJCas);
                    depAnno.setDependencyType(dep.getLabel());
                    depAnno.setDependent(tokenIdx.get(dependent));
                    depAnno.setGovernor(tokenIdx.get(governor));
                    depAnno.setBegin(depAnno.getDependent().getBegin());
                    depAnno.setEnd(depAnno.getDependent().getEnd());
                    depAnno.addToIndexes();
                }
            });

    // Constituents
    view.getAnnotations().stream().filter(a -> Discriminators.Uri.PHRASE_STRUCTURE.equals(a.getAtType()))
            .forEach(ps -> {
                String rootId = findRoot(view, ps);
                // Get the constituent IDs
                Set<String> constituentIDs;
                constituentIDs = new HashSet<>(getSetFeature(ps, Features.PhraseStructure.CONSTITUENTS));

                List<Annotation> constituents = new ArrayList<>();
                Map<String, Constituent> constituentIdx = new HashMap<>();

                // Instantiate all the constituents
                view.getAnnotations().stream().filter(a -> constituentIDs.contains(a.getId())).forEach(con -> {
                    if (Discriminators.Uri.CONSTITUENT.equals(con.getAtType())) {
                        Constituent conAnno;
                        if (rootId.equals(con.getId())) {
                            conAnno = new de.tudarmstadt.ukp.dkpro.core.api.syntax.type.constituent.ROOT(aJCas);
                        } else {
                            conAnno = new Constituent(aJCas);
                        }
                        if (con.getStart() != null) {
                            conAnno.setBegin(con.getStart().intValue());
                        }
                        if (con.getEnd() != null) {
                            conAnno.setEnd(con.getEnd().intValue());
                        }
                        conAnno.setConstituentType(con.getLabel());
                        constituentIdx.put(con.getId(), conAnno);
                        constituents.add(con);
                    }
                    // If it is not a constituent, it must be a token ID - we already
                    // have created the tokens and recorded them in the tokenIdx
                });

                // Set parent and children features
                constituents.forEach(con -> {
                    // Check if it is a constituent or token
                    Constituent conAnno = constituentIdx.get(con.getId());
                    Set<String> childIDs = getSetFeature(con, Features.Constituent.CHILDREN);

                    List<org.apache.uima.jcas.tcas.Annotation> children = new ArrayList<>();
                    childIDs.forEach(childID -> {
                        Constituent conChild = constituentIdx.get(childID);
                        Token tokenChild = tokenIdx.get(childID);
                        if (conChild != null && tokenChild == null) {
                            conChild.setParent(conAnno);
                            children.add(conChild);
                        } else if (conChild == null && tokenChild != null) {
                            tokenChild.setParent(conAnno);
                            children.add(tokenChild);
                        } else if (conChild == null && tokenChild == null) {
                            throw new IllegalStateException("ID [" + con.getId() + "] not found");
                        } else {
                            throw new IllegalStateException(
                                    "ID [" + con.getId() + "] is constituent AND token? Impossible!");
                        }
                    });

                    conAnno.setChildren(FSCollectionFactory.createFSArray(aJCas, children));
                });

                // Percolate offsets - they might not have been set on the constituents!
                Constituent root = constituentIdx.get(rootId);
                percolateOffsets(root);

                // Add to indexes
                constituentIdx.values().forEach(conAnno -> {
                    conAnno.addToIndexes();
                });
            });
}

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

/**
 * /* www. ja  v a2s  . co m*/
 * 
 * @param index
 * @param vMevalue
 * @throws java.lang.IndexOutOfBoundsException if the index
 * given is outside the bounds of the collection
 */
public void setMevalue(final int index, final java.lang.String vMevalue)
        throws java.lang.IndexOutOfBoundsException {
    // check bounds for index
    if (index < 0 || index >= this._mevalueList.size()) {
        throw new IndexOutOfBoundsException("setMevalue: Index value '" + index + "' not in range [0.."
                + (this._mevalueList.size() - 1) + "]");
    }

    this._mevalueList.set(index, vMevalue.intern());
}

From source file:org.hyperledger.fabric.sdk.ChaincodeCollectionConfiguration.java

private IndexedHashMap<String, MSPPrincipal> parseIdentities(JsonArray identities)
        throws ChaincodeCollectionConfigurationException {
    IndexedHashMap<String, MSPPrincipal> ret = new IndexedHashMap<>();

    for (JsonValue jsonValue : identities) {
        if (jsonValue.getValueType() != JsonValue.ValueType.OBJECT) {
            throw new ChaincodeCollectionConfigurationException(
                    format("Expected in identies user to be Object type but got: %s",
                            jsonValue.getValueType().name()));
        }/*www . j a va  2  s  . c  o m*/
        JsonObject user = jsonValue.asJsonObject();
        if (user.entrySet().size() != 1) {
            throw new ChaincodeCollectionConfigurationException(
                    "Only expected on property for user entry in identies.");
        }
        Map.Entry<String, JsonValue> next = user.entrySet().iterator().next();
        String name = next.getKey();
        jsonValue = next.getValue();
        if (jsonValue.getValueType() != JsonValue.ValueType.OBJECT) {
            throw new ChaincodeCollectionConfigurationException(
                    format("Expected in identies role to be Object type but got: %s",
                            jsonValue.getValueType().name()));
        }
        JsonObject role = jsonValue.asJsonObject();
        JsonObject roleObj = getJsonObject(role, "role");
        String roleName = getJsonString(roleObj, "name");
        String mspId = getJsonString(roleObj, "mspId");

        MSPRole.MSPRoleType mspRoleType;

        switch (roleName.intern()) {
        case "member":
            mspRoleType = MSPRole.MSPRoleType.MEMBER;
            break;
        case "admin":
            mspRoleType = MSPRole.MSPRoleType.ADMIN;
            break;
        case "client":
            mspRoleType = MSPRole.MSPRoleType.CLIENT;
            break;
        case "peer":
            mspRoleType = MSPRole.MSPRoleType.PEER;
            break;
        default:
            throw new ChaincodeCollectionConfigurationException(format(
                    "In identities with key %s name expected member, admin, client, or peer in role got %s ",
                    name, roleName));
        }

        MSPRole mspRole = MSPRole.newBuilder().setRole(mspRoleType).setMspIdentifier(mspId).build();

        MSPPrincipal principal = MSPPrincipal.newBuilder()
                .setPrincipalClassification(MSPPrincipal.Classification.ROLE)
                .setPrincipal(mspRole.toByteString()).build();

        ret.put(name, principal);

    }

    return ret;
}

From source file:pcgen.persistence.lst.BioSetLoader.java

@Override
public void parseLine(LoadContext context, String lstLine, URI sourceURI) {
    if (lstLine.startsWith("#")) {
        //Is a comment
        return;//from   w w w. j av  a  2 s . c om
    }
    if (lstLine.startsWith("AGESET:")) {
        String line = lstLine.substring(7);
        int pipeLoc = line.indexOf('|');
        if (pipeLoc == -1) {
            Logging.errorPrint("Found invalid AGESET " + "in Bio Settings " + sourceURI
                    + ", was expecting a |: " + lstLine);
            return;
        }
        String ageIndexString = line.substring(0, pipeLoc);
        try {
            currentAgeSetIndex = Integer.parseInt(ageIndexString);
        } catch (NumberFormatException e) {
            Logging.errorPrint("Illegal Index for AGESET " + "in Bio Settings " + sourceURI + ": "
                    + ageIndexString + " was not an integer");
        }
        StringTokenizer colToken = new StringTokenizer(line.substring(pipeLoc + 1), SystemLoader.TAB_DELIM);
        AgeSet ageSet = new AgeSet();
        ageSet.setSourceURI(sourceURI);
        ageSet.setAgeIndex(currentAgeSetIndex);
        ageSet.setName(colToken.nextToken().intern());
        while (colToken.hasMoreTokens()) {
            try {
                LstUtils.processToken(context, ageSet, sourceURI, colToken.nextToken());
            } catch (PersistenceLayerException e) {
                Logging.errorPrint("Error in token parse: " + e.getLocalizedMessage());
            }
        }

        ageSet = bioSet.addToAgeMap(region, ageSet, sourceURI);
        Integer oldIndex = bioSet.addToNameMap(ageSet);
        if (oldIndex != null && oldIndex != currentAgeSetIndex) {
            Logging.errorPrint("Incompatible Index for AGESET " + "in Bio Settings " + sourceURI + ": "
                    + oldIndex + " and " + currentAgeSetIndex + " for " + ageSet.getDisplayName());
        }

    } else if (lstLine.startsWith("REGION:")) {
        region = Optional.of(Region.getConstant(lstLine.substring(7).intern()));
    } else if (lstLine.startsWith("RACENAME:")) {
        StringTokenizer colToken = new StringTokenizer(lstLine, SystemLoader.TAB_DELIM);
        String raceName = colToken.nextToken().substring(9).intern();
        List<String> preReqList = null;

        while (colToken.hasMoreTokens()) {
            String colString = colToken.nextToken();

            if (PreParserFactory.isPreReqString(colString)) {
                if (preReqList == null) {
                    preReqList = new ArrayList<>();
                }

                preReqList.add(colString);
            } else {
                String aString = colString;

                if (preReqList != null) {
                    final StringBuilder sBuf = new StringBuilder(100 + colString.length());
                    sBuf.append(colString);

                    for (String aPreReqList : preReqList) {
                        sBuf.append('[').append(aPreReqList).append(']');
                    }

                    aString = sBuf.toString();
                }

                bioSet.addToUserMap(region, raceName, aString.intern(), currentAgeSetIndex);
            }
        }
    } else if (!StringUtils.isEmpty(lstLine)) {
        Logging.errorPrint("Unable to process line " + lstLine + "in Bio Settings " + sourceURI);
    }
}

From source file:com.ankang.report.register.impl.MonitorRegister.java

private void loadOldData(List<String> modulNames) {

    loadFile();/*from   w ww .  j a  v a  2 s.  c o  m*/
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader(this.monitorFile));
        String text = null;
        int count = 0;
        while ((text = br.readLine()) != null) {
            if (count++ > 9 && StringUtils.isNotEmpty(text)) {
                for (String modulName : modulNames) {
                    if (text.startsWith(modulName)) {
                        APPENDTEXT.add(text.intern());
                        continue;
                    }
                }
            }
        }
    } catch (IOException e) {
        logger.error("File read exception", e);
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                logger.error("IO flow off exception", e);
            }
        }
    }
}

From source file:org.bdval.Predict.java

protected String trueLabel(final String sampleId) {
    final String label = sample2TrueLabelMap == null ? "unknown" : sample2TrueLabelMap.get(sampleId.intern());
    if (LOG.isTraceEnabled()) {
        LOG.trace("True label for " + sampleId + " is " + label);
    }/* w  w w .  j  a  va2s .c o m*/
    if (label == null) {
        LOG.warn("Cannot find sampleId " + sampleId + " in true label information, for model  "
                + this.modelFilenamePrefixNoPath + ". We read true labels from filename: " + trueLabelFilename
                + " The test set was read from " + testSampleFilename);
        return "unknown";
    } else {
        return label;
    }
}

From source file:org.opendaylight.netvirt.vpnmanager.ArpNotificationHandler.java

private void removeMipAdjacency(String vpnName, String vpnInterface, IpAddress prefix) {
    String ip = VpnUtil.getIpPrefix(prefix.getIpv4Address().getValue());
    LOG.trace("Removing {} adjacency from Old VPN Interface {} ", ip, vpnInterface);
    InstanceIdentifier<VpnInterface> vpnIfId = VpnUtil.getVpnInterfaceIdentifier(vpnInterface);
    InstanceIdentifier<Adjacencies> path = vpnIfId.augmentation(Adjacencies.class);
    synchronized (vpnInterface.intern()) {
        Optional<Adjacencies> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, path);
        if (adjacencies.isPresent()) {
            InstanceIdentifier<Adjacency> adjacencyIdentifier = InstanceIdentifier.builder(VpnInterfaces.class)
                    .child(VpnInterface.class, new VpnInterfaceKey(vpnInterface))
                    .augmentation(Adjacencies.class).child(Adjacency.class, new AdjacencyKey(ip)).build();
            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
            LOG.trace("Successfully Deleted Adjacency into VpnInterface {}", vpnInterface);
        }//ww  w .j  a  v a2s  . c  o m
    }
}

From source file:chatbot.Chatbot.java

/** ************************************************************************************************
 * Read a file of stopwords into the variable
 * ArrayList<String> stopwords/* ww  w. j a v a 2s  . c  o m*/
 */
private void readStopWords(String stopwordsFilename) throws IOException {

    String filename = "";
    if (asResource) {
        URL stopWordsFile = Resources.getResource("resources/stopwords.txt");
        filename = stopWordsFile.getPath();
    } else
        filename = stopwordsFilename;
    FileReader r = new FileReader(filename);
    LineNumberReader lr = new LineNumberReader(r);
    String line;
    while ((line = lr.readLine()) != null)
        stopwords.add(line.intern());
    return;
}