@SuppressWarnings("unchecked") public Object getNodeValue(String path) { String[] pathComponents = path.split("/"); if (namedRoot) Assert.equals(rootName, pathComponents[0], "Illegal path: " + path); Map<String, Object> node = rootMap; for (int i = (namedRoot ? 1 : 0); i < pathComponents.length - 1; i++) { String subNodeName = pathComponents[i]; Map<String, Object> subNode = (Map<String, Object>) node.get(subNodeName); if (subNode == null) return null; node = subNode; } return node.get(pathComponents[pathComponents.length - 1]); }
public AwtFileChooser(String prompt, FileOperation operation, FileTypeSupport supportedTypes) { super((Frame) null, prompt, (operation == FileOperation.OPEN ? FileDialog.LOAD : FileDialog.SAVE)); Assert.notNull(supportedTypes, "supportedTypes"); Assert.notNull(operation, "operation"); this.supportedTypes = supportedTypes; }
public Token(E type, int startOffset, int endOffset) { // check preconditions Assert.notNull(type, "tokenType"); Assert.notNegative(startOffset, "startOffset"); Assert.that(startOffset <= endOffset, "startOffset is greater that endOffset"); // assign values this.type = type; this.startOffset = startOffset; this.endOffset = endOffset; }
private void checkParallelizable(Converter<?, ?> converter) { if (converter.isParallelizable()) { Assert.isTrue(converter instanceof Cloneable, "Parallelizable converters must implement " + Cloneable.class); Assert.isTrue(BeanUtil.findMethod(converterClass, "clone", (Class[]) null) != null, "Parallelizable converters must have a public clone() method"); } }
protected TabularIterator query(String query, Connection connection) { Assert.notEmpty(query, "query"); return new ArrayResultSetIterator(connection, query); } protected void handleNKNotFound(String naturalKey, String tableName, String sourceDbId, String targetDbId) {
public FileHistory(Class<?> clazz, int length, boolean toleratingFailure) { this.clazz = clazz; Assert.lessOrEqual(length, HISTORY_LENGTH_LIMIT, "length"); this.files = new ArrayDeque<File>(length); this.toleratingFailure = toleratingFailure; load(); }
@Override public Object evaluate(Context context) { Expression<?>[] summands = { terms[0], terms[1] }; Assert.isTrue(summands.length > 1, "At least two summands needed"); Object result = summands[0].evaluate(context); for (int i = 1; i < summands.length; i++) result = ArithmeticEngine.defaultInstance().add(result, summands[i].evaluate(context)); return result; }
public TabularIterator query(String query, Connection connection) { Assert.notEmpty(query, "query"); return new ArrayResultSetIterator(connection, query); }
public AnyMutator(String path, boolean required, boolean autoConvert) { this.path = Assert.notNull(path, "path"); this.required = required; this.autoConvert = autoConvert; }
public void setCellValues(String[] columnNames, Object[] cellValues) { Assert.equals(columnNames.length, cellValues.length, "mismatch of column and value counts"); for (int i = 0; i < columnNames.length; i++) setCellValue(columnNames[i], cellValues[i]); }
private static Expression<?> convertBeanSpec(CommonTree node) throws SyntaxError { Assert.isTrue(node.getType() == DatabeneScriptLexer.BEANSPEC, "BEANSPEC expected, found: " + node.getToken()); node = childAt(0, node); if (node.getType() == DatabeneScriptLexer.QUALIFIEDNAME) return new QNBeanSpecExpression(convertQualifiedNameToStringArray(node)); else if (node.getType() == DatabeneScriptLexer.IDENTIFIER) return new QNBeanSpecExpression(new String[] { node.getText() }); else if (node.getType() == DatabeneScriptLexer.BEAN) return convertBean(node); else return convertNode(node); }
public ArrayIterator(E[] array) { Assert.notNull(array, "array"); this.array = array; this.cursor = 0; }
private static String[] parseHeaders(String uri, String sheetName, XLSLineIterator iterator) { // get headers String[] headers = iterator.getHeaders(); Assert.notEmpty(headers, "Empty XLS sheet '" + sheetName + "' in document " + uri); // normalize headers for (int i = 0; i < headers.length; i++) headers[i] = StringUtil.trimmedEmptyToNull(headers[i]); // determine trailing empty headers int headerCount = headers.length; while (headers[headerCount - 1] == null && headerCount > 0) headerCount--; // verify the regular headers if (headerCount == 0) throw new IllegalArgumentException("No headers in XLS sheet '" + sheetName + "' of document " + uri); for (int i = 0; i < headerCount; i++) Assert.notNull(headers[i], "Empty header in column #" + i + " of sheet '" + sheetName + "' of file '" + uri + "'"); // remove trailing empty headers return ArrayUtil.copyOfRange(headers, 0, headerCount); }
private static Integer convertInt(CommonTree node) { Assert.equals(RegexLexer.INT, node.getType(), "node is not an integer"); return Integer.parseInt(node.getText()); }
private static WeightedTransition convertTransition(CommonTree node) throws SyntaxError { Assert.isTrue(node.getType() == DatabeneScriptLexer.ARROW, "expected transition, found: " + node.getToken()); Expression<?> from = convertNode(childAt(0, node)); Expression<?> to = convertNode(childAt(1, node)); Expression<Double> weight; if (node.getChildCount() > 2) weight = new TypeConvertingExpression<Double>(convertNode(childAt(2, node)), Double.class); else weight = new ConstantExpression<Double>(1.); return new WeightedTransition(from.evaluate(null), to.evaluate(null), weight.evaluate(null)); }
public Escalation(String message, Object originator, Object cause) { super(); Assert.notNull(message, "message"); this.message = message; this.originator = originator; this.cause = cause; }
private Integer convertInt(CommonTree node) { Assert.equals(RegexLexer.INT, node.getType(), "node is not an integer"); return Integer.parseInt(node.getText()); }
private static BeanSpec resolveBeanSpec(CommonTree node, Context context) throws SyntaxError { Assert.isTrue(node.getType() == DatabeneScriptLexer.BEANSPEC, "BEANSPEC expected, found: " + node.getToken()); node = childAt(0, node); if (node.getType() == DatabeneScriptLexer.QUALIFIEDNAME) return new QNBeanSpecExpression(convertQualifiedNameToStringArray(node)).resolve(context); else if (node.getType() == DatabeneScriptLexer.IDENTIFIER) return new QNBeanSpecExpression(new String[] { node.getText() }).resolve(context); else if (node.getType() == DatabeneScriptLexer.BEAN) return BeanSpec.createConstruction(convertBean(node).evaluate(context)); else if (node.getType() == DatabeneScriptLexer.CONSTRUCTOR) return BeanSpec.createConstruction(convertNode(node).evaluate(context)); else return BeanSpec.createReference(convertNode(node).evaluate(context)); }