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.wso2.carbon.appfactory.s4.integration.DomainMappingManagementService.java

/**
 * Add new domain mapping entry to stratos.
 *
 * @param stage          mapping stage/*w  w  w  .  j  ava  2s. com*/
 * @param domain         e.g: some.organization.org this doesn't require the protocol such as http/https
 * @param appKey         application key
 * @param version        version to be mapped, null if map to default page
 * @param isCustomDomain whether {@code domain} is custom domain or not
 * @throws AppFactoryException                if an error occurred during the operation
 * @throws DomainMappingVerificationException if the requested {@code domain} is not verified, given that it is a
 *                                            custom domain({@code isCustomDomain} is true). To find more info on
 *                                            verification method, please refer to {@link
 *                                            #verifyCustomUrlForApplication}
 */
public void addSubscriptionDomain(String stage, String domain, String appKey, String version,
        boolean isCustomDomain) throws AppFactoryException, DomainMappingVerificationException {
    String appType = ApplicationDAO.getInstance().getApplicationInfo(appKey).getType();
    String addSubscriptionDomainEndPoint = DomainMappingUtils.getAddDomainEndPoint(stage, appType);
    synchronized (domain.intern()) {

        // Check domain availability
        boolean domainAvailable = isDomainAvailable(stage, domain, appType);
        if (!domainAvailable) {
            // Throws an exception, if requested domain is not available.
            log.error("Requested domain: " + domain + " does not available for application id :" + appKey
                    + " for stage :" + stage);
            throw new AppFactoryException(
                    String.format(DomainMappingUtils.AF_DOMAIN_NOT_AVAILABLE_MSG, domain));
        }

        // if the given domain is custom domain, check whether domain is verified
        if (isCustomDomain && !verifyCustomUrlForApplication(domain, appKey)) {
            // if custom utl is not verified, throw an exception. Here we are throwing DomainMappingVerificationException therefore
            // we could identify the error occurred due to unsuccessful verification
            notifyAppWall(appKey, AF_APPWALL_CUSTOM_URL_INVALID_MSG, String.format(AF_APPWALL_URL, domain),
                    Event.Category.ERROR);
            log.warn("Requested custom domain :" + domain + " is not verified for application id :" + appKey
                    + " for stage :" + stage);
            throw new DomainMappingVerificationException(
                    String.format(DomainMappingUtils.AF_CUSTOM_URL_NOT_VERIFIED, domain));
        }

        DomainMappingResponse response;
        try {
            String body;
            if (StringUtils.isNotBlank(version)) { // if the domain is to be mapped to a version
                body = DomainMappingUtils.generateAddSubscriptionDomainJSON(domain, appKey, version, stage);
            } else { // map the domain to initial url
                body = DomainMappingUtils.generateInitialSubscriptionDomainJSON(domain);
            }
            response = DomainMappingUtils.sendPostRequest(stage, body, addSubscriptionDomainEndPoint);
        } catch (AppFactoryException e) {
            log.error("Error occurred adding domain mappings to appkey " + appKey + " version " + version
                    + " domain " + domain, e);
            //Notifying the domain mapping failure to app wall
            notifyAppWall(appKey, AF_APPWALL_ERROR_MSG, "", Event.Category.ERROR);
            throw new AppFactoryException(String.format(DomainMappingUtils.AF_ERROR_ADD_DOMAIN_MSG, domain));
        }

        if (response.statusCode == HttpStatus.SC_OK) {
            log.info("Successfully added domain mapping for application: " + appKey + " domain:" + domain
                    + (StringUtils.isNotBlank(version) ? (" to version: " + version) : ""));
            if (log.isDebugEnabled()) {
                log.debug("Stratos response status: " + response.statusCode + " Stratos Response message: "
                        + response.getResponse());
            }
            DomainMappingUtils.publishToDomainMappingEventHandlers(domain,
                    DomainMappingAction.ADD_DOMAIN_MAPPING);
            //Notifying the domain mapping success to app wall
            notifyAppWall(appKey, AF_APPWALL_SUCCESS_MSG, String.format(AF_APPWALL_URL, domain),
                    Event.Category.INFO);
        } else {
            notifyAppWall(appKey, AF_APPWALL_ERROR_MSG, "", Event.Category.ERROR);
            log.error(String.format(DomainMappingUtils.AF_ERROR_ADD_DOMAIN_MSG, domain)
                    + " Stratos response status: " + response.statusCode + " Stratos Response message: "
                    + response.getResponse());
            throw new AppFactoryException(String.format(DomainMappingUtils.AF_ERROR_ADD_DOMAIN_MSG, domain));
        }
    } // end of synchronized
}

From source file:org.ambraproject.article.service.BrowseServiceImpl.java

/**
 * Get the dates of all articles with a <code>state</code> of <code>ACTIVE</code> (meaning the articles have been
 * published). The outer map is a map of years, the next inner map a map of months, and finally the innermost is a
 * list of days. <br/>//  w  w w  .  ja v  a 2s .  com
 *
 * @param  journalKey the current journal
 *
 * @return the article dates.
 */
@Transactional(readOnly = true)
public Years getArticleDatesForJournal(final String journalKey) {
    if (this.useCache) {
        String cacheKey = DATE_LIST_KEY + journalKey;

        return browseSolrCache.get(cacheKey, this.cacheTimeToLive,
                new Cache.SynchronizedLookup<Years, RuntimeException>(cacheKey.intern()) {
                    @SuppressWarnings("synthetic-access")
                    @Override
                    public Years lookup() throws RuntimeException {
                        return loadArticleDates(journalKey);
                    }
                });
    } else {
        return loadArticleDates(journalKey);
    }
}

From source file:org.ambraproject.article.service.BrowseServiceImpl.java

/**
 * Get a list of article-counts for each category.
 *
 * @param journalKey The current journal
 * @return the category infos.//from  ww  w  . j  a va 2  s . com
 */
@Transactional(readOnly = true)
public SortedMap<String, Long> getSubjectsForJournal(final String journalKey) {
    if (this.useCache) {
        final String cacheKey = ARTBYCAT_LIST_KEY + journalKey;

        return browseSolrCache.get(cacheKey, this.cacheTimeToLive,
                new Cache.SynchronizedLookup<SortedMap<String, Long>, RuntimeException>(cacheKey.intern()) {
                    @Override
                    public SortedMap<String, Long> lookup() throws RuntimeException {
                        return getSubjectsForJournalViaSolr(journalKey);
                    }
                });
    } else {
        return getSubjectsForJournalViaSolr(journalKey);
    }
}

From source file:com.cyberway.issue.crawler.settings.ComplexType.java

/** Creates a new instance of ComplexType.
 *
 * @param name the name of the element./*from  w ww  .ja  va 2  s  . c  o m*/
 * @param description the description of the element.
 */
public ComplexType(String name, String description) {
    super(name, null);
    this.description = description.intern();
}

From source file:com.idylwood.yahoo.YahooFinance.java

/**
 * Get the historical csv table for symbol. Will memoize (cache) the result.
 * @param symbol//  w  w  w.j a  v  a2s.c o  m
 * @return
 * @throws IOException
 */
public HistTable HistoricalPrices(String symbol) throws IOException {
    HistTable ret = null;
    synchronized (mTables) {
        ret = mTables.get(symbol);
        // TODO make this more sophisticated. As it is it's going to download the whole table another time every day. Lol.
        // Try something where you just download today's price. problematic
        // because then it's like mutable.
        //
        // If we don't have the table or it is old get a new one
        if (null == ret || System.currentTimeMillis() - ret.dateAccessed > TwentyFourHours) {
            ret = DownloadHistoricalPrices(symbol);
            // intern it in case calling code is smart
            mTables.put(symbol.intern(), ret);
        }
    }
    return ret;
}

From source file:org.ambraproject.article.service.BrowseServiceImpl.java

/**
 * Get articles in the given date range, from newest to oldest, of the given article type(s). One "page" of articles
 * will be returned, i.e. articles pageNum * pageSize .. (pageNum + 1) * pageSize - 1 . Note that less than a pageSize
 * articles may be returned, either because it's the end of the list or because some articles are not accessible.
 * <p/>/*from  ww  w  .  j  a v a2 s.  c  o  m*/
 * Note: this method assumes the dates are truly just dates, i.e. no hours, minutes, etc.
 * <p/>
 * If the <code>articleTypes</code> parameter is null or empty, then all types of articles are returned.
 * <p/>
 * This method should never return null.
 *
 * @param params A collection filters / parameters to browse by
 * @return the articles.
 */
@Transactional(readOnly = true)
public BrowseResult getArticlesByDate(final BrowseParameters params) {

    BrowseResult result;

    if (this.useCache) {
        String mod = params.getJournalKey() + "-" + params.getStartDate().getTimeInMillis() + "-"
                + params.getEndDate().getTimeInMillis() + "-" + params.getSort();
        String cacheKey = ARTBYDATE_LIST_KEY + mod + "-" + params.getPageNum() + "-" + params.getPageSize();

        result = browseSolrCache.get(cacheKey, this.cacheTimeToLive,
                new Cache.SynchronizedLookup<BrowseResult, RuntimeException>(cacheKey.intern()) {
                    @Override
                    public BrowseResult lookup() throws RuntimeException {
                        return getArticlesByDateViaSolr(params);
                    }
                });
    } else {
        result = getArticlesByDateViaSolr(params);
    }

    return result;
}

From source file:org.wso2.carbon.event.processor.core.internal.CarbonEventProcessorService.java

@Override
public void deployExecutionPlan(String executionPlan)
        throws ExecutionPlanDependencyValidationException, ExecutionPlanConfigurationException {
    //validate execution plan
    org.wso2.siddhi.query.api.ExecutionPlan parsedExecutionPlan;
    try {//from w  w  w  .j  a  va2 s  .c  om
        parsedExecutionPlan = SiddhiCompiler.parse(executionPlan);
        String executionPlanName = AnnotationHelper
                .getAnnotationElement(EventProcessorConstants.ANNOTATION_NAME_NAME, null,
                        parsedExecutionPlan.getAnnotations())
                .getValue();

        if (isExecutionPlanAlreadyExist(executionPlanName)) {
            throw new ExecutionPlanConfigurationException(
                    executionPlanName + " already registered as an execution in this tenant");
        }

        String repoPath = EventProcessorUtil.getAxisConfiguration().getRepository().getPath();
        File directory = new File(repoPath);
        if (!directory.exists()) {
            synchronized (repoPath.intern()) {
                if (!directory.mkdir()) {
                    throw new ExecutionPlanConfigurationException(
                            "Cannot create directory to add tenant specific " + "execution plan : "
                                    + executionPlanName);
                }
            }
        }

        String eventProcessorConfigPath = directory.getAbsolutePath() + File.separator
                + EventProcessorConstants.EP_ELE_DIRECTORY;
        directory = new File(eventProcessorConfigPath);
        if (!directory.exists()) {
            synchronized (eventProcessorConfigPath.intern()) {
                if (!directory.mkdir()) {
                    throw new ExecutionPlanConfigurationException(
                            "Cannot create directory " + EventProcessorConstants.EP_ELE_DIRECTORY
                                    + " to add tenant specific  execution plan :" + executionPlanName);
                }
            }
        }

        validateToRemoveInactiveExecutionPlanConfiguration(executionPlanName);
        EventProcessorConfigurationFilesystemInvoker.save(executionPlan, executionPlanName,
                executionPlanName + EventProcessorConstants.SIDDHIQL_EXTENSION);

    } catch (SiddhiParserException re) {
        throw new ExecutionPlanConfigurationException(
                "Couldn't parse execution plan: \n" + executionPlan + "\n");
    }
}

From source file:org.protempa.backend.dsb.filter.PropertyValueFilter.java

/**
 * Instantiate with the proposition ids to which this filter applies,
 * the property to which this filter applies, the operator and a value.
 *
 * @param propositionIds a proposition id {@link String[]}.
 * @param property a property name {@link String}.
 * Cannot be <code>null</code>.
 * @param valueComparator a {@link ValueComparator} operator. Cannot be
 * <code>null</code>.//ww w.j  a v  a  2 s.  c  o  m
 * @param value a {@link Value}. If a {@link ListValue}, it cannot contain
 * nested lists. Cannot be <code>null</code>.
 * @param negation a <code>boolean</code>, <code>false</code> means find
 * propositions that do not have the specified value.
 */
public PropertyValueFilter(String[] propositionIds, String property, ValueComparator valueComparator,
        Value... values) {
    super(propositionIds);
    if (property == null)
        throw new IllegalArgumentException("property cannot be null");
    if (valueComparator == null) {
        throw new IllegalArgumentException("valueComparator cannot be null");
    }
    if (valueComparator == ValueComparator.UNKNOWN) {
        throw new IllegalArgumentException("Cannot use UNKNOWN value comparator here");
    }
    if (values.length > 1) {
        if (valueComparator != ValueComparator.IN && valueComparator != ValueComparator.NOT_IN) {
            throw new IllegalArgumentException(
                    "Multiple value arguments are only allowed if the value comparator is IN or NOT_IN");
        }
    }
    for (Value val : values) {
        if (val instanceof ValueList) {
            throw new IllegalArgumentException("values connnot contain any ListValues");
        }
    }
    this.property = property.intern();
    this.valueComparator = valueComparator;
    this.values = values.clone();
}

From source file:org.jajuk.base.Collection.java

/**
 * Handle albums. //from  w  w  w. ja v  a  2  s .  c  om
 *
 * @param attributes 
 * @param idIndex 
 */
private void handleAlbums(Attributes attributes, int idIndex) {
    String sID = attributes.getValue(idIndex).intern();
    String sItemName = attributes.getValue(Const.XML_NAME).intern();
    String sAttributeAlbumArtist = attributes.getValue(Const.XML_ALBUM_ARTIST);
    if (sAttributeAlbumArtist != null) {
        // Make sure to store the string into the String pool to save memory
        sAttributeAlbumArtist.intern();//NOSONAR
    }
    long lItemDiscID = 0;
    String sAttributeDiskId = attributes.getValue(Const.XML_ALBUM_DISC_ID);
    if (sAttributeDiskId != null) {
        lItemDiscID = Long.parseLong(sAttributeDiskId);
    }
    // UPGRADE test
    String sRightID = sID;
    if (needCheckID) {
        sRightID = AlbumManager.createID(sItemName, lItemDiscID).intern();
        if (sRightID == sID) {//NOSONAR
            needCheckID = UpgradeManager.isUpgradeDetected() || SessionService.isTestMode();
        } else {
            Log.debug("** Wrong album Id, upgraded: " + sItemName);
            hmWrongRightAlbumID.put(sID, sRightID);
        }
    }
    Album album = AlbumManager.getInstance().registerAlbum(sRightID, sItemName, lItemDiscID);
    if (album != null) {
        album.populateProperties(attributes);
    }
}

From source file:org.jajuk.base.Collection.java

/**
 * Handle tracks. /*from  www .ja  v a  2s  . com*/
 *
 * @param attributes 
 * @param idIndex 
 *
 * @throws ParseException the parse exception
 */
private void handleTracks(Attributes attributes, int idIndex) throws ParseException {
    String sID = attributes.getValue(idIndex).intern();
    String sTrackName = attributes.getValue(Const.XML_TRACK_NAME);
    // album
    String sAlbumID = attributes.getValue(Const.XML_TRACK_ALBUM).intern();
    if ((hmWrongRightAlbumID.size() > 0) && (hmWrongRightAlbumID.containsKey(sAlbumID))) {
        sAlbumID = hmWrongRightAlbumID.get(sAlbumID);
    }
    Album album = AlbumManager.getInstance().getAlbumByID(sAlbumID);
    // Genre
    String sGenreID = attributes.getValue(Const.XML_TRACK_GENRE).intern();
    if ((hmWrongRightGenreID.size() > 0) && (hmWrongRightGenreID.containsKey(sGenreID))) {
        sGenreID = hmWrongRightGenreID.get(sGenreID);
    }
    Genre genre = GenreManager.getInstance().getGenreByID(sGenreID);
    // Year
    String sYearID = attributes.getValue(Const.XML_TRACK_YEAR).intern();
    Year year = YearManager.getInstance().getYearByID(sYearID);
    // For jajuk < 1.4
    if (year == null) {
        year = YearManager.getInstance().registerYear(sYearID, sYearID);
    }
    // Artist
    String sArtistID = attributes.getValue(Const.XML_TRACK_ARTIST).intern();
    if ((hmWrongRightArtistID.size() > 0) && (hmWrongRightArtistID.containsKey(sArtistID))) {
        sArtistID = hmWrongRightArtistID.get(sArtistID);
    }
    Artist artist = ArtistManager.getInstance().getArtistByID(sArtistID);
    // Album-artist (not a constructor level property)
    String sAlbumArtist = attributes.getValue(Const.XML_ALBUM_ARTIST);
    if (StringUtils.isNotBlank(sAlbumArtist)) {
        sAlbumArtist = sAlbumArtist.intern();
    }
    if ((hmWrongRightAlbumArtistID.size() > 0) && (hmWrongRightAlbumArtistID.containsKey(sAlbumArtist))) {
        sAlbumArtist = hmWrongRightAlbumArtistID.get(sAlbumArtist);
    }
    // Note that when upgrading from jajuk < 1.9, album artists field is alway null, call on the
    // next line always return null
    AlbumArtist albumArtist = AlbumArtistManager.getInstance().getAlbumArtistByID(sAlbumArtist);
    if (albumArtist == null) {
        // we force album artist to this default, a deep scan will be required to get actual values
        albumArtist = AlbumArtistManager.getInstance().registerAlbumArtist(Const.UNKNOWN_ARTIST);
    }
    // Length
    long length = UtilString.fastLongParser(attributes.getValue(Const.XML_TRACK_LENGTH));
    // Type
    String typeID = attributes.getValue(Const.XML_TYPE).intern();
    if (needCheckConversions) {
        if (CONVERSION.containsKey(typeID)) {
            typeID = CONVERSION.get(typeID);
        } else {
            needCheckConversions = false;
        }
    }
    Type type = TypeManager.getInstance().getTypeByID(typeID);
    // more checkups
    if (album == null || artist == null) {
        return;
    }
    if (genre == null || type == null) {
        return;
    }
    // Idem for order
    long lOrder = 0l;
    try {
        lOrder = UtilString.fastLongParser(attributes.getValue(Const.XML_TRACK_ORDER));
    } catch (Exception e) {
        if (Log.isDebugEnabled()) {
            // wrong format
            Log.debug(Messages.getString("Error.137") + ":" + sTrackName); // wrong
        }
    }
    // Idem for disc number
    long lDiscNumber = 0l;
    if (attributes.getValue(Const.XML_TRACK_DISC_NUMBER) != null) {
        try {
            lDiscNumber = UtilString.fastLongParser(attributes.getValue(Const.XML_TRACK_DISC_NUMBER));
        } catch (Exception e) {
            if (Log.isDebugEnabled()) {
                // wrong format
                Log.debug(Messages.getString("Error.137") + ":" + sTrackName);
            }
        }
    }
    // UPGRADE test
    String sRightID = sID;
    if (needCheckID) {
        sRightID = TrackManager
                .createID(sTrackName, album, genre, artist, length, year, lOrder, type, lDiscNumber).intern();
        if (sRightID == sID) {//NOSONAR
            needCheckID = UpgradeManager.isUpgradeDetected() || SessionService.isTestMode();
        } else {
            Log.debug("** Wrong Track Id, upgraded: " + sTrackName);
            hmWrongRightTrackID.put(sID, sRightID);
        }
    }
    Track track = TrackManager.getInstance().registerTrack(sRightID, sTrackName, album, genre, artist, length,
            year, lOrder, type, lDiscNumber);
    TrackManager.getInstance().changeTrackRate(track,
            UtilString.fastLongParser(attributes.getValue(Const.XML_TRACK_RATE)));
    track.setHits(UtilString.fastLongParser(attributes.getValue(Const.XML_TRACK_HITS)));
    // only set discovery date if it is available in the file
    if (attributes.getValue(Const.XML_TRACK_DISCOVERY_DATE) != null) {
        // Date format should be OK
        Date dAdditionDate = additionFormatter.parse(attributes.getValue(Const.XML_TRACK_DISCOVERY_DATE));
        track.setDiscoveryDate(dAdditionDate);
    }
    String sComment = attributes.getValue(Const.XML_TRACK_COMMENT);
    if (sComment == null) {
        sComment = "";
    }
    track.setComment(sComment.intern());
    track.setAlbumArtist(albumArtist);
    track.populateProperties(attributes);
}