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:de.betterform.xml.xforms.model.constraints.Validator.java

private boolean checkDatatype(String expandedName, String value) {
    XSSimpleType simpleType = (XSSimpleType) this.datatypes.get(expandedName);
    ValidatedInfo validatedInfo = new ValidatedInfo();
    ValidationState validationState = new ValidationState();
    validationState.setFacetChecking(true);
    validationState.setExtraChecking(false);
    validationState.setUsingNamespaces(true);

    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("checking datatype - expandedName: " + expandedName);
    }/* www  .  j  a  v  a  2s .co m*/
    // TODO: does not yet work with restricted QNames
    if (expandedName.endsWith("QName") && value.indexOf(":") != -1) {
        NamespaceSupport support = new NamespaceSupport();
        support.pushContext();
        String nsPrefix = value.substring(0, value.indexOf(":")).intern();
        Map namespaces = NamespaceResolver.getAllNamespaces(this.model.getElement());
        String nsURI = (String) namespaces.get(nsPrefix);

        if (nsPrefix != null && nsURI != null) {
            support.declarePrefix(nsPrefix, nsURI);
            validationState.setNamespaceSupport(support);
        }
    }

    //TODO: handle nullpointer see Testcase 8.1.4.b
    try {
        simpleType.validate(value.intern(), validationState, validatedInfo);
    } catch (InvalidDatatypeValueException e) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("value '" + value + "' of type " + expandedName + " is invalid - " + e.getMessage());
        }
        return false;
    }

    return true;
}

From source file:haven.GameUI.java

public void uimsg(String msg, Object... args) {
    if (msg == "err") {
        String err = (String) args[0];
        error(err);/*from   www .  ja va2s. com*/
        if (err.startsWith("Swimming is now turned"))
            togglebuff(err, "swim", Bufflist.buffswim);
        else if (err.startsWith("Tracking is now turned"))
            togglebuff(err, "track", Bufflist.bufftrack);
        else if (err.startsWith("Criminal acts are now turned"))
            togglebuff(err, "crime", Bufflist.buffcrime);
    } else if (msg == "msg") {
        String text = (String) args[0];
        msg(text);
    } else if (msg == "prog") {
        if (args.length > 0)
            prog = ((Number) args[0]).doubleValue() / 100.0;
        else
            prog = -1;
    } else if (msg == "setbelt") {
        int slot = (Integer) args[0];
        if (args.length < 2) {
            belt[slot] = null;
        } else {
            belt[slot] = ui.sess.getres((Integer) args[1]);
        }
    } else if (msg == "polowner") {
        String o = (String) args[0];
        boolean n = ((Integer) args[1]) != 0;
        if (o.length() == 0)
            o = null;
        else
            o = o.intern();
        if (o != polowner) {
            if (map != null) {
                if (o == null) {
                    if (polowner != null)
                        map.setpoltext("Leaving " + polowner);
                } else {
                    map.setpoltext("Entering " + o);
                }
            }
            polowner = o;
        }
    } else if (msg == "showhelp") {
        Indir<Resource> res = ui.sess.getres((Integer) args[0]);
        if (help == null)
            help = adda(new HelpWnd(res), 0.5, 0.5);
        else
            help.res = res;
    } else {
        super.uimsg(msg, args);
    }
}

From source file:bboss.org.apache.velocity.runtime.RuntimeInstance.java

/**
 *  Checks to see if a VM exists/*from  w w w  .j  a va  2 s  .c o  m*/
 *
 * @param vmName Name of the Velocimacro.
 * @param templateName Template on which to look for the Macro.
 * @return True if VM by that name exists, false if not
 */
public boolean isVelocimacro(String vmName, String templateName) {
    return vmFactory.isVelocimacro(vmName.intern(), templateName);
}

From source file:edu.stanford.muse.util.EmailUtils.java

