Tag: 代码清理

如何以优雅的方式初始化具有大量字段的类?

在我的应用程序中,我必须实例化许多不同类型的对象。 每种类型都包含一些字段,需要添加到包含类型中。 我怎样才能以优雅的方式做到这一点? 我当前的初始化步骤看起来像这样: public void testRequest() { //All these below used classes are generated classes from xsd schema file. CheckRequest checkRequest = new CheckRequest(); Offers offers = new Offers(); Offer offer = new Offer(); HotelOnly hotelOnly = new HotelOnly(); Hotel hotel = new Hotel(); Hotels hotels = new Hotels(); Touroperator touroperator = new Touroperator(); […]

如何从代码库中删除System.out.println

我们有一个庞大的(旧的遗留Java)代码库,其中许多文件(大约5k)都有System.out.println。 我们计划因清理/性能原因删除它们。 我们如何编写一个脚本来替换它们而不会在代码中引入任何问题? 脚本不能盲目删除它们,因为以下情况可能是一个问题: if () some.code… else System.out.println(…); DB.close(); 我想用’;’代替它们。 这将照顾上述情况。 你还有其他问题吗? 还有其他建议吗?

如何从XML文件中删除多余的空行?

简而言之; 我在XML文件中生成了许多空行,我正在寻找一种方法来删除它们作为一种倾斜文件的方式。 我怎样才能做到这一点 ? 详细说明; 我目前有这个XML文件: path1 path2 path3 path4 我使用此Java代码删除所有标记,并添加新标记: public void savePaths( String recentFilePath ) { ArrayList newPaths = getNewRecentPaths(); Document recentDomObject = getXMLFile( recentFilePath ); // Get the element. NodeList pathNodes = recentDomObject.getElementsByTagName( “path” ); // Get all nodes. //1. Remove all old path nodes : for ( int i = pathNodes.getLength() […]