Returns an information string for the supplied input and the expected arity. @param supplied arguments @param arities allowed arities (if single arity is negative, function is variadic) @return string
(final String supplied, final IntList arities)
| 1815 | * @return string |
| 1816 | */ |
| 1817 | public static String arity(final String supplied, final IntList arities) { |
| 1818 | final String expected; |
| 1819 | final int as = arities.ddo().size(); |
| 1820 | if(as == 1 && arities.peek() < 0) { |
| 1821 | expected = "at least " + -arities.peek(); |
| 1822 | } else { |
| 1823 | int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE; |
| 1824 | for(int a = 0; a < as; a++) { |
| 1825 | final int m = arities.get(a); |
| 1826 | if(m < min) min = m; |
| 1827 | if(m > max) max = m; |
| 1828 | } |
| 1829 | final TokenBuilder tb = new TokenBuilder(); |
| 1830 | if(as > 2 && max - min + 1 == as) { |
| 1831 | tb.addInt(min).add('-').addInt(max); |
| 1832 | } else { |
| 1833 | for(int a = 0; a < as; a++) { |
| 1834 | if(a != 0) tb.add(a + 1 < as ? ", " : " or "); |
| 1835 | tb.addInt(arities.get(a)); |
| 1836 | } |
| 1837 | } |
| 1838 | expected = tb.toString(); |
| 1839 | } |
| 1840 | return Util.info("% supplied, % expected", supplied, expected); |
| 1841 | } |
| 1842 | |
| 1843 | /** |
| 1844 | * Returns an info message for similar strings. |