/** * Interns all the strings in the given array in place, * returning the same array. */ public static String[] internStringsInArray(String[] strings) { for (int i = 0; i < strings.length; i++) { strings[i] = weakIntern(strings[i]); } return strings; }
/** * Set the hosts hosting this block */ public void setHosts(String[] hosts) throws IOException { if (hosts == null) { this.hosts = EMPTY_STR_ARRAY; } else { this.hosts = StringInterner.internStringsInArray(hosts); } }
/** * Test the same strong reference is returned for any * of string instances that are equal to each other. */ @Test public void testStrongIntern() { String strongInternLiteralABC = strongIntern("ABC"); String strongInternSubstringABC = strongIntern("ABCDE".substring(0,3)); String strongInternHeapABC = strongIntern(new String("ABC")); assertSame(strongInternLiteralABC, strongInternSubstringABC); assertSame(strongInternLiteralABC, strongInternHeapABC); assertSame(strongInternSubstringABC, strongInternHeapABC); }
/** * Test the same strong reference is returned for any * of string instances that are equal to each other. */ @Test public void testStrongIntern() { String strongInternLiteralABC = strongIntern("ABC"); String strongInternSubstringABC = strongIntern("ABCDE".substring(0,3)); String strongInternHeapABC = strongIntern(new String("ABC")); assertSame(strongInternLiteralABC, strongInternSubstringABC); assertSame(strongInternLiteralABC, strongInternHeapABC); assertSame(strongInternSubstringABC, strongInternHeapABC); }
/** * Copied method from org.apache.hadoop.yarn.util.Apps. * It was broken by YARN-1824 (2.4.0) and fixed for 2.4.1 * by https://issues.apache.org/jira/browse/YARN-1931 */ public static void addToEnvironment(Map<String, String> environment, String variable, String value) { String val = environment.get(variable); if (val == null) { val = value; } else { val = val + File.pathSeparator + value; } environment.put(StringInterner.weakIntern(variable), StringInterner.weakIntern(val)); }
/** * Set the names (host:port) hosting this block */ public void setNames(String[] names) throws IOException { if (names == null) { this.names = EMPTY_STR_ARRAY; } else { this.names = StringInterner.internStringsInArray(names); } }
case "name": if (token.length() > 0) { confName = StringInterner.weakIntern(tokenStr.trim()); confValue = StringInterner.weakIntern(tokenStr); break; case "source": confSource.add(StringInterner.weakIntern(tokenStr)); break; case "tag": if (token.length() > 0) { confTag = StringInterner.weakIntern(tokenStr);
/** * Set the hosts hosting a cached replica of this block */ public void setCachedHosts(String[] cachedHosts) { if (cachedHosts == null) { this.cachedHosts = EMPTY_STR_ARRAY; } else { this.cachedHosts = StringInterner.internStringsInArray(cachedHosts); } }
private void handleStartProperty() { confName = null; confValue = null; confFinal = false; confTag = null; confSource.clear(); // First test for short format configuration int attrCount = reader.getAttributeCount(); for (int i = 0; i < attrCount; i++) { String propertyAttr = reader.getAttributeLocalName(i); if ("name".equals(propertyAttr)) { confName = StringInterner.weakIntern( reader.getAttributeValue(i)); } else if ("value".equals(propertyAttr)) { confValue = StringInterner.weakIntern( reader.getAttributeValue(i)); } else if ("final".equals(propertyAttr)) { confFinal = "true".equals(reader.getAttributeValue(i)); } else if ("source".equals(propertyAttr)) { confSource.add(StringInterner.weakIntern( reader.getAttributeValue(i))); } else if ("tag".equals(propertyAttr)) { confTag = StringInterner .weakIntern(reader.getAttributeValue(i)); } } }
/** * Set the network topology paths of the hosts */ public void setTopologyPaths(String[] topologyPaths) throws IOException { if (topologyPaths == null) { this.topologyPaths = EMPTY_STR_ARRAY; } else { this.topologyPaths = StringInterner.internStringsInArray(topologyPaths); } }
Element field = (Element)fieldNode; if ("name".equals(field.getTagName()) && field.hasChildNodes()) attr = StringInterner.weakIntern( ((Text)field.getFirstChild()).getData().trim()); if ("value".equals(field.getTagName()) && field.hasChildNodes()) value = StringInterner.weakIntern( ((Text)field.getFirstChild()).getData()); if ("final".equals(field.getTagName()) && field.hasChildNodes()) finalParameter = "true".equals(((Text)field.getFirstChild()).getData()); if ("source".equals(field.getTagName()) && field.hasChildNodes()) source.add(StringInterner.weakIntern( ((Text)field.getFirstChild()).getData()));
public void setStorageIds(String[] storageIds) { if (storageIds == null) { this.storageIds = EMPTY_STR_ARRAY; } else { this.storageIds = StringInterner.internStringsInArray(storageIds); } }
String propertyAttr = reader.getAttributeLocalName(i); if ("name".equals(propertyAttr)) { confName = StringInterner.weakIntern( reader.getAttributeValue(i)); } else if ("value".equals(propertyAttr)) { confValue = StringInterner.weakIntern( reader.getAttributeValue(i)); } else if ("final".equals(propertyAttr)) { confFinal = "true".equals(reader.getAttributeValue(i)); } else if ("source".equals(propertyAttr)) { confSource.add(StringInterner.weakIntern( reader.getAttributeValue(i))); case "name": if (token.length() > 0) { confName = StringInterner.weakIntern(token.toString().trim()); confValue = StringInterner.weakIntern(token.toString()); break; case "source": confSource.add(StringInterner.weakIntern(token.toString())); break; case "include":
this.names = EMPTY_STR_ARRAY; } else { this.names = StringInterner.internStringsInArray(names); this.hosts = StringInterner.internStringsInArray(hosts); this.cachedHosts = StringInterner.internStringsInArray(cachedHosts); this.topologyPaths = StringInterner.internStringsInArray(topologyPaths); this.storageIds = StringInterner.internStringsInArray(storageIds);
public GroupInputSpec(String groupName, List<String> groupVertices, InputDescriptor inputDescriptor) { this.groupName = StringInterner.weakIntern(groupName); this.groupVertices = groupVertices; this.mergedInputDescriptor = inputDescriptor; }
public InputSpec(String sourceVertexName, InputDescriptor inputDescriptor, int physicalEdgeCount) { this.sourceVertexName = StringInterner.weakIntern(sourceVertexName); this.inputDescriptor = inputDescriptor; this.physicalEdgeCount = physicalEdgeCount; }
public AbstractCounterGroup(String name, String displayName, Limits limits) { this.name = StringInterner.weakIntern(name); this.displayName = StringInterner.weakIntern(displayName); this.limits = limits; }
public OutputSpec(String destinationVertexName, OutputDescriptor outputDescriptor, int physicalEdgeCount) { this.destinationVertexName = StringInterner.weakIntern(destinationVertexName); this.outputDescriptor = outputDescriptor; this.physicalEdgeCount = physicalEdgeCount; }
@Override public void setDisplayName(String displayName) { this.displayName = StringInterner.weakIntern(displayName); }
public GenericCounter(String name, String displayName, long value) { this.name = StringInterner.weakIntern(name); this.displayName = StringInterner.weakIntern(displayName); this.value.set(value); }