は、私はほとんど同様の4つの方法があるが、私は彼らに私はそれらをリファクタリングすることができますどのようにこれらのメソッドをどのようにリファクタリングするのですか?
public String listWeatherConditions()
{
String retVal = "";
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm a");
for(Map.Entry<String , ArrayList<Weather>> entry : this.weathers.entrySet())
{
retVal = String.format("\n Data From %s \n", entry.getKey());
retVal += String.format("displaying \tWeather Conditions hPa\n","");
for (Weather element : this.weathers.get(entry.getKey()))
{
retVal += String.format("%s\t\t%s\n",formatter.format(element.getCalculatedDate()) , element.getConditions());
}
}
retVal += "--------------------";
return retVal;
}
public String listWind()
{
String retVal = "";
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm a");
for(Map.Entry<String , ArrayList<Weather>> entry : this.weathers.entrySet())
{
retVal = String.format("\n Data From %s \n", entry.getKey());
retVal += String.format("displaying \tWind Direction\tWind SpeedKm/h\tWindDirDegrees\n","");
for (Weather element : this.weathers.get(entry.getKey()))
{
retVal += String.format("%s\t\t%s\t\t%s\t\t%d\n", formatter.format(element.getCalculatedDate()), element.getWindDirection() , element.getWindSpeedKmh() , element.getWindDirDegrees());
}
}
retVal += "--------------------";
return retVal;
}
をリファクタリングする方法を見つけ出すことはできませんか?
の書式設定の戦略を定義するためにStrategyパターンを使用して、私は唯一の2つの方法を数えます。 –
便宜のためにここに2つだけコピーしました –