Minor bug fixes.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@46 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-02-05 08:56:44 +00:00
parent 8444136be1
commit 3ea230b11c
2 changed files with 12 additions and 9 deletions

View File

@ -30,21 +30,24 @@ public class Get implements Function {
start = Math.min(a.length, Math.max(0, start)); start = Math.min(a.length, Math.max(0, start));
if (to == null) { if (to == null) {
return a[start]; return start < a.length ? a[start] : null;
} else { } else {
int end = to != null && to instanceof Number ? int end = to != null && to instanceof Number ?
((Number) to).intValue() : a.length; ((Number) to).intValue() : a.length;
if (end < 0) { if (end < 0) {
end = a.length - end; end = a.length + end;
} }
end = Math.min(a.length, Math.max(start, end)); end = Math.min(a.length, Math.max(start, end));
if (end > start) {
Object[] a2 = new Object[end - start]; Object[] a2 = new Object[end - start];
System.arraycopy(a, start, a2, 0, end - start); System.arraycopy(a, start, a2, 0, end - start);
return a2; return a2;
} }
}
} else { } else {
String s = (v instanceof String ? (String) v : v.toString()); String s = (v instanceof String ? (String) v : v.toString());
@ -57,7 +60,7 @@ public class Get implements Function {
if (to != null && to instanceof Number) { if (to != null && to instanceof Number) {
int end = ((Number) to).intValue(); int end = ((Number) to).intValue();
if (end < 0) { if (end < 0) {
end = s.length() - end; end = s.length() + end;
} }
end = Math.min(s.length(), Math.max(start, end)); end = Math.min(s.length(), Math.max(start, end));

View File

@ -26,7 +26,7 @@ public class Slice implements Function {
start = Math.min(a.length, Math.max(0, start)); start = Math.min(a.length, Math.max(0, start));
if (end < 0) { if (end < 0) {
end = a.length - end; end = a.length + end;
} }
end = Math.min(a.length, Math.max(start, end)); end = Math.min(a.length, Math.max(start, end));
@ -46,7 +46,7 @@ public class Slice implements Function {
if (to != null && to instanceof Number) { if (to != null && to instanceof Number) {
int end = ((Number) to).intValue(); int end = ((Number) to).intValue();
if (end < 0) { if (end < 0) {
end = s.length() - end; end = s.length() + end;
} }
end = Math.min(s.length(), Math.max(start, end)); end = Math.min(s.length(), Math.max(start, end));