/** * * @param hostEntries comma separated ip/cidr/host addresses */ public MachineList(String hostEntries) { this(StringUtils.getTrimmedStringCollection(hostEntries)); }
/** * Get the comma delimited values of the <code>name</code> property as * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace. * If no such property is specified then empty <code>Collection</code> is returned. * * @param name property name. * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code> */ public Collection<String> getTrimmedStringCollection(String name) { String valueString = get(name); if (null == valueString) { Collection<String> empty = new ArrayList<String>(); return empty; } return StringUtils.getTrimmedStringCollection(valueString); }
/** * Get the comma delimited values of the <code>name</code> property as * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace. * If no such property is specified then empty <code>Collection</code> is returned. * * @param name property name. * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code> */ public Collection<String> getTrimmedStringCollection(String name) { String valueString = get(name); if (null == valueString) { Collection<String> empty = new ArrayList<String>(); return empty; } return StringUtils.getTrimmedStringCollection(valueString); }
/** * Returns a list of strings from a comma-delimited configuration value. * * @param conf configuration to check * @param name configuration property name * @param defaultValue default value if no value found for name * @return list of strings from comma-delimited configuration value, or an * empty list if not found */ private static List<String> getTrimmedStringList(Configuration conf, String name, String defaultValue) { String valueString = conf.get(name, defaultValue); if (valueString == null) { return new ArrayList<>(); } return new ArrayList<>(StringUtils.getTrimmedStringCollection(valueString)); }
/** * Get the comma delimited values of the <code>name</code> property as * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace. * If no such property is specified then empty <code>Collection</code> is returned. * * @param name property name. * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code> */ public Collection<String> getTrimmedStringCollection(String name) { String valueString = get(name); if (null == valueString) { Collection<String> empty = new ArrayList<String>(); return empty; } return StringUtils.getTrimmedStringCollection(valueString); }
/** * Build ACL from the given two Strings. * The Strings contain comma separated values. * * @param aclString build ACL from array of Strings */ private void buildACL(String[] userGroupStrings) { users = new HashSet<String>(); groups = new HashSet<String>(); for (String aclPart : userGroupStrings) { if (aclPart != null && isWildCardACLValue(aclPart)) { allAllowed = true; break; } } if (!allAllowed) { if (userGroupStrings.length >= 1 && userGroupStrings[0] != null) { users = StringUtils.getTrimmedStringCollection(userGroupStrings[0]); } if (userGroupStrings.length == 2 && userGroupStrings[1] != null) { groups = StringUtils.getTrimmedStringCollection(userGroupStrings[1]); groupsMapping.cacheGroupsAdd(new LinkedList<String>(groups)); } } }
org.apache.hadoop.util.StringUtils.getTrimmedStringCollection(userListStr)); org.apache.hadoop.util.StringUtils.getTrimmedStringCollection(groupListStr));
/** * Parse configuration setting dfs.namenode.protected.directories to retrieve * the set of protected directories. * * @param protectedDirsString * a comma separated String representing a bunch of paths. * @return a TreeSet */ @VisibleForTesting static SortedSet<String> parseProtectedDirectories( final String protectedDirsString) { return parseProtectedDirectories(StringUtils .getTrimmedStringCollection(protectedDirsString)); }
private static void setRenameReservedMapInternal(String renameReserved) { Collection<String> pairs = StringUtils.getTrimmedStringCollection(renameReserved); for (String p : pairs) { String[] pair = StringUtils.split(p, '/', '='); Preconditions.checkArgument(pair.length == 2, "Could not parse key-value pair " + p); String key = pair[0]; String value = pair[1]; Preconditions.checkArgument(DFSUtil.isReservedPathComponent(key), "Unknown reserved path " + key); Preconditions.checkArgument(DFSUtil.isValidNameForComponent(value), "Invalid rename path for " + key + ": " + value); LOG.info("Will rename reserved path " + key + " to " + value); renameReservedMap.put(key, value); } }
if (excludeDatanodes != null) { for (String host : StringUtils .getTrimmedStringCollection(excludeDatanodes)) { int idx = host.indexOf(":"); if (idx != -1) {
/** * * @param hostEntries comma separated ip/cidr/host addresses */ public MachineList(String hostEntries) { this(StringUtils.getTrimmedStringCollection(hostEntries)); }
/** * * @param hostEntries comma separated ip/cidr/host addresses */ public MachineList(String hostEntries) { this(StringUtils.getTrimmedStringCollection(hostEntries)); }
/** * * @param hostEntries comma separated ip/cidr/host addresses */ public MachineList(String hostEntries) { this(StringUtils.getTrimmedStringCollection(hostEntries)); }
/** * * @param hostEntries comma separated ip/cidr/host addresses */ public MachineList(String hostEntries) { this(StringUtils.getTrimmedStringCollection(hostEntries)); }
/** * Get the comma delimited values of property as * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace. * If no such property is specified then empty <code>Collection</code> is returned. * * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code> */ public Collection<String> getTrimmedStringCollection() { if (null == value) { return Collections.emptyList(); } return StringUtils.getTrimmedStringCollection(value); }
@Test public void testGetUniqueNonEmptyTrimmedStrings (){ final String TO_SPLIT = ",foo, bar,baz,,blah,blah,bar,"; Collection<String> col = StringUtils.getTrimmedStringCollection(TO_SPLIT); assertEquals(4, col.size()); assertTrue(col.containsAll(Arrays.asList(new String[]{"foo","bar","baz","blah"}))); }
@Test public void testGetUniqueNonEmptyTrimmedStrings (){ final String TO_SPLIT = ",foo, bar,baz,,blah,blah,bar,"; Collection<String> col = StringUtils.getTrimmedStringCollection(TO_SPLIT); assertEquals(4, col.size()); assertTrue(col.containsAll(Arrays.asList(new String[]{"foo","bar","baz","blah"}))); }
@Test public void testStaticIPHostNameList()throws UnknownHostException { //create MachineList with a list of of Hostnames InetAddress addressHost1 = InetAddress.getByName("1.2.3.1"); InetAddress addressHost4 = InetAddress.getByName("1.2.3.4"); MachineList.InetAddressFactory addressFactory = Mockito.mock(MachineList.InetAddressFactory.class); Mockito.when(addressFactory.getByName("host1")).thenReturn(addressHost1); Mockito.when(addressFactory.getByName("host4")).thenReturn(addressHost4); MachineList ml = new MachineList( StringUtils.getTrimmedStringCollection(HOST_LIST), addressFactory); //test for inclusion with an known IP assertTrue(ml.includes("1.2.3.4")); //test for exclusion with an unknown IP assertFalse(ml.includes("1.2.3.5")); }
@Test public void testGetCollection() { //create MachineList with a mix of ip addresses , hostnames and ip ranges MachineList ml = new MachineList(HOSTNAME_IP_CIDR_LIST); Collection<String> col = ml.getCollection(); //test getCollectionton to return the full collection assertEquals(7,ml.getCollection().size()); for (String item:StringUtils.getTrimmedStringCollection(HOSTNAME_IP_CIDR_LIST)) { assertTrue(col.contains(item)); } } }
@Test public void testGetCollection() { //create MachineList with a mix of ip addresses , hostnames and ip ranges MachineList ml = new MachineList(HOSTNAME_IP_CIDR_LIST); Collection<String> col = ml.getCollection(); //test getCollectionton to return the full collection assertEquals(7,ml.getCollection().size()); for (String item:StringUtils.getTrimmedStringCollection(HOSTNAME_IP_CIDR_LIST)) { assertTrue(col.contains(item)); } } }