Skip to content

Commit

Permalink
Merge pull request #7 from baranowb/Generic-Array-PE
Browse files Browse the repository at this point in the history
Generic Array Property editor
  • Loading branch information
baranowb committed Apr 3, 2012
2 parents a8c4243 + 7f08cb1 commit 4aa37c0
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 588 deletions.

This file was deleted.

Expand Up @@ -27,42 +27,14 @@
*
* @author baranowb
*/
public class BooleanArrayEditor extends ArrayPropertyEditorSupport<boolean[]> {
public class BooleanArrayEditor extends GenericArrayPropertyEditor<boolean[]> {

public BooleanArrayEditor() {
super(boolean[].class);
}

private static final String[] BOOLEAN_TAGS = { "true", "false" };

/**
* Build a boolean[] from comma or eol seperated elements
*
*/
@Override
public void setAsText(final String text) {
if (PropertyEditors.isNull(text)) {
setValue(null);
return;
}
String[] tokens = super.tokenize(text);
boolean[] theValue = new boolean[tokens.length];

for (int index = 0; index < tokens.length; index++) {
theValue[index] = Boolean.parseBoolean(tokens[index]);
}
setValue(theValue);
}

/**
* @return a comma seperated string of the array elements
*/
@Override
public String getAsText() {
boolean[] theValue = (boolean[]) getValue();
return super.encode(theValue);
}

@Override
public String[] getTags() {
return BOOLEAN_TAGS;
Expand Down
Expand Up @@ -26,41 +26,9 @@
*
* @author baranowb
*/
public class ByteArrayEditor extends ArrayPropertyEditorSupport<byte[]> {
public class ByteArrayEditor extends GenericArrayPropertyEditor<byte[]> {

public ByteArrayEditor() {
super(byte[].class);
}

/**
* Build a byte[] from comma or eol seperated elements
*
*/
@Override
public void setAsText(final String text) {
if (PropertyEditors.isNull(text)) {
setValue(null);
return;
}
String[] tokens = super.tokenize(text);
byte[] theValue = new byte[tokens.length];

for (int index = 0; index < tokens.length; index++) {
try {
theValue[index] = Byte.decode(tokens[index]);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Failed to parse byte.", e);
}
}
setValue(theValue);
}

/**
* @return a comma seperated string of the array elements
*/
@Override
public String getAsText() {
byte[] theValue = (byte[]) getValue();
return super.encode(theValue);
}
}
Expand Up @@ -28,7 +28,7 @@
* @todo REVIEW: look at possibly parsing escape sequences?
* @author baranowb
*/
public class CharacterArrayEditor extends ArrayPropertyEditorSupport<char[]> {
public class CharacterArrayEditor extends GenericArrayPropertyEditor<char[]> {

public CharacterArrayEditor() {
super(char[].class);
Expand All @@ -55,13 +55,4 @@ public void setAsText(final String text) {
}
setValue(theValue);
}

/**
* @return a comma seperated string of the array elements
*/
@Override
public String getAsText() {
char[] theValue = (char[]) getValue();
return super.encode(theValue);
}
}

0 comments on commit 4aa37c0

Please sign in to comment.