public String name() { return joinAsString(toArray(filter(keywords(), new NotBlank())), " "); }
@Override protected List<String> keywords() { return even(getCells()); }
@Override public Object parse(String value, Class< ? > type) { String text = removeSquareBrackets(value); List<Object> values = new ArrayList<Object>(); if (StringUtils.isBlank(text)) { return CollectionUtil.toArray(values, type.getComponentType()); } String[] parts = text.split(separators); for (String part : parts) { values.add(TypeConversion.parse(part.trim(), type.getComponentType())); } return CollectionUtil.toPrimitiveBoolArray(values); }
@Test public void testOperationsCanBeCombined() { String filePath = joinAsString(toArray("c:", "path", "to", "dir", "sub dir", "my file.html"), File.separator); String dirPath = joinAsString(toArray("c:", "path", "to"), File.separator); assertEquals("dir-sub dir-my file.html", flatten(relativize(dirPath, filePath))); }
public String[] getTests() { return toArray(tests); }
@Override public Object parse(String value, Class< ? > type) { String text = removeSquareBrackets(value); List<Object> values = new ArrayList<Object>(); if (StringUtils.isBlank(text)) { return CollectionUtil.toArray(values, type.getComponentType()); } String[] parts = text.split(separators); for (String part : parts) { values.add(TypeConversion.parse(part.trim(), type.getComponentType())); } return CollectionUtil.toPrimitiveDoubleArray(values); }
@Override public Object parse(String value, Class< ? > type) { String text = removeSquareBrackets(value); List<Object> values = new ArrayList<Object>(); if (StringUtils.isBlank(text)) { return CollectionUtil.toArray(values, type.getComponentType()); } String[] parts = text.split(separators); for (String part : parts) { values.add(TypeConversion.parse(part.trim(), type.getComponentType())); } return CollectionUtil.toPrimitiveFloatArray(values); }
@Override public Object parse(String value, Class< ? > type) { String text = removeSquareBrackets(value); List<Object> values = new ArrayList<Object>(); if (StringUtils.isBlank(text)) { return CollectionUtil.toArray(values, type.getComponentType()); } String[] parts = text.split(separators); for (String part : parts) { values.add(TypeConversion.parse(part.trim(), type.getComponentType())); } return CollectionUtil.toPrimitiveIntArray(values); }
@Override public Object parse(String value, Class< ? > type) { String text = removeSquareBrackets(value); List<Object> values = new ArrayList<Object>(); if (StringUtils.isBlank(text)) { return CollectionUtil.toArray(values, type.getComponentType()); } String[] parts = text.split(separators); for (String part : parts) { values.add(TypeConversion.parse(part.trim(), type.getComponentType())); } return CollectionUtil.toPrimitiveLongArray(values); }
@Override public Interpreter selectInterpreter(Example table) { Example cells = table.at(0, 0, 0); if (cells == null) { return new SkipInterpreter(); } String interpreterName = cells.at(0).getContent(); String[] fixtureAndParameters = fixtureAndParams(cells.at(1)); try { Object[] args = isEmpty(fixtureAndParameters) ? toArray(systemUnderDevelopment) : toArray( selectFixture(fixtureAndParameters)); return LivingDoc.getInterpreter(interpreterName, args); } catch (Throwable t) { LOG.error(LOG_ERROR, t); cells.at(0).annotate(Annotations.exception(t)); return new SkipInterpreter(new Statistics(0, 0, 1, 0)); } }
@Override public void specificationDone(Example spec, Statistics statistics) { try { String[] args1 = args(definitionRef); URI location = URI.create(URIUtil.raw(definitionRef.get(1))); List<Serializable> args = CollectionUtil.toList(args1[1], args1[2], (ArrayList<String>) CollectionUtil .toList(location.getFragment(), definitionRef.get(4), sut, XmlReport.toXml(documentRef))); String msg = getRestClient().saveExecutionResult(args); if (!("<success>".equals(msg))) { throw new IllegalStateException(msg); } } catch (LivingDocServerException e) { // Old server / incompatible method ? if (e.getMessage().indexOf(NoSuchMethodException.class.getName()) == -1) { // @todo : Log ? Critical ? Do we want the test execution to // fail if we can't post the result back ? throw ExceptionImposter.imposterize(e); } } catch (IllegalStateException e) { // @todo : Log ? Critical ? Do we want the test execution to // fail if we can't post the result back ? throw ExceptionImposter.imposterize(e); } catch (IOException e) { // @todo : Log ? Critical ? Do we want the test execution to // fail if we can't post the result back ? throw ExceptionImposter.imposterize(e); } } }
private String firstTag(List<String> listTags) { return elementPattern(toRegex(CollectionUtil.first(listTags))); }
private static String toString(Object... args) { if (args.length == 0) { return ""; } return "[" + CollectionUtil.joinAsString(args, ", ") + "]"; }
@Override public Example addChild() { if (hasChild()) { return child.addSibling(); } if (childTags.isEmpty()) { throw new IllegalStateException("No child tag"); } List<String> moreTags = new ArrayList<String>(childTags); String childTag = firstPattern(CollectionUtil.shift(moreTags)); child = createSpecification(childTag, moreTags); return child; }
@Test public void testCanFilterCollections() { List<String> values = Arrays.asList("", "start", "and", "with a blank", " "); Collection<String> nonBlanks = CollectionUtil.filter(values, new CollectionUtil.Predicate<String>() { @Override public boolean isVerifiedBy(String element) { return ! StringUtils.isBlank(element); } }); assertEquals(Arrays.asList("start", "and", "with a blank"), nonBlanks); }
public static <T> T first(List<T> list) { return get(list, 0); }
@Test public void testDecodedNormalizesPathSeparators() { assertEquals("c:/path/to/my_file.html", decoded(joinAsString(toArray("c:", "path", "to", "my_file.html"), File.separator))); }
public static String[] toArray(List<String> list) { return toArray(list, String.class); }
/** * Most regex implementations today do not build a DFA / NFA -- especially * those that offer backreferences (which are not "regular" at all). * * And because they do NOT build DFAs and NFAs, it's very simple to * construct pathological cases - e.g., "((a*)(a*))+b" can take * exponentially long to decide that aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac is * not in the language using the matching techniques commonly in use. * * Ori Berger * * @param text The text to check * @return boolean true, if the text matches pathological case, else false */ private boolean pathologicalCase(String text) { String tag = toRegex(CollectionUtil.first(tags)); String regex = String.format("(?is)(<\\s*(%s)\\s*.*?>)", tag); Matcher match = compile(regex).matcher(text); if (match.find()) { regex = String.format("(?is)(.*?)(<\\s*/\\s*(%s)\\s*.*?>)", tag); return ! compile(regex).matcher(text).find(match.end()); } return true; }