| 1708 | } |
| 1709 | |
| 1710 | static public Object[] toArray(Object coll) { |
| 1711 | if(coll == null) |
| 1712 | return EMPTY_ARRAY; |
| 1713 | else if(coll instanceof Object[]) |
| 1714 | return (Object[]) coll; |
| 1715 | else if(coll instanceof Collection) |
| 1716 | return ((Collection) coll).toArray(); |
| 1717 | else if(coll instanceof Iterable) { |
| 1718 | ArrayList ret = new ArrayList(); |
| 1719 | for(Object o : (Iterable)coll) |
| 1720 | ret.add(o); |
| 1721 | return ret.toArray(); |
| 1722 | } else if(coll instanceof Map) |
| 1723 | return ((Map) coll).entrySet().toArray(); |
| 1724 | else if(coll instanceof String) { |
| 1725 | char[] chars = ((String) coll).toCharArray(); |
| 1726 | Object[] ret = new Object[chars.length]; |
| 1727 | for(int i = 0; i < chars.length; i++) |
| 1728 | ret[i] = chars[i]; |
| 1729 | return ret; |
| 1730 | } |
| 1731 | else if(coll.getClass().isArray()) { |
| 1732 | ISeq s = (seq(coll)); |
| 1733 | Object[] ret = new Object[count(s)]; |
| 1734 | for(int i = 0; i < ret.length; i++, s = s.next()) |
| 1735 | ret[i] = s.first(); |
| 1736 | return ret; |
| 1737 | } |
| 1738 | else |
| 1739 | throw Util.runtimeException("Unable to convert: " + coll.getClass() + " to Object[]"); |
| 1740 | } |
| 1741 | |
| 1742 | static public Object[] seqToArray(ISeq seq){ |
| 1743 | int len = length(seq); |