FreeColXMLReader.java 文件源码

java
阅读 30 收藏 0 点赞 0 评论 0

项目:FreeCol 作者:
/**
 * Find a FreeCol AI object from an attribute in a stream.
 *
 * @param <T> The actual return type.
 * @param aiMain The {@code AIMain} that contains the object.
 * @param attributeName The attribute name.
 * @param returnClass The {@code AIObject} type to expect.
 * @param defaultValue The default value.
 * @param required If true a null result should throw an exception.
 * @exception XMLStreamException if there is problem reading the stream.
 * @return The {@code AIObject} found, or the default value if not.
 */
public <T extends AIObject> T findAIObject(AIMain aiMain,
    String attributeName, Class<T> returnClass, T defaultValue,
    boolean required) throws XMLStreamException {

    T ret = getAttribute(aiMain, attributeName, returnClass, (T)null);
    if (ret == (T)null) {
        if (required) {
            throw new XMLStreamException("Missing " + attributeName
                + " for " + returnClass.getName() + ": " + currentTag());
        } else {
            ret = defaultValue;
        }
    }
    return ret;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号