Apache Thrift:我们可以指示 thrift 将 SET 容器转换为 Java LinkedHashSet 吗? [英] Apache Thrift: Can we instruct thrift to translate a SET container to Java LinkedHashSet?

查看:18
本文介绍了Apache Thrift:我们可以指示 thrift 将 SET 容器转换为 Java LinkedHashSet 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自文档:默认情况下,Thrift 将 SET 容器转换为 HashSet.我们可以改变这种行为吗?

From the documentation: Thrift translates a SET container to HashSet by default. Can we change this behavior?

容器Thrift 容器是强类型容器,映射到大多数编程语言中常用和常用的容器类型.

Containers Thrift containers are strongly typed containers that map to commonly used and commonly available container types in most programming languages.

https://thrift.apache.org/docs/types:

共有三种容器类型:list:元素的有序列表.转换为 STL 向量、Java ArrayList、脚本语言中的本机数组等.set:一组无序的唯一元素.转换为 STL 集合、Java HashSet、Python 中的集合等.注意:PHP 不支持集合,因此将其视为类似于 List

推荐答案

sorted_containers 选项 切换到

The sorted_containers option switches to

  • TreeMap for map<>
  • TreeSet for set<>
  • TreeMap for map<>
  • TreeSet for set<>

调用Thrift编译器时需要指定该选项,如下所示:

The option is to be specified when calling the Thrift compiler, like so:

$ thrift  -gen java:sorted_containers  myfile.thrift

这里是所有可用于 Java 的选项(当前的 master 分支,thrift -help 揭示了更多信息)

Here are all options available for Java (curent master branch, thrift -help reveals more info)

 java (Java):
    beans:           Members will be private, and setter methods will return void.
    private-members: Members will be private, but setter methods will return 'this' like usual.
    nocamel:         Do not use CamelCase field accessors with beans.
    fullcamel:       Convert underscored_accessor_or_service_names to camelCase.
    android:         Generated structures are Parcelable.
    android_legacy:  Do not use java.io.IOException(throwable) (available for Android 2.3 and above).
    option_type:     Wrap optional fields in an Option type.
    java5:           Generate Java 1.5 compliant code (includes android_legacy flag).
    reuse-objects:   Data objects will not be allocated, but existing instances will be used (read and write).
    sorted_containers:
                     Use TreeSet/TreeMap instead of HashSet/HashMap as a implementation of set/map.
    generated_annotations=[undated|suppress]:
                     undated: suppress the date at @Generated annotations
                     suppress: suppress @Generated annotations entirely

其他选项不可用.C++ 生成器支持注解,Java 似乎不是这种情况.我有没有提到我们接受补丁?

Other options are not available. The C++ generator supports annotations, this seems not to be the case with Java. Did I mention that we accept patches?

这篇关于Apache Thrift:我们可以指示 thrift 将 SET 容器转换为 Java LinkedHashSet 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