Demo entry 6319354

Directory is a class that implements AbstractFile class

   

Submitted by anonymous on Nov 07, 2016 at 22:59
Language: Java. Code size: 867 Bytes.

package composite.example1;

import java.util.ArrayList;
import java.awt.Composite;

import javax.swing.text.html.HTMLDocument.HTMLReader.IsindexAction;

public class Directory implements AbstractFile {

	private String m_name;
    private ArrayList<Object> m_files = new ArrayList<Object>();
    
	public Directory(String name)
	{
		m_name = name;
	}
	
	public void add(Object obj)
	{
		m_files.add(obj);
	}
	
	public void ls()
	{
		
        for (int i = 0; i < m_files.size(); ++i)
        {
            Object obj = m_files.get(i);
            // Recover the type of this object
            if (obj  instanceof Directory )
              ((Directory)obj).ls();
            else
              ((File)obj).ls();
        }
	}
	
	
}


package composite.example1;

public interface AbstractFile {

	public void ls();
	
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).