如何使用Javadoc记录功能的运行时
我想记录功能的渐近运行时,因为它将用于用于图形问题的算法工程。 做这件事的最惯用方法是什么?有没有办法在@return或@author之类的Javadoc中创建新标签?
我在下面提供了一个示例,这是删除图表中顶点的方法。
/**
* Runtime: O( degreeOf(v) ) because every neighbour of [v] also needs to be updated.
*/
fun deleteVertex(v: V): SimpleGraph<V> {
if (v in m.keys) {
for (nb in m[v]!!)
m[nb]!!.remove(v)
m.remove(v)
}
return this
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要为Javadocs创建自定义标签,只需遵循以下说明。
您可以为Javadoc创建其他自定义。例如,在Eclipse中,您可以创建“模板”,以便在创建新类或添加新方法时,IDE会自动应用此模板以添加(Javadoc)以所应用模板的规定样式格式化的(Javadoc)注释。您可以将这些模板保存在XML文件中,以便可以与团队的其他成员共享。我相信Intellij和其他现代IDE将具有类似的功能。我只是对日食更加熟悉。这是我多年前在。如果您提前到1:48标记,您将在我在视频中选择的“代码格式化”选项上方看到“代码模板”。创建代码模板比格式化器要容易得多。
为此,只需单击 Windows &gt; 首选项菜单以获取首选项弹出窗口。在那里,选择 java &gt; 代码样式&gt; 代码模板。在右窗格中,展开注释,然后选择要创建评论模板的组件,例如方法。单击“编辑”按钮,然后将Javadoc注释格式化为您的喜好。显然,您将不得不进行一些研究,以使您的评论真正创造。例如,您可能需要弄清楚如何使用系统变量或创建自己的变量。例如,在下图中,我使用年度变量在创建新类时应用本年度。
完成所有模板自定义后,只需单击导出按钮,然后使用文件选择器对话框来保存文件。
最后一个提示是,如果您需要在Javadocs中嵌入代码段,则可以关注本文中的建议。我经常这样做。有时,我发现嵌入几行代码以说明该方法的不同用例很有用。这样,其他开发人员可以看到如何在正确的上下文中使用该方法。
To create custom tags for Javadocs, simply follow these instructions.
You can create other customizations for Javadoc. For example, in Eclipse, you can create "templates" so that when you create new classes or add new methods, the IDE automatically apply this template to add a (Javadoc) comment formatted in the prescribed style of the template you applied. You can save these templates in an XML file so that you could share it with other members of your team. I am sure that IntelliJ and other modern IDEs will have similar features. I am just more familiarized with Eclipse. Here is a video I created many years ago on how to create a Code Formatter in Eclipse. If you advance to the 1:48 mark, you will see "Code Template" right above the "Code Formatter" option I selected in the video. Creating a code template is much easier than a formatter.
To do this, simply click on Windows > Preferences menu to get the Preferences popup. There, select Java > Code Style > Code Templates. in the right pane, expand Comments and select the component you wish to create a comment template for, for example Methods. Click Edit button and format the Javadoc comment to your liking. Obviously, you will have to do a bit of research to get really creative with your comments. For example, you might need to figure out how to use system variables or create your own. For example, in the image below, I made use the year variable to apply the current year whenever I create a new class.
Once you finish with all your template customizations, simply click the Export button and use the File Chooser dialog to save the file wherever you would like.
One last tip, if you need to embed code snippets in your Javadocs, you can follow the recommendations in this article. I do this very often. Sometimes I find it useful to embed a few lines of code to illustrate different use cases for the method. That way, other developers can see how to use the method in the correct context.