Java 8 PropertyEditor - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 PropertyEditor class.

This code example shows how to use the following methods:getAsText, getValue, setAsText, setValue
 
	/** 
	 * Returns {@code true} if the supplied candidate value is equal to the value bound to 
	 * the supplied {@link BindStatus}. Equality in this case differs from standard Java equality and 
	 * is described in more detail <a href="#equality-contract">here</a>. 
	 */ 
	public static boolean isSelected(BindStatus bindStatus, Object candidateValue) {
		if (bindStatus == null) {
			return (candidateValue == null); 
		} 
 
		// Check obvious equality matches with the candidate first, 
		// both with the rendered value and with the original value. 
		Object boundValue = bindStatus.getValue();
		if (ObjectUtils.nullSafeEquals(boundValue, candidateValue)) { 
			return true; 
		} 
		Object actualValue = bindStatus.getActualValue();
		if (actualValue != null && actualValue != boundValue && 
				ObjectUtils.nullSafeEquals(actualValue, candidateValue)) { 

8
CodeRank
This code example shows how to use the following methods:getAsText, getValue, setAsText
	} 
 
	@Test
	public void testSetAsTextWithNull() throws Exception {
		PropertyEditor urlEditor = new URLEditor();
		urlEditor.setAsText(null);
		assertNull(urlEditor.getValue());
		assertEquals("", urlEditor.getAsText());
	} 
 
	@Test
	public void testGetAsTextReturnsEmptyStringIfValueNotSet() throws Exception {
		PropertyEditor urlEditor = new URLEditor();
		assertEquals("", urlEditor.getAsText());
	} 
 
	@Test(expected=IllegalArgumentException.class)
	public void testCtorWithNullResourceEditor() throws Exception {
		new URLEditor(null); 
	} 
7
CodeRank
This code example shows how to use the following methods:getAsText, getValue, setAsText
	} 
 
	@Test
	public void setAsTextWithNull() throws Exception {
		PropertyEditor uriEditor = new URIEditor();
		uriEditor.setAsText(null);
		assertNull(uriEditor.getValue());
		assertEquals("", uriEditor.getAsText());
	} 
 
	@Test
	public void getAsTextReturnsEmptyStringIfValueNotSet() throws Exception {
		PropertyEditor uriEditor = new URIEditor();
		assertEquals("", uriEditor.getAsText());
	} 
 
	@Test
	public void encodeURI() throws Exception {
		PropertyEditor uriEditor = new URIEditor();
		uriEditor.setAsText("http://example.com/spaces and \u20AC");
7
CodeRank
This code example shows how to use the following methods:getAsText, setValue
	 * @see #getDisplayString(Object, boolean) 
	 */ 
	public static String getDisplayString(Object value, PropertyEditor propertyEditor, boolean htmlEscape) {
		if (propertyEditor != null && !(value instanceof String)) {
			try { 
				propertyEditor.setValue(value);
				String text = propertyEditor.getAsText();
				if (text != null) {
					return getDisplayString(text, htmlEscape);
				} 
			} 
			catch (Throwable ex) {
				// The PropertyEditor might not support this value... pass through. 
			} 
		} 
		return getDisplayString(value, htmlEscape);
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:getValue, setAsText
public final class FileEditorTests { 
 
	@Test
	public void testClasspathFileName() throws Exception {
		PropertyEditor fileEditor = new FileEditor();
		fileEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/"
				+ ClassUtils.getShortName(getClass()) + ".class");
		Object value = fileEditor.getValue();
		assertTrue(value instanceof File);
		File file = (File) value;
		assertTrue(file.exists());
	} 
 
	@Test(expected=IllegalArgumentException.class)
	public void testWithNonExistentResource() throws Exception {
		PropertyEditor propertyEditor = new FileEditor();
		propertyEditor.setAsText("classpath:no_way_this_file_is_found.doc");
	} 
 
	@Test
7
CodeRank
This code example shows how to use the following methods:getAsText, setAsText
		assertEquals(text, charEditor.getAsText());
	} 
 
	public void testGetAsTextReturnsEmptyStringIfValueIsNull() throws Exception {
		PropertyEditor charEditor = new CharArrayPropertyEditor();
		assertEquals("", charEditor.getAsText());
 
		charEditor.setAsText(null);
		assertEquals("", charEditor.getAsText());
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:getValue, setAsText
	@Test
	public void testSystemPropertyReplacement() { 
		PropertyEditor editor = new ResourceArrayPropertyEditor();
		System.setProperty("test.prop", "foo");
		try { 
			editor.setAsText("${test.prop}-${bar}");
			Resource[] resources = (Resource[]) editor.getValue();
			assertEquals("foo-${bar}", resources[0].getFilename());
		} 
		finally { 
			System.getProperties().remove("test.prop");
		} 
	} 
 
	@Test(expected=IllegalArgumentException.class)
	public void testStrictSystemPropertyReplacement() { 
		PropertyEditor editor = new ResourceArrayPropertyEditor(
				new PathMatchingResourcePatternResolver(), new StandardEnvironment(),
				false); 
		System.setProperty("test.prop", "foo");
7
CodeRank
This code example shows how to use the following methods:getAsText, setAsText
	} 
 
	@Test
	public void setAndGetAsTextWithNull() throws Exception {
		PropertyEditor editor = new ResourceEditor();
		editor.setAsText(null);
		assertEquals("", editor.getAsText());
	} 
 
	@Test
	public void setAndGetAsTextWithWhitespaceResource() throws Exception {
		PropertyEditor editor = new ResourceEditor();
		editor.setAsText("  ");
		assertEquals("", editor.getAsText());
	} 
 
	@Test
	public void testSystemPropertyReplacement() { 
		PropertyEditor editor = new ResourceEditor();
		System.setProperty("test.prop", "foo");
7
CodeRank
This code example shows how to use the following methods:getAsText, setValue
This code example shows how to use the following methods:getAsText, setAsText
		assertEquals(text, byteEditor.getAsText());
	} 
 
	public void testGetAsTextReturnsEmptyStringIfValueIsNull() throws Exception {
		PropertyEditor byteEditor = new ByteArrayPropertyEditor();
		assertEquals("", byteEditor.getAsText());
 
		byteEditor.setAsText(null);
		assertEquals("", byteEditor.getAsText());
	} 
 
} 
7
CodeRank
See Code Examples for Java 8 PropertyEditor Methods: