@Override public void setConnection_point(Set<ConnectionPoint> connection_point) { for (ConnectionPoint cp : connection_point) if (!(cp instanceof VNFDConnectionPoint)) throw new TypeConstraintException( "Connection Point " + cp.getId() + " field must be an instance of " + ConnectionPoint.class.getCanonicalName()); this.connection_point = connection_point; }
private URL returnAsUrl(String parameter, String name, String altMethod){ Object obj = getParameter(parameter); if (obj == null){ return null; } if (obj instanceof URL){ return (URL)obj; } throw new TypeConstraintException("The stored " + name + " is a String, not a URL. Use \""+ altMethod + "\" instead."); }
private String returnAsString(String parameter, String name, String altMethod){ Object obj = getParameter(parameter); if (obj == null){ return null; } if (obj instanceof String){ return (String)obj; } throw new TypeConstraintException("The stored " + name + " is a URL, not a String. Use \""+ altMethod + "\" instead."); }
private String stringify(Object o) { if (o == null) throw new TypeConstraintException( "TypeError: no implicit conversion of null into String"); if (o instanceof String) return (String) o; if (o instanceof CharSequence) { CharSequence cs = (CharSequence) o; return new StringBuilder(cs.length()).append(cs).toString(); } return o.toString(); }
/** * Searches sep in the string and returns the part before it, the match, and * the part after it. If it is not found, returns two empty strings and str. * * @param sep * @return {@link RubyArray} */ public RubyArray<String> partition(String sep) { if (sep == null) throw new TypeConstraintException("TypeError: type mismatch: null given"); int sepIndex = str.indexOf(sep); if (sepIndex == -1) return Ruby.Array.of(str, "", ""); return Ruby.Array.of(str.substring(0, sepIndex), sep, str.substring(sepIndex + sep.length())); }
/** * Searches pattern in the string and returns the part before it, the match, * and the part after it. If it is not found, returns two empty strings and * str. * * @param pattern * a Pattern * @return {@link RubyArray} */ public RubyArray<String> partition(Pattern pattern) { if (pattern == null) throw new TypeConstraintException("TypeError: type mismatch: null given"); Matcher matcher = pattern.matcher(str); if (matcher.find()) { String sep = matcher.group(); int sepIndex = str.indexOf(sep); return Ruby.Array.of(str.substring(0, sepIndex), sep, str.substring(sepIndex + sep.length())); } else { return Ruby.Array.of(str, "", ""); } }
/** * Returns the matching portion of the string. * * @param pattern * a Pattern * @return new {@link RubyString} or null */ public RubyString slice(Pattern pattern) { if (pattern == null) throw new TypeConstraintException("TypeError: type mismatch: null given"); Matcher matcher = pattern.matcher(str); if (matcher.find()) return Ruby.String.of(matcher.group()); else return null; }
@Test(expected = TypeConstraintException.class) public void testRpartitionWithPatternException() { rs.rpartition((Pattern) null); }
@Test(expected = TypeConstraintException.class) public void testSqueezeWithCharSetException() { rs(" now is the").squeeze(null); }
@Test(expected = TypeConstraintException.class) public void testLindexWithPatternAndStopAtException() { rs.rindex((Pattern) null, -1); }
@Test(expected = TypeConstraintException.class) public void testTrSException1() { rs.trS(null, ""); }
@Test(expected = TypeConstraintException.class) public void testUptoWithExclusiveAndBlockException() { rs.upto(null, true, (Consumer<String>) null); }
@Test(expected = TypeConstraintException.class) public void testSliceWithPatternException() { rs.slice((Pattern) null); }
@Test(expected = TypeConstraintException.class) public void testCountException1() { RubyStrings.count(rs, (String) null); }
@Test(expected = TypeConstraintException.class) public void testCryptException() { RubyStrings.crypt(rs, null); }
@Test(expected = TypeConstraintException.class) public void testDeleteException() { RubyStrings.delete(rs, null); }
@Test(expected = TypeConstraintException.class) public void testEachLineWithSeparatorException() { RubyStrings.eachLine(rs, (String) null); }
@Test(expected = TypeConstraintException.class) public void testEachLineWithSeparatorAndBlockException() { RubyStrings.eachLine(rs, (String) null, item -> {}); }
@Test(expected = TypeConstraintException.class) public void testEncodeException() { RubyStrings.encode(rs, null); }
@Test(expected = TypeConstraintException.class) public void testEncodeExceptionWithNullDestinationEncoding() { RubyStrings.encode(rs, null, "UTF-8"); }
@Test(expected = TypeConstraintException.class) public void testEncodeExceptionWithNullSourceEncoding() { RubyStrings.encode(rs, "ISO-8859-1", null); }
@Test(expected = TypeConstraintException.class) public void testSliceǃWithPatternException() { rs.sliceǃ((Pattern) null); }
@Test(expected = TypeConstraintException.class) public void testGsubException1() { RubyStrings.gsub("ab4c56", null, "77"); }
@Test(expected = TypeConstraintException.class) public void testGsubException2() { RubyStrings.gsub("ab4c56", "\\d+", (String) null); }
@Test(expected = TypeConstraintException.class) public void testGsubWithMapException() { RubyStrings.gsub("0ab4c56", null, rh("4", "88", "56", "99")); }
@Test(expected = TypeConstraintException.class) public void testGsubWithBlockException() { RubyStrings.gsub("ab4c56", null, item -> item + "0"); }
@Test(expected = TypeConstraintException.class) public void testGsubWithoutReplacementException() { RubyStrings.gsub("ab4c56", null); }
@Test(expected = TypeConstraintException.class) public void testIndexException() { RubyStrings.index(rs, (String) null); }
@Test(expected = TypeConstraintException.class) public void testIndexWithOffsetException() { RubyStrings.index(rs, (String) null, 100); }
@Test(expected = TypeConstraintException.class) public void testTransposeException1() { ra.transpose(); }
@Test(expected = TypeConstraintException.class) public void testIndexWithPatternAndOffsetException() { RubyStrings.index(rs, (Pattern) null, 1); }
@Test(expected = TypeConstraintException.class) public void testInsertException() { RubyStrings.insert(rs, 0, null); }
@Test(expected = TypeConstraintException.class) public void testLinesWithSeparatorException() { RubyStrings.lines("a\nb\n\nc", null); }
@Test(expected = TypeConstraintException.class) public void testLjustWithPadstrException() { RubyStrings.ljust("hello", 20, null); }
@Test(expected = TypeConstraintException.class) public void testToByteArrayWithObjectAndException2() { ByteUtils.toByteArray((Object) null, le); }
@Test(expected = TypeConstraintException.class) public void testSubException2() { rs("hello").sub("[aeiou]", (String) null); }
@Test(expected = TypeConstraintException.class) public void testPartitionException() { RubyStrings.partition(rs, (String) null); }
@Test(expected = TypeConstraintException.class) public void testPartitionWithPatternException() { RubyStrings.partition(rs, (Pattern) null); }
@Test(expected = TypeConstraintException.class) public void testPrependException() { RubyStrings.prepend(rs, null); }