java - Geotools:关于 SimpleFeatureTypeBuilder 的 length(int length) 方法
问题描述
我想设置字符串类型字段的长度,但是我看到了源代码:</p>
调用 {@link #add(String, Class)} 后重置值
方法的意义是什么?如何设置字符串类型字段的长度?任何人都可以帮助我
/**
* Sets a restriction on the field length of the next attribute added to the feature type.
*
* <p>This method is the same as adding a restriction based on length( value ) < length This
* value is reset after a call to {@link #add(String, Class)}
*
* @return length Used to limit the length of the next attribute created
*/
public SimpleFeatureTypeBuilder length(int length) {
attributeBuilder.setLength(length);
return this;
}
解决方案
如果您按照代码进行操作,您将看到add(String, Class)
调用该代码以将新属性添加到架构中。它要求AttributeTypeBuilder
对属性进行编码。这是setLength
存储您设置的长度限制的地方length
。一旦生成了属性,resetTypeState
就会调用“重置”属性构建器来准备下一个属性(这是将长度重置为空的地方)。
因此,在将属性添加到模式后,JavaDoc 警告是正确的长度会被重置,因此,如果要对属性设置长度限制,则需要执行以下操作:
fBuilder.length(30);
fBuilder.add("myStringAttr",String.class);
schema = fBuilder.buildFeatureType();
推荐阅读
- hyperledger-composer - 如何在本地使用超级账本网卡
- php - 从 gmail 复制客户端数据并提交表单时 PHP 抛出 403 禁止错误
- php - 在 Drupal8 自定义块中使用自定义树枝模板
- c++ - Android 上 __property 的 Embarcadero C++Builder 错误
- ios - Xcode 10 - 构建和安装后未更新应用程序
- python-3.x - 带有迁移学习的自动编码器?
- java - 如何使用声明范围之外的对象?
- php - 填补时间表中的空白
- java - 在非活动类中保存值
- model-view-controller - 如何将对象从剑道网格传递到 MVC 中的剑道窗口