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:Main.java

public static void main(String[] args) {
    String str1 = "java2s.com";

    String str2 = str1.intern();

    System.out.println(str2);//from  w  w  w .  jav a2s  .  c  o  m

    System.out.println("Is str1 equal to str2 ? = " + (str1 == str2));
}

From source file:Main.java

public static final Set<String> stringArrayToSet(final String[] array) {
    if (array == null) {
        return Collections.emptySet();
    }/*  ww w.  j  av  a 2  s  .  c  om*/
    Set<String> tmp = new LinkedHashSet<>();
    for (String part : array) {
        String trimmed = part.trim();
        if (trimmed.length() > 0) {
            tmp.add(trimmed.intern());
        }
    }
    return tmp;
}

From source file:org.blockartistry.DynSurround.registry.Evaluator.java

@Nonnull
public static Variant eval(@Nonnull final String script) {
    return compile(script.intern()).eval();
}

From source file:org.voltdb.types.QueryType.java

public static QueryType get(String name) {
    QueryType ret = QueryType.name_lookup.get(name.intern());
    return (ret == null ? QueryType.INVALID : ret);
}

From source file:org.protempa.proposition.DataSourceBackendId.java

/**
 * Creates a data source backend id./*from   www .  j  a va  2 s  .  co  m*/
 * 
 * @param id the id {@link String}. Cannot be <code>null</code>.
 * @return a {@link DataSourceBackendId}.
 */
public static DataSourceBackendId getInstance(String id) {
    DataSourceBackendId result = cache.get(id);
    if (result == null) {
        id = id.intern();
        result = new DataSourceBackendId(id);
        cache.put(id, result);
    }
    return result;
}

From source file:net.darkmist.clf.LogEntry.java

private static String internIfNotNull(String str) {
    return (str == null) ? null : str.intern();
}

From source file:com.jiangge.apns4j.impl.ApnsServiceImpl.java

public static IApnsService createInstance(ApnsConfig config) {
    checkConfig(config);/*from  w w w  .ja v a2s  .  com*/
    String name = config.getName();
    IApnsService service = getCachedService(name);
    if (service == null) {
        synchronized (name.intern()) {
            service = getCachedService(name);
            if (service == null) {
                service = new ApnsServiceImpl(config);
                serviceCacheMap.put(name, service);
            }
        }
    }
    return service;
}

From source file:com.dbay.apns4j.impl.ApnsServiceImpl.java

public final static IApnsService createInstance(ApnsConfig config, ErrorProcessHandler errorProcessHandler)
        throws UnrecoverableKeyException, KeyManagementException, KeyStoreException, NoSuchAlgorithmException,
        CertificateException, CertificateExpiredException, IOException {
    checkConfig(config);/*from w  ww  . ja  v a2  s  .  co  m*/
    String name = config.getName();
    IApnsService service = getCachedService(name);
    if (service == null) {
        synchronized (name.intern()) {
            service = getCachedService(name);
            if (service == null) {
                service = new ApnsServiceImpl(config, errorProcessHandler);
                serviceCacheMap.put(name, service);
            }
        }
    }
    return service;
}

From source file:models.service.LoginUserCache.java

/**
 * ?session??<br>/*from w ww. ja v  a2  s .  co  m*/
 * null
 * 
 * @param session Http Session
 * @return null
 */
public static User getBySession(Session session) {
    String uid = UserAuthService.getLoginUid(session);
    if (UserAuthService.isLogin(session)) {
        User user = LoginUserCache.getUser(uid);
        if (null == user) {
            synchronized (uid.intern()) {
                user = LoginUserCache.getUser(uid);
                if (null == user) {
                    user = queryUserByUidWithAutoTrasaction(uid);
                    LOGGER.debug("query login user from db. uid = " + uid);
                    if (null != user) {
                        LoginUserCache.setUser(uid, user);
                    }
                } else {
                    LOGGER.debug("get login user from cache. uid = " + uid);
                }
            }
        } else {
            LOGGER.debug("get login user from cache. uid = " + uid);
        }
        return user;
    }

    return null;
}

From source file:org.kalypsodeegree_impl.io.sax.parser.ContentHandlerUtils.java

/** Get srs from attributes, fallback to default crs */
public static String parseSrsFromAttributes(final Attributes attributes, final String defaultSrs) {
    final String srs = parseStringFromAttributes(attributes, "srsName", defaultSrs);
    if (srs == null)
        return null;

    // BUGFIX/REMARK: preserve memory by intern'ing the srs strings. Especially for bigger gml's this can have a major
    // effect, as every srs string was being kept separately in memory.
    return srs.intern();
}