/** * Creates a valid filename for the given source name. The method returns a string which is the given name where * each occurence of a character which is not a letter, a digit or one of '_', '-', '.' is replaced by an * underscore. The returned string always has the same length as the source name. * * @param name the source name, must not be <code>null</code> */ public static String createValidFilename(String name) { Guardian.assertNotNull("name", name); return StringUtils.createValidName(name, new char[]{'_', '-', '.'}, '_'); }
/** * Sets a value of type <code>boolean</code>. * * @param key the key * @param value the value * * @throws IllegalArgumentException */ public void setPropertyBool(String key, boolean value) { Guardian.assertNotNullOrEmpty("key", key); setPropertyBool(key, value ? Boolean.TRUE : Boolean.FALSE); }
public void trace(String label) { if (Debug.isEnabled()) { Debug.trace(label + ": " + getTimeDiffString()); } } }
/** * Sets a value of type <code>String</code>. * * @param key the key * @param newValue the new value * * @throws IllegalArgumentException */ public void setPropertyString(String key, String newValue) { Guardian.assertNotNullOrEmpty("key", key); String oldValue = getPropertyString(key, null); changeInternalProperty(key, oldValue, newValue); }
public void testNotNullAndNotEmpty() { assertEquals(false, StringUtils.isNotNullAndNotEmpty(null)); assertEquals(false, StringUtils.isNotNullAndNotEmpty("")); assertEquals(true, StringUtils.isNotNullAndNotEmpty("a")); }
public void testNullOrEmpty() { assertEquals(true, StringUtils.isNullOrEmpty(null)); assertEquals(true, StringUtils.isNullOrEmpty("")); assertEquals(false, StringUtils.isNullOrEmpty("a")); }
/** * Sets a value of type <code>Double</code>. * * @param key the key * @param newValue the value * * @throws IllegalArgumentException */ public void setPropertyDouble(String key, Double newValue) { Guardian.assertNotNullOrEmpty("key", key); Double oldValue = getPropertyDouble(key, null); changeInternalProperty(key, oldValue, newValue); }
/** * Tests the functionality of getTimeDiff */ public void testGetTimeDiff() { StopWatch watch = new StopWatch(); long startTime; long endTime; startTime = watch.getStartTime(); watch.stop(); endTime = watch.getEndTime(); assertEquals(endTime - startTime, watch.getTimeDiff()); }
public void testJoinAndSplit() { Object[] tokensOrig = {"Fischer's", "Fritz", "fischt", "frische", "", "Fische"}; String textOrig1 = "Fischer's Fritz fischt frische Fische"; String textOrig2 = "Fischer's|Fritz|fischt|frische||Fische"; assertEquals(StringUtils.join(tokensOrig, " "), textOrig1); assertEquals(StringUtils.join(tokensOrig, "|"), textOrig2); assertEquals(ArrayUtils.equalArrays(StringUtils.split(textOrig1, new char[]{' '}, false), tokensOrig), true); assertEquals(ArrayUtils.equalArrays(StringUtils.split(textOrig2, new char[]{'|'}, false), tokensOrig), true); }
/** * Tests the functionality of getTimeDiffString() */ public void testGetTimeDiffString() { StopWatch watch = new StopWatch(); watch.stop(); // just check that we don't get an empty string assertTrue("" != watch.getTimeDiffString()); }
public void testGetCSVString() { final byte[] bytes = new byte[]{Byte.MAX_VALUE, Byte.MIN_VALUE, 0, 1, -1}; String csvString = StringUtils.arrayToCsv(bytes); assertEquals("127,-128,0,1,-1", csvString); }
private void testAccessors(BitRaster bitRaster, int x, int y) { assertEquals(false, bitRaster.isSet(x, y)); assertEquals(false, bitRaster.isSet(x + y * bitRaster.getWidth())); bitRaster.set(x, y, true); assertEquals(true, bitRaster.isSet(x, y)); assertEquals(true, bitRaster.isSet(x + y * bitRaster.getWidth())); bitRaster.set(x, y, false); assertEquals(false, bitRaster.isSet(x, y)); assertEquals(false, bitRaster.isSet(x + y * bitRaster.getWidth())); }
public void testRoot() { TreeNode<String> root = new TreeNode<String>(""); TreeNode<String> grunt = root.createChild("foo/bar/grunt"); assertSame(root, grunt.getRoot()); }
public void testRemoveFromArray() { String[] strings; strings = StringUtils.removeFromArray(new String[]{"A", "B", "C"}, "A"); assertTrue("String[]{\"B\",\"C\"} expected", ArrayUtils.equalArrays(new String[]{"B", "C"}, strings)); strings = StringUtils.removeFromArray(new String[]{"A", "B", "C"}, "B"); assertTrue("String[]{\"A\",\"C\"} expected", ArrayUtils.equalArrays(new String[]{"A", "C"}, strings)); strings = StringUtils.removeFromArray(new String[]{"A", "B", "C"}, "C"); assertTrue("String[]{\"A\",\"B\"} expected", ArrayUtils.equalArrays(new String[]{"A", "B"}, strings)); strings = StringUtils.removeFromArray(new String[]{"A", "B", "C"}, "D"); assertTrue("String[]{\"A\",\"B\",\"C\"} expected", ArrayUtils.equalArrays(new String[]{"A", "B", "C"}, strings)); }
public void testCreateTagsWithAtribs() { String[] tags = XmlWriter.createTags(2, "name", new String[][]{{"a", "b"}, {"c", "d"}}); assertEquals(2, tags.length); assertEquals(" <name a=\"b\" c=\"d\">", tags[0]); assertEquals(" </name>", tags[1]); }
/** * Tests the functionality of getTimeString */ public void testGetTimeString() { // just test that we don't get an empty string assertTrue("" != StopWatch.getTimeString(12)); }
public void testFail() { String[] strings; strings = StringUtils.removeFromArray(new String[]{"A", "B", "C"}, new String[]{"A"}); assertTrue("String[]{\"B\",\"C\"} expected", ArrayUtils.equalArrays(new String[]{"B", "C"}, strings)); strings = StringUtils.removeFromArray(new String[]{"A", "B", "C"}, new String[]{"B"}); assertTrue("String[]{\"A\",\"C\"} expected", ArrayUtils.equalArrays(new String[]{"A", "C"}, strings)); strings = StringUtils.removeFromArray(new String[]{"A", "B", "C"}, new String[]{"C"}); assertTrue("String[]{\"A\",\"B\"} expected", ArrayUtils.equalArrays(new String[]{"A", "B"}, strings)); strings = StringUtils.removeFromArray(new String[]{"A", "B", "C"}, new String[]{"D"}); assertTrue("String[]{\"A\",\"B\",\"C\"} expected", ArrayUtils.equalArrays(new String[]{"A", "B", "C"}, strings)); strings = StringUtils.removeFromArray(new String[]{"A", "B", "C", "D"}, new String[]{"D", "B"}); assertTrue("String[]{\"A\",\"C\"} expected", ArrayUtils.equalArrays(new String[]{"A", "C"}, strings)); }
public void testCreateTags() { String[] tags = XmlWriter.createTags(0, "name"); assertEquals(2, tags.length); assertEquals("<name>", tags[0]); assertEquals("</name>", tags[1]); }
public void testCreateTagsWithAtribs_ampersand_and_parentheses() { String[] tags = XmlWriter.createTags(2, "name", new String[][]{{"a", "a & b"}, {"c", "d < e > f"}}); assertEquals(2, tags.length); assertEquals(" <name a=\"a & b\" c=\"d < e > f\">", tags[0]); assertEquals(" </name>", tags[1]); } }