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.deployment.synchronizer.DeploymentSynchronizationManager.java

/**
 * Creates a new DeploymentSynchronizer instance using the provided parameters. A given file path
 * may only have one DeploymentSynchronizer engaged on it. Any attempts to create multiple
 * DeploymentSynchronizer instances on the same file path will result in an IllegalStateException.
 * This method only creates DeploymentSynchronizer instances. The caller should take action
 * to customize and further initialize the repository as required.
 *
 * @param artifactRepository ArtifactRepository representing the remote repository
 * @param filePath File path in the local file system
 * @return a DeploymentSynchronizer instance
 *///from ww w. j  a va  2 s . c o  m
public DeploymentSynchronizer createSynchronizer(int tenantId, ArtifactRepository artifactRepository,
        String filePath) {

    // We synchronize based on filePath.intern() to make sure that two threads don't
    // access the following logic with the same path. That could lead to multiple
    // synchronizers getting engaged on the same file path.
    synchronized (filePath.intern()) {
        if (synchronizers.containsKey(filePath)) {
            log.warn("A deployment synchronizer is already engaged for the " + "file system at: " + filePath);
            DeploymentSynchronizer synchronizer = synchronizers.remove(filePath);
            if (synchronizer != null) {
                synchronizer.stop();
            }
        }

        DeploymentSynchronizer synchronizer = new DeploymentSynchronizer(tenantId, artifactRepository,
                filePath);
        synchronizers.put(filePath, synchronizer);
        return synchronizer;
    }
}

From source file:edu.cornell.med.icb.learning.tools.svmlight.EvaluationMeasure.java

public double getPerformanceValueAverage(final String measureName) {
    double sum = 0;
    final DoubleList values = name2Values.get(measureName.intern());
    if (values == null) {

        return Double.NaN;
    }//from  ww w  .j a  v a 2s.c  om
    for (final double value : values) {
        sum += value;
    }

    final double value = sum / values.size();
    if (LOG.isTraceEnabled()) {
        LOG.trace(String.format(
                "returning average value %f for measure %s, " + "averaged over %d distinct values: %s.", value,
                measureName, values.size(), ArrayUtils.toString(values)));

    }

    return value;

}

From source file:com.qwazr.library.audio.AudioParser.java

@Override
public void parseContent(final MultivaluedMap<String, String> parameters, final InputStream inputStream,
        final String extension, final String mimeType, final ParserResultBuilder resultBuilder)
        throws Exception {
    String format = getParameterValue(parameters, FORMAT, 0);
    if (StringUtils.isEmpty(format))
        format = extension;/*  www .  jav a 2  s.  c  o  m*/
    if (StringUtils.isEmpty(format) && mimeType != null)
        format = MIMEMAP.get(mimeType.intern());
    if (StringUtils.isEmpty(format))
        throw new Exception("The format is not found");
    final Path tempFile = ParserAbstract.createTempFile(inputStream, '.' + format);
    try {
        parseContent(parameters, tempFile, extension, mimeType, resultBuilder);
    } finally {
        Files.deleteIfExists(tempFile);
    }
}

From source file:org.protempa.valueset.ValueSet.java

public ValueSet(String id, String displayName, OrderedValue lowerBound, OrderedValue upperBound,
        SourceId sourceId) {//  w w w .j  ava 2  s .c om
    if (id == null) {
        throw new IllegalArgumentException("id cannot be null");
    }
    this.id = id.intern();
    this.displayName = displayName;
    this.lowerBound = lowerBound;
    this.upperBound = upperBound;
    this.valueSetElements = EMPTY_VALUE_SET_ELT_ARRAY;
    this.values = new HashMap<>();
    this.valuesKeySet = this.values.keySet();
    if (sourceId == null) {
        this.sourceId = NotRecordedSourceId.getInstance();
    } else {
        this.sourceId = sourceId;
    }
    this.ordered = true;
}

From source file:org.protempa.dest.table.Link.java

/**
 * Specifies a link with proposition ids, constraints, 
 * an index range for selecting from the list of propositions that match 
 * the proposition ids and constraints, and a comparator for ordering the 
 * list.//from  w ww.  jav a 2s.c o m
 * 
 * @param propositionIds
 *            a {@link String[]} of proposition ids.
 * @param constraints
 *            a {@link PropertyConstraint[]} of constraints.
 * @param comparator
 *            a {@link Comparator<Proposition>}.
 * @param fromIndex
 *            the lower bound of the range (a negative number or zero is
 *            interpreted as the beginning of the list).
 * @param toIndex
 *            the upper bound of the range exclusive (a negative number is
 *            interpreted as the end of the list).
 */
Link(String[] propositionIds, PropertyConstraint[] constraints, Comparator<Proposition> comparator,
        int fromIndex, int toIndex) {
    if (propositionIds == null) {
        this.propIdsAsSet = Collections.emptySet();
    } else {
        ProtempaUtil.checkArrayForNullElement(propositionIds, "propositionIds");
        this.propIdsAsSet = new HashSet<>();
        for (String propId : propositionIds) {
            this.propIdsAsSet.add(propId.intern());
        }
    }
    if (constraints == null) {
        this.constraints = EMPTY_PROPERTY_CONSTRAINT_ARR;
    } else {
        ProtempaUtil.checkArrayForNullElement(constraints, "constraints");
        this.constraints = constraints.clone();
    }
    if (fromIndex >= 0 && toIndex >= 0 && fromIndex >= toIndex) {
        throw new IllegalArgumentException("fromIndex cannot be greater than or equal to toIndex");
    }

    this.comparator = comparator;
    this.fromIndex = fromIndex;
    this.toIndex = toIndex;
}

From source file:org.wso2.andes.server.slot.SlotManager.java

/**
 * Remove slot entry from slotAssignment map
 *
 * @param queueName name of the queue which is owned by the slot to be deleted
 * @param emptySlot reference of the slot to be deleted
 *///from  w ww  .ja v a2 s. c  om
public void deleteSlot(String queueName, Slot emptySlot, String nodeId) {
    String lockKey = nodeId + SlotManager.class;
    synchronized (lockKey.intern()) {
        HashMap<String, List<String>> queueToSlotMap = null;
        HashmapStringListWrapper wrapper = slotAssignmentMap.get(nodeId);
        if (wrapper != null) {
            queueToSlotMap = wrapper.getStringListHashMap();
        }
        if (queueToSlotMap != null) {
            ArrayList<String> currentSlotList = (ArrayList<String>) queueToSlotMap.get(queueName);
            if (currentSlotList != null) {
                com.google.gson.Gson gson = new GsonBuilder().create();
                currentSlotList.remove(gson.toJson(emptySlot));
                queueToSlotMap.put(queueName, currentSlotList);
                wrapper.setStringListHashMap(queueToSlotMap);
                slotAssignmentMap.set(nodeId, wrapper);
            }
            if (log.isDebugEnabled()) {
                log.debug("Unassigned slot " + emptySlot.getStartMessageId() + " - "
                        + emptySlot.getEndMessageId() + "owned by node: " + nodeId + "");
            }
        }
    }
}

From source file:org.wso2.andes.server.slot.SlotManager.java

/**
 * Update the slot assignment map when a slot is assigned
 *
 * @param queueName     Name of the queue
 * @param allocatedSlot Slot object which is allocated to a particular node
 *///from  w ww.  j a  v  a  2s .co  m
private void updateSlotAssignmentMap(String queueName, Slot allocatedSlot, String nodeId) {
    ArrayList<String> currentSlotList;
    HashMap<String, List<String>> queueToSlotMap;
    HashmapStringListWrapper wrapper = slotAssignmentMap.get(nodeId);
    if (wrapper == null) {
        wrapper = new HashmapStringListWrapper();
        queueToSlotMap = new HashMap<String, List<String>>();
        wrapper.setStringListHashMap(queueToSlotMap);
        slotAssignmentMap.putIfAbsent(nodeId, wrapper);
    }
    //Lock is used because this method will be called by multiple nodes at the same time
    String lockKey = nodeId + SlotManager.class;
    synchronized (lockKey.intern()) {
        wrapper = slotAssignmentMap.get(nodeId);
        queueToSlotMap = wrapper.getStringListHashMap();
        currentSlotList = (ArrayList<String>) queueToSlotMap.get(queueName);
        if (currentSlotList == null) {
            currentSlotList = new ArrayList<String>();
        }
        com.google.gson.Gson gson = new GsonBuilder().create();
        currentSlotList.add(gson.toJson(allocatedSlot));
        queueToSlotMap.put(queueName, currentSlotList);
        wrapper.setStringListHashMap(queueToSlotMap);
        slotAssignmentMap.set(nodeId, wrapper);
    }

}

From source file:org.wso2.andes.mqtt.connectors.InMemoryConnector.java

/**
 * handles removal of subscriptions//from  w  ww. java2  s.co m
 *
 * @param subscribedTopic the name of the topic subscription
 * @param mqttClientID    the unique client identifier
 * @throws MQTTException
 */
private void handleSubscriptionRemoval(String subscribedTopic, String mqttClientID) throws MQTTException {
    List<String> subscribers = messageSubscription.get(subscribedTopic);

    if (null == subscribers) {
        throw new MQTTException("There're no subscribers for topic " + subscribedTopic);
    }

    subscribers.remove(mqttClientID.intern());

    //After removal if the subscriber list is empty let's remove the subscription itself off
    if (subscribers.isEmpty()) {
        messageSubscription.remove(subscribedTopic);
    }

    if (log.isDebugEnabled()) {
        log.debug("Subscriber with id " + mqttClientID + " removed from topic " + subscribedTopic);
    }

}

From source file:org.diorite.impl.permissions.pattern.ExtendedPermissionPatternImpl.java

/**
 * Construct new advanced permission pattern.
 *
 * @param patternValue value of permission.
 * @param groups       special groups used by this pattern.
 *//*from ww  w  .j  av a2s .co m*/
public ExtendedPermissionPatternImpl(String patternValue, final SpecialGroup<?, ?>[] groups) {
    Validate.isTrue(groups.length > 0, "Advanced pattern must use special groups.");
    patternValue = patternValue.intern();
    this.patternValue = patternValue;
    String temp = patternValue;
    final List<String> parts = new ArrayList<>(10);
    this.groups = new SpecialGroupEntry[groups.length];
    try {
        int lastPart = 0;
        String rest = null;
        for (int i = 0, groupsLength = groups.length; i < groupsLength; i++) {
            final SpecialGroup<?, ?> group = groups[i];
            final String pat = group.getGroupPattern();
            final int index = temp.indexOf(pat);
            if (index == -1) {
                throw new RuntimeException("Pattern value doesn't match all special groups.");
            }
            this.groups[i] = new SpecialGroupEntry(group, index);
            final String part = temp.substring(lastPart, index);
            lastPart = index;
            if (!part.isEmpty()) {
                parts.add(part);
            }
            parts.add(null);
            rest = temp.substring(index + pat.length());
            temp = temp.substring(0, index) + rest;
        }
        if ((rest != null) && !rest.isEmpty()) {
            parts.add(rest);
        }
    } catch (final Exception e) {
        throw new RuntimeException("Pattern value doesn't match all special groups.", e);
    }
    this.permMap = parts.toArray(new String[parts.size()]);
    this.basePermission = temp;
}

From source file:org.wso2.carbon.appfactory.core.governance.RxtManager.java

/**
 * This method will add the given newValue as the value of the key,
 * replacing the existing value/* w  w  w  .j a va  2 s . c o  m*/
 *
 * @param applicationId the Id of the current application
 * @param version       version of the current application
 * @param key           the attribute key that is been updated
 * @param newValue      the new value of the attribute key
 * @throws AppFactoryException
 */
public void updateAppVersionForUserRxt(String applicationId, String version, String userName, String key[],
        String newValue[], String tenantDomain) throws AppFactoryException {

    // creating a unique key for an application in a tenant
    String tenant_appLock = tenantDomain.concat("_").concat(applicationId).concat(userName);

    synchronized (tenant_appLock.intern()) {
        GenericArtifactImpl artifact = getAppVersionForUserArtifact(applicationId, version, userName,
                tenantDomain);
        if (log.isDebugEnabled()) {
            log.debug("Updating application version for user rxt with keys : " + Arrays.toString(key)
                    + " values : " + Arrays.toString(newValue) + "applicationId : " + applicationId
                    + " version : " + version + " in tenant domain : " + tenantDomain);
        }
        try {
            for (int i = 0; i < key.length; i++) {
                String currentVal = artifact.getAttribute(key[i]);
                if (currentVal == null) {
                    artifact.addAttribute(key[i], newValue[i]);
                } else {
                    artifact.setAttribute(key[i], newValue[i]);
                }
            }
            UserRegistry userRegistry = getUserRegistry(tenantDomain);
            GovernanceUtils.loadGovernanceArtifacts(userRegistry);
            GenericArtifactManager artifactManager = new GenericArtifactManager(userRegistry, "repouser");
            artifactManager.updateGenericArtifact(artifact);
        } catch (RegistryException e) {
            String errorMsg = "Error while updating the artifact " + applicationId;
            log.error(errorMsg, e);
            throw new AppFactoryException(errorMsg, e);
        } catch (Exception e) {
            String errorMsg = String.format("Unable to get tenant id for %s", tenantDomain);
            log.error(errorMsg, e);
            throw new AppFactoryException(errorMsg, e);
        }
    }

}