나는 두 개의 자바 클래스를 가지고 있는데, 대부분 getter와 setters 같은 생성자이다.한 클래스의 객체를 다른 클래스의 arraylist에 추가하기
ReportGroup.java
String ReportGroupName;
List<ReportInfo> reportList; //getter & setter
ReportInfo.java
String ReportName;
String ReportId;
String ReportPath; //getter&setter
내가 거기 ReportGroup.Is에 내가 ReportGroup (목록 reportList)
공용 클래스 테스트 {의 목록에 ReportInfo의 값을 추가 할 수있는 모든 가능한 방법을 ReportInfo 및 ReportGroupName의 모든 값을 설정 한
public static List<ReportInfo> reportInfo = new ArrayList<ReportInfo>();
public static void main(String[] args) throws IOException {
String orgId="346";
String orgName="Ralph Lauren Corporation";
String reportPath= "/"+orgId +"_"+orgName.replaceAll(" ","_");
String reportFolderPath = "C:/Lokesh/Dev Tools/apache-tomcat-6.0.37/webapps/ROOT/Reports";
List<String> filesArray = null;
filesArray = new ArrayList<String>();
String filetowrite="C:/Users/lbandhu/Desktop/test.html";
FileWriter fw=new FileWriter(filetowrite);
ReportGroup reportGroup=new ReportGroup();
reportGroup.setReportGroupName(orgName);
reportGroup.getReportList().addAll(reportInfo);
File folder = new File(reportFolderPath+reportPath);
List<String> reportNames = listFolder(folder);
for (String rname : reportNames) {
ReportInfo reportInfo=new ReportInfo();
reportInfo.setReportName(rname);
folder = new File(reportFolderPath+reportPath+"/"+rname);
System.out.println(folder);
fw.write("<br><tr> "+rname +" Utilization Reports</tr><br>");
Iterator<String> iterator=listFilesForFolder(folder, filesArray).iterator();
writeReportPath(fw,iterator, reportFolderPath,reportInfo);
fw.write("<br>");
}
filesArray.clear();
fw.close();
private static void writeReportPath(FileWriter fw,Iterator<String> iterator, String reportFolderPath,ReportInfo reportInfo) throws IOException
{
while(iterator.hasNext()){
String listofFiles=iterator.next();
StringBuilder strgfile=new StringBuilder(listofFiles);
String filename=strgfile.substring(strgfile.indexOf("/")+1);
//System.out.println("name" +filename);
String[] split = filename.split("_");
if(split.length > 1) {
if(split[0].contains("MONTHLY")) {
//System.out.println(split[1].substring(0, 3) + " " + split[2]);
String monthly=split[1]+ " " + split[2];
int index=monthly.indexOf('/');
String reportId=monthly.substring(0, index);
//ReportInfo reportInfo=new ReportInfo();
//List <ReportInfo> reportGroup=new ArrayList<ReportInfo>();
reportInfo.setReportId(reportId);
reportInfo.setReportPath(reportFolderPath + "/" + strgfile);
fw.write("<br><tr><a href="+"\"" + reportFolderPath + "/" + strgfile+"\""+"/>"
+reportId+"</a></tr>");
}
else {
for(int i = 1; i < split.length; i++) {
//String org=+rname;
String title2=split[i] + " ";
}
//System.out.println("");
}
}
else {
fw.write("<br>"+"<h>"+filename +"</h>"+"<br>");
}
}
}
이것은'ReportGroup'과'ReportInfo' 모두의 인스턴스를 필요로하게 있는지 확인
ReportGroup
의 대상을, 그렇지 않으면ReportGroup.reportList.add(info)
를 사용할 수 있습니다. –
감사합니다. – Lokesh