List of usage examples for java.lang String intern
public native String intern();
From source file:com.bytelightning.opensource.pokerface.ScriptHelperImpl.java
/** * @see AddMimeEntry/*from w w w . jav a2 s . co m*/ */ private static void AddMimeEntryImpl(String type, String extensions) { LinkedHashSet<String> extSet = new LinkedHashSet<String>(); MimeEntry entry = MimeHashTable.find(type); if (entry == null) entry = new sun.net.www.MimeEntry(type.intern()); // Ensure the type is an interned string entry.setType(type.intern()); String[] existing = entry.getExtensions(); if (existing != null) for (String ext : existing) extSet.add(ext); String[] additional = extensions.split(","); for (int i = 0; i < additional.length; i++) { additional[i] = additional[i].trim().toLowerCase(); if (additional[i].length() == 0) throw new RuntimeException("Invalid mime extensions for: " + type); if (additional[i].charAt(0) != '.') throw new RuntimeException("mime extensions must start with a '.' (" + type + ")"); extSet.add(additional[i]); } StringBuffer sb = new StringBuffer(); for (String ext : extSet) { if (sb.length() > 0) sb.append(','); sb.append(ext); } entry.setExtensions(sb.toString()); // This little hack ensures that the MimeEntry itself has interned strings in it's list. Yes it's a trade off between bad practice and speed. String[] processed = entry.getExtensions(); for (int i = 0; i < processed.length; i++) processed[i] = processed[i].intern(); }
From source file:org.dkpro.core.udpipe.internal.UDPipe2DKPro.java
public static void convertPosLemmaMorph(Sentence sentence, Collection<Token> tokens, JCas aJCas, MappingProvider mappingProvider, boolean internTags) { CAS cas = aJCas.getCas();/*from w w w. ja v a 2 s . c o m*/ int i = 1; // the first tag is <root> for (Token t : tokens) { Word w = sentence.getWords().get(i); String xtag = w.getXpostag(); String utag = w.getUpostag(); // For Norwegian xtag is not provided. It is a blank string. // So the value of Utag is used as an replacement. if (xtag.length() == 0 && utag.length() > 0) xtag = utag; // Convert the tag produced by the tagger to an UIMA type, create an annotation // of this type, and add it to the document. Type posTag = mappingProvider.getTagType(xtag); POS posAnno = (POS) cas.createAnnotation(posTag, t.getBegin(), t.getEnd()); // To save memory, we typically intern() tag strings posAnno.setPosValue(internTags ? xtag.intern() : xtag); if (utag == null) { posAnno.setCoarseValue( posAnno.getClass().equals(POS.class) ? null : posAnno.getType().getShortName().intern()); } else { posAnno.setCoarseValue(internTags ? utag.intern() : utag); } posAnno.addToIndexes(); // Connect the POS annotation to the respective token annotation t.setPos(posAnno); if (StringUtils.isNotBlank(w.getLemma())) { Lemma lemma = new Lemma(aJCas, t.getBegin(), t.getEnd()); lemma.setValue(w.getLemma()); lemma.addToIndexes(); t.setLemma(lemma); } if (StringUtils.isNotBlank(w.getForm())) { MorphologicalFeatures morph = new MorphologicalFeatures(aJCas, t.getBegin(), t.getEnd()); morph.setValue(w.getFeats()); morph.addToIndexes(); t.setMorph(morph); } i++; } }
From source file:com.salas.bb.utils.StringUtils.java
/** * Safely intern's a string.// w w w . j a va 2s .c om * * @param s string. * * @return intern'ed version. */ public static String intern(String s) { return s == null ? null : s.intern(); }
From source file:org.wso2.carbon.utils.deployment.GhostDeployerUtils.java
/** * Removes the given ghost service and deploys the actual service. Service file name is * extracted from the Ghost Service and then the actual service is deployed. Finally the * actual service is returned./*from ww w .j a v a2 s . c o m*/ * * @param axisConfig - AxisConfiguration instance * @param ghostService - Existing Ghost service * @return - newly deployed real service * @throws org.apache.axis2.AxisFault - On errors while removing existing service */ public static AxisService deployActualService(AxisConfiguration axisConfig, AxisService ghostService) throws AxisFault { AxisService newService = null; /** * There can be multiple requests for the same ghost service depending on the level * of concurrency. Therefore we have to synchronize on the ghost service instance. */ String serviceName = ghostService.getName(); synchronized (serviceName.intern()) { // there can be situations in which the actual service is already deployed and // available in the axisConfig AxisService axisConfigService = axisConfig.getService(serviceName); if (axisConfigService == null) { return null; } Parameter actualGhostParam = axisConfigService.getParameter(CarbonConstants.GHOST_SERVICE_PARAM); if (actualGhostParam == null || "false".equals(actualGhostParam.getValue())) { // if the service from axisConfig is not a ghost, return it newService = axisConfigService; } else { GhostArtifactRepository ghostArtifactRepository = GhostDeployerUtils .getGhostArtifactRepository(axisConfig); //TODO use a canonical path? DeploymentFileDataWrapper dfd = ghostArtifactRepository .getDeploymentFileData(axisConfigService.getFileName().getPath()); if (dfd != null) { // remove the existing service log.info("Removing Ghost Service and loading actual service : " + serviceName); AxisServiceGroup existingSG = (AxisServiceGroup) axisConfigService.getParent(); existingSG.addParameter(CarbonConstants.KEEP_SERVICE_HISTORY_PARAM, PARAMETER_VALUE_TRUE); // Add all services in the group to the ghost list Map<String, AxisService> transitGhostList = getTransitGhostServicesMap(axisConfig); for (Iterator<AxisService> servicesItr = existingSG.getServices(); servicesItr.hasNext();) { AxisService service = servicesItr.next(); transitGhostList.put(service.getName(), service); } String serviceGroupName = existingSG.getServiceGroupName(); if (axisConfig.getServiceGroup(serviceGroupName) != null) { axisConfig.removeServiceGroup(serviceGroupName); } if (axisConfig.getService(serviceName) != null) { axisConfig.removeService(serviceName); } // deploy the new service dfd.getDeploymentFileData().deploy(); newService = axisConfig.getService(serviceName); // Remove all services in the new group from the ghost list AxisServiceGroup newSG = (AxisServiceGroup) newService.getParent(); for (Iterator<AxisService> servicesItr = newSG.getServices(); servicesItr.hasNext();) { AxisService service = servicesItr.next(); transitGhostList.remove(service.getName()); } } } updateLastUsedTime(newService); } return newService; }
From source file:org.apache.hadoop.mapreduce.v2.jobhistory.JobHistoryUtils.java
/** * Gets the timestamp component based on millisecond time. * @param millisecondTime/*from w ww . j av a 2s . co m*/ * @return the timestamp component based on millisecond time */ public static String timestampDirectoryComponent(long millisecondTime) { Calendar timestamp = Calendar.getInstance(); timestamp.setTimeInMillis(millisecondTime); String dateString = null; dateString = String.format(TIMESTAMP_DIR_FORMAT, timestamp.get(Calendar.YEAR), // months are 0-based in Calendar, but people will expect January to // be month #1. timestamp.get(Calendar.MONTH) + 1, timestamp.get(Calendar.DAY_OF_MONTH)); dateString = dateString.intern(); return dateString; }
From source file:com.openAtlas.bundleInfo.maker.PackageLite.java
private static String buildClassName(String str, CharSequence charSequence) { if (charSequence == null || charSequence.length() <= 0) { System.out.println("Empty class name in package " + str); return null; }/* w w w .j av a 2s. co m*/ String obj = charSequence.toString(); char charAt = obj.charAt(0); if (charAt == '.') { return (str + obj).intern(); } if (obj.indexOf(46) < 0) { StringBuilder stringBuilder = new StringBuilder(str); stringBuilder.append('.'); stringBuilder.append(obj); return stringBuilder.toString().intern(); } else if (charAt >= 'a' && charAt <= 'z') { return obj.intern(); } else { System.out.println("Bad class name " + obj + " in package " + str); return null; } }
From source file:org.diorite.impl.permissions.PermissionsGroupImpl.java
public PermissionsGroupImpl(final String name) { this.name = name.intern(); }
From source file:org.diorite.impl.permissions.pattern.PermissionPatternImpl.java
public PermissionPatternImpl(String permission) { permission = permission.intern(); this.permission = permission; }
From source file:org.web4thejob.studio.dom.NodeFactory.java
@Override public Element startMakingElement(String name, String namespace) { return new Element(name, namespace.intern()); }
From source file:com.qwazr.utils.json.client.JsonMultiClientAbstract.java
/** * @param url// www . ja va 2s . com * the URL of the client * @return the client which handle this URL */ public T getClientByUrl(String url) { return clientsMap.get(url.intern()); }