private static Map<String, String> readDBpedia(double p, String typesFile) {
    if (dbpedia != null) {
        if (p == 1)
            return dbpedia;
        else/* ww w.ja v  a2  s .c  o  m*/
            return new org.apache.commons.collections4.map.CaseInsensitiveMap<>(sample(dbpedia, p));
    }
    if (typesFile == null)
        typesFile = Config.DBPEDIA_INSTANCE_FILE;
    //dbpedia = new LinkedHashMap<>();
    //we want to be able to access elements in the map in a case-sensitive manner, this is a way to do that.
    dbpedia = new org.apache.commons.collections4.map.CaseInsensitiveMap<>();
    int d = 0, numPersons = 0, lines = 0;
    try {
        InputStream is = Config.getResourceAsStream(typesFile);
        if (is == null) {
            log.warn("DBpedia file resource could not be read!!");
            return dbpedia;
        }

        //true argument for BZip2CompressorInputStream so as to load the whole file content into memory
        LineNumberReader lnr = new LineNumberReader(
                new InputStreamReader(new BZip2CompressorInputStream(is, true), "UTF-8"));
        while (true) {
            String line = lnr.readLine();
            if (line == null)
                break;
            if (lines++ % 1000000 == 0)
                log.info("Processed " + lines + " lines of approx. 3.02M in " + typesFile);

            if (line.contains("GivenName"))
                continue;

            String[] words = line.split("\\s+");
            String r = words[0];

            /**
             * The types file contains lines like this:
             * National_Bureau_of_Asian_Research Organisation|Agent
             * National_Bureau_of_Asian_Research__1 PersonFunction
             * National_Bureau_of_Asian_Research__2 PersonFunction
             * Which leads to classifying "National_Bureau_of_Asian_Research" as PersonFunction and not Org.
             */
            if (r.contains("__")) {
                d++;
                continue;
            }
            //if it still contains this, is a bad title.
            if (r.equals("") || r.contains("__")) {
                d++;
                continue;
            }
            String type = words[1];
            //Royalty names, though tagged person are very weird, contains roman characters and suffixes like of_Poland e.t.c.
            if (type.equals("PersonFunction") || type.equals("Royalty|Person|Agent"))
                continue;
            //in places there are things like: Shaikh_Ibrahim,_Iraq
            if (type.endsWith("Settlement|PopulatedPlace|Place"))
                r = r.replaceAll(",_.*", "");

            //its very dangerous to remove things inside brackets as that may lead to terms like
            //University_(Metrorail_Station) MetroStation|Place e.t.c.
            //so keep them, or just skip this entry all together
            //We are not considering single word tokens any way, so its OK to remove things inside the brackets
            //removing stuff in brackets may cause trouble when blind matching entities
            //r = r.replaceAll("_\\(.*?\\)", "");
            String title = r.replaceAll("_", " ");

            String badSuffix = "|Agent";
            if (type.endsWith(badSuffix) && type.length() > badSuffix.length())
                type = type.substring(0, type.length() - badSuffix.length());
            if (type.endsWith("|Person"))
                numPersons++;
            type = type.intern(); // type strings are repeated very often, so intern

            if (type.equals("Road|RouteOfTransportation|Infrastructure|ArchitecturalStructure|Place")) {
                //System.err.print("Cleaned: "+title);
                title = cleanDBPediaRoad(title);
                //System.err.println(" to "+title);
            }
            dbpedia.put(title, type);
        }
        lnr.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    log.info("Read " + dbpedia.size() + " names from DBpedia, " + numPersons + " people name. dropped: " + d);

    return new org.apache.commons.collections4.map.CaseInsensitiveMap<>(sample(dbpedia, p));
}

From source file:bboss.org.apache.velocity.runtime.RuntimeInstance.java

/**
 * Adds a new Velocimacro. Usually called by Macro only while parsing.
 * /*from   w  w  w  . j  ava 2s.com*/
 * Called by bboss.org.apache.velocity.runtime.directive.processAndRegister
 *
 * @param name  Name of velocimacro
 * @param macro  root AST node of the parsed macro
 * @param argArray  Array of strings, containing the
 *                         #macro() arguments.  the 0th is the name.
 * @param sourceTemplate
 * 
 * @since Velocity 1.6
 *                   
 * @return boolean  True if added, false if rejected for some
 *                  reason (either parameters or permission settings)
 */
public boolean addVelocimacro(String name, Node macro, String argArray[], String sourceTemplate) {
    return vmFactory.addVelocimacro(name.intern(), macro, argArray, sourceTemplate);
}

From source file:bboss.org.apache.velocity.runtime.RuntimeInstance.java

/**
 * Adds a new Velocimacro. Usually called by Macro only while parsing.
 *
 * @param name Name of velocimacro/*from w w w  . ja v  a 2s . c  o m*/
 * @param macro String form of macro body
 * @param argArray Array of strings, containing the
 *                         #macro() arguments.  the 0th is the name.
 * @param sourceTemplate Name of the template that contains the velocimacro.
 * 
 * @deprecated Use addVelocimacro(String, Node, String[], String) instead
 * 
 * @return True if added, false if rejected for some
 *                  reason (either parameters or permission settings)
 */
public boolean addVelocimacro(String name, String macro, String argArray[], String sourceTemplate) {
    return vmFactory.addVelocimacro(name.intern(), macro, argArray, sourceTemplate);
}

From source file:org.dhatim.cdr.SmooksResourceConfiguration.java

/**
 * Set the namespace URI to which the selector is associated.
 *
 * @param namespaceURI Selector namespace.
 *///  ww w . j av a2s. com
public void setSelectorNamespaceURI(String namespaceURI) {
    if (namespaceURI != null) {
        if (namespaceURI.equals("*")) {
            this.namespaceURI = null;
        } else {
            this.namespaceURI = namespaceURI.intern();
        }
        fireChangedEvent();
    }
}

From source file:org.apache.hadoop.mapred.JobHistory.java

private static String timestampDirectoryComponent(JobID id, long millisecondTime) {
    int serialNumber = jobSerialNumber(id);
    Integer boxedSerialNumber = serialNumber;

    // don't want to do this inside the lock
    Calendar timestamp = Calendar.getInstance();
    timestamp.setTimeInMillis(millisecondTime);

    synchronized (idToDateString) {
        String dateString = idToDateString.get(boxedSerialNumber);

        if (dateString == null) {

            dateString = String.format("%04d/%02d/%02d", timestamp.get(Calendar.YEAR),
                    // months are 0-based in Calendar, but people will expect January
                    // to be month #1.
                    timestamp.get(DEBUG_MODE ? Calendar.HOUR : Calendar.MONTH) + 1,
                    timestamp.get(DEBUG_MODE ? Calendar.MINUTE : Calendar.DAY_OF_MONTH));

            dateString = dateString.intern();

            idToDateString.put(boxedSerialNumber, dateString);

            if (idToDateString.size() > MAXIMUM_DATESTRING_COUNT) {
                idToDateString.remove(idToDateString.firstKey());
            }/*  www.  j ava 2  s. c om*/
        }

        return dateString;
    }
}

From source file:org.apache.carbondata.core.datamap.DataMapStoreManager.java

/**
 * Get the datamap for reading data./*from w  w w .ja va2 s.  c o  m*/
 */
public TableDataMap getDataMap(CarbonTable table, DataMapSchema dataMapSchema) {
    String tableUniqueName = table.getAbsoluteTableIdentifier().getCarbonTableIdentifier().getTableUniqueName();
    List<TableDataMap> tableIndices = allDataMaps.get(tableUniqueName);
    if (tableIndices == null) {
        String keyUsingTablePath = getKeyUsingTablePath(table.getTablePath());
        if (keyUsingTablePath != null) {
            tableUniqueName = keyUsingTablePath;
            tableIndices = allDataMaps.get(tableUniqueName);
        }
    }
    // in case of fileformat or sdk, when table is dropped or schema is changed the datamaps are
    // not cleared, they need to be cleared by using API, so compare the columns, if not same, clear
    // the datamaps on that table
    if (allDataMaps.size() > 0 && !CollectionUtils.isEmpty(allDataMaps.get(tableUniqueName))
            && !allDataMaps.get(tableUniqueName).get(0).getTable().getTableInfo().getFactTable()
                    .getListOfColumns().equals(table.getTableInfo().getFactTable().getListOfColumns())) {
        clearDataMaps(tableUniqueName);
        tableIndices = null;
    }
    TableDataMap dataMap = null;
    if (tableIndices != null) {
        dataMap = getTableDataMap(dataMapSchema.getDataMapName(), tableIndices);
    }
    if (dataMap == null) {
        synchronized (tableUniqueName.intern()) {
            tableIndices = allDataMaps.get(tableUniqueName);
            if (tableIndices != null) {
                dataMap = getTableDataMap(dataMapSchema.getDataMapName(), tableIndices);
            }
            if (dataMap == null) {
                try {
                    dataMap = createAndRegisterDataMap(table, dataMapSchema);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }

    if (dataMap == null) {
        throw new RuntimeException("Datamap does not exist");
    }
    // This is done to handle the scenario of stale cache because of which schema mismatch
    // exception can be thrown. Scenario: In case of carbondata used through FileFormat API,
    // once a table is dropped and recreated with the same name again then because the dataMap
    // contains the stale carbon table schema mismatch exception is thrown. To avoid such scenarios
    // it is always better to update the carbon table object retrieved
    dataMap.getDataMapFactory().setCarbonTable(table);
    return dataMap;
}

From source file:ubic.basecode.bio.geneset.GeneAnnotations.java

/**
 * @param classIds/*from  w  ww  .ja  v  a  2s .  c o m*/
 * @param probe
 */
private void extractPipeDelimitedGoIds(String classIds, String probe) {
    String[] classIdAry = pipePattern.split(classIds);
    if (classIdAry.length == 0)
        return;

    Collection<String> probeCol = probeToGeneSetMap.get(probe);
    probeCol.addAll(Arrays.asList(classIdAry));

    for (String element : classIdAry) {
        String go = element.intern();

        if (!geneSetToProbeMap.containsKey(go)) {
            geneSetToProbeMap.put(go, new HashSet<String>());
        }
        geneSetToProbeMap.get(go).add(probe);
    }
}