使用UML的类层次结构

时间:2014-03-29 17:41:28

标签: java file uml

任务是使用这个简单的图表Diagram创建类/接口层次结构。有人可以检查我的尝试,并说出我做错了什么。我需要类SystemFile才能保持我的IFile对象的数组取决于currentDirectory值。实现IFile接口的类需要像File类那样执行一些FIle类方法。另一个问题是在listFiles方法中,它返回File值,我怎样才能使它成为IFile?

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.cert.Extension;

public interface IFile {
public String getName();

public String getParent();

public String getPath();

public String getAbsolutePath();

public long lastModified();

public boolean isFile();

public boolean isDirectory();

public long size();

public boolean exists();

public boolean delete();

public File[] listFiles();

public InputStream getInputStream();

public OutputStream getOutputStream();

public Extension getFileExtension();

}
 import java.io.File;
 import java.util.Date;

import javax.swing.filechooser.FileSystemView;
 import javax.swing.table.AbstractTableModel;

 public class FileSystemTableModel extends AbstractTableModel implements
    Constants {

private IFile currentDirectory;
private IFile[] files;


@Override
public int getColumnCount() {
    return 3;  
}

@Override
public int getRowCount() {
    // TODO Auto-generated method stub
    return files.length;
}

@Override
public Object getValueAt(int arg0, int arg1) {

    switch (arg1) {
    case 0:
        if(FileSystemView.getFileSystemView().isDrive((IFile)files[arg0]))
        return files[arg0].toString();
        else
            return files[arg0].getName();
    case 1:
        return files[arg0].size();
    case 2:
        return new Date(files[arg0].lastModified());
    }
    return arg1;    
}

@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
    // TODO Auto-generated method stub
    return false;
}

public IFile getCurrentDirectory() {
    return currentDirectory;
}

public void setCurrentDirectory(IFile currentDirectory) {
    this.currentDirectory = currentDirectory;
}

public void setFiles(IFile[] files) {
    this.files = files;
}

public IFile[] getFiles() {
    return files;
}


@Override
public String getColumnName(int column) {
    switch(column){
    case 0:
        return TABLE_COLUMN_NAME;
    case 1:
        return TABLE_COLUMN_SIZE;
    case 2:
        return TABLE_COLUMN_MODIFIED;
    } 

    return null;
}
 }
 public class SystemFile extends File implements IFile {


 public SystemFile(String arg0) {
    super(arg0);
    // TODO Auto-generated constructor stub
}

 @Override
 public String getName() {
// TODO Auto-generated method stub
return super.getName();
}

@Override
public String getParent() {
    // TODO Auto-generated method stub
    return super.getParent();
}

@Override
public String getPath() {
    // TODO Auto-generated method stub
    return super.getPath();
}

@Override
public String getAbsolutePath() {
    // TODO Auto-generated method stub
    return super.getAbsolutePath();
}

@Override
public long lastModified() {
    // TODO Auto-generated method stub
    return super.lastModified();
}

@Override
public boolean isFile() {
    // TODO Auto-generated method stub
    return super.isFile();
}

@Override
public boolean isDirectory() {
    // TODO Auto-generated method stub
    return super.isDirectory();
}

public long size() {
    // TODO Auto-generated method stub
    return super.length();
}

@Override
public boolean exists() {
    // TODO Auto-generated method stub
    return super.exists();
}

@Override
public boolean delete() {
    // TODO Auto-generated method stub
    return super.delete();
}

@Override
public File[] listFiles() {
    // TODO Auto-generated method stub
    return super.listFiles();
}

@Override
public InputStream getInputStream() {
    // TODO Auto-generated method stub
    return null;
}

@Override
public OutputStream getOutputStream() {
    // TODO Auto-generated method stub
    return null;
}

@Override
public Extension getFileExtension() {
    // TODO Auto-generated method stub
    return null;
}

 }

我还没有使用remotefile类。

0 个答案:

没有答案