901 - From Databases to XML

All about problems in Volume 9. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
thurbo
New poster
Posts: 9
Joined: Wed Apr 05, 2006 2:00 pm
Location: Stockholm, Sweden

901 - From Databases to XML

Post by thurbo » Wed Oct 11, 2006 2:25 am

Hi,

The problem was more challenging than I thought :-).
Basically, I read testcases and output the resulting XML.
For every testcase I first determine the possible relationships between tables (assuming that primary keys can consist of one or more columns), I collect the root nodes (the nodes to be added under <DB>) which are the records from tables that do not have a reference to other tables (the problem states that there is exactly one such table but if there are more then I just add them under <DB> as well) AND the records from tables that point to another table but where the foreign key is empty or not existing.
Before adding a node, I collect the underlying nodes using recursion so that for new underlying nodes their underlying nodes will be collected as well.
Nodes will be sorted, both on name and on attributes.
That should be it. Am I missing something? (For example, what about spaces in the input?)
Here are some testcases:
S(#C,A,D)
R(#A,B)
T(E,A)
data
T(e1,a2)
S(c3,a1,d1)
S(c1,a2,d2)
S(c2,a1,d3)
R(a1,b1)
R(a2,b2)

QQ(#Q,Q,W)
data
QQ(q5,,w5)
QQ(q1,q0,w1)
QQ(q2,q1,w2)
QQ(q3,q1,w3)
QQ(q4,q2,w4)

XXX(#X,X1,X2,X3,X4,Y1,Y2)
YYY(#Y1,#Y2,Y3)
ZZZ(#Z,Y2,Z1,Z2)
data
YYY(y1,y1,yvalue1)
YYY(y2,y2,yvalue2)
XXX(x1,1,2,3,4,y1,y1)
XXX(x2,1,2,3,4,y2,y2)
XXX(x3,1,2,3,4,y2,y2)
XXX(x4,1,2,3,4,,)
ZZZ(z1,y2,v1,v2)
ZZZ(z2,y2,v1,v2)
ZZZ(z3,y2,v1,v2)
and my output:
<DB>
<R #A="a1" B="b1">
<S #C="c2" D="d3">
</S>
<S #C="c3" D="d1">
</S>
</R>
<R #A="a2" B="b2">
<S #C="c1" D="d2">
</S>
<T E="e1">
</T>
</R>
</DB>

<DB>
<QQ #Q="q1" Q="q0" W="w1">
<QQ #Q="q2" W="w2">
<QQ #Q="q4" W="w4">
</QQ>
</QQ>
<QQ #Q="q3" W="w3">
</QQ>
</QQ>
<QQ #Q="q5" Q="" W="w5">
</QQ>
</DB>

<DB>
<XXX #X="x4" X1="1" X2="2" X3="3" X4="4" Y1="" Y2="">
</XXX>
<YYY #Y1="y1" #Y2="y1" Y3="yvalue1">
<XXX #X="x1" X1="1" X2="2" X3="3" X4="4">
</XXX>
</YYY>
<YYY #Y1="y2" #Y2="y2" Y3="yvalue2">
<XXX #X="x2" X1="1" X2="2" X3="3" X4="4">
</XXX>
<XXX #X="x3" X1="1" X2="2" X3="3" X4="4">
</XXX>
</YYY>
<ZZZ #Z="z1" Y2="y2" Z1="v1" Z2="v2">
</ZZZ>
<ZZZ #Z="z2" Y2="y2" Z1="v1" Z2="v2">
</ZZZ>
<ZZZ #Z="z3" Y2="y2" Z1="v1" Z2="v2">
</ZZZ>
</DB>
I did try to find some more test input but could not find any at the site of the Porto University (where the problem originates) but it could be that my Portuguese is very bad :-).

To be complete, I'll enclose a copy of my program:

Code: Select all

#include <iostream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <vector>
#include <string>
#include <map>

struct TableData {
	std::string sName;
	std::vector<std::string> vColumns;
	std::vector< std::vector<std::string> > vData;
};

struct TableRelation { 
	std::string sReferencedTable; 
	std::map<size_t, size_t> mapColumns; 
}; 

struct XMLElement {
	std::string sName;
	std::map<std::string, std::string> mapAttributes;
	std::vector<XMLElement> vChildElements;

	friend std::ostream& operator<<(std::ostream& strm, const XMLElement& element) {
		strm << '<' << element.sName;
		for ( std::map<std::string, std::string>::const_iterator p = element.mapAttributes.begin(); p != element.mapAttributes.end(); ++p )
			strm << ' ' << p->first << "=\"" << p->second << '"'; 
		strm << '>' << std::endl;
		std::copy(element.vChildElements.begin(), element.vChildElements.end(), std::ostream_iterator<XMLElement>(strm));
		strm << "</" << element.sName << '>' << std::endl;

		return strm;
	}
};

struct IsTable : std::binary_function<std::string, TableData, bool> {
	bool operator()(const std::string& s, const TableData& table) const {
		return table.sName == s;
	}
};

struct IsKeyColumn : std::unary_function<std::string, bool> {
	bool operator()(const std::string& s) const {
		return s.length() && s[0] == '#';
	}
};

struct Key2Column : std::unary_function<std::string, std::string> {
	std::string operator()(const std::string& s) const {
		return s.substr(1);
	}
};

struct IsSourceColumn : std::binary_function<std::string, std::string, bool> {
	bool operator()(const std::string& s1, const std::string& s2) const {
		return s1 == s2.substr(1);
	}
};

struct IsRelated : std::binary_function<std::vector<std::string>, std::vector<std::string>, bool> { 
	const std::map<size_t, size_t>& mapColumns;

	IsRelated(const std::map<size_t, size_t>& _mapColumns)
		: mapColumns(_mapColumns)
	{}

	bool operator()(const std::vector<std::string> data, const std::vector<std::string>& sourceData) const {
		bool related = true;

		for ( std::map<size_t, size_t>::const_iterator p = mapColumns.begin(); related && p != mapColumns.end(); ++p )
			related = data[p->first] == sourceData[p->second];

		return related;
	}
}; 

struct Cmp_XMLElement : std::binary_function<XMLElement, XMLElement, bool> {
	bool operator()(const XMLElement& e1, const XMLElement& e2) const {
		bool cmp = false;

		if ( e1.sName < e2.sName )
			cmp = true;
		else if ( e1.sName == e2.sName ) {
			for ( std::map<std::string, std::string>::const_iterator p = e1.mapAttributes.begin(); p != e1.mapAttributes.end(); ++p ) {
				std::map<std::string, std::string>::const_iterator q = e2.mapAttributes.find(p->first);

				if ( p->second != q->second ) {
					if ( p->second < q->second )
						cmp = true;
					break;
				}
			}
		}

		return cmp;
	}
};

struct Problem {
	std::vector<TableData> vTables;

	friend std::istream& operator>>(std::istream& strm, Problem& problem) {
		bool bReadHeaders = true;
		std::string sLine;

		problem.vTables.clear();
		for ( bool bRead = true; bRead; ) {
			if ( strm.peek() != -1 ) {	// no std::char_traits<char>::eof()
				if ( std::getline(strm, sLine) && sLine != "" ) {
					if ( bReadHeaders && sLine == "data" )
						bReadHeaders = false;
					else {
						TableData data;
						std::string::size_type pos = sLine.find('(');
						std::string::size_type pos_orig = 0;

						data.sName = sLine.substr(0, pos);
						sLine = sLine.substr(pos + 1);
						sLine.resize(sLine.length() - 1);
						while ( (pos = sLine.find(',', pos_orig)) != std::string::npos ) {
							data.vColumns.push_back(sLine.substr(pos_orig, pos - pos_orig));
							pos_orig = pos + 1;
						}
						data.vColumns.push_back(sLine.substr(pos_orig));

						if ( bReadHeaders )
							problem.vTables.push_back(data);
						else {
							std::vector<TableData>::iterator p = std::find_if(problem.vTables.begin(), problem.vTables.end(), std::bind1st(IsTable(), data.sName));

							p->vData.push_back(data.vColumns);
						}
					}
				}
				else
					bRead = false;
			}
			else {
				if ( !problem.vTables.size() )
					std::getline(strm, sLine);
				bRead = false;
			}
		}

		return strm;
	}
};

struct Solution {
	bool first;
	XMLElement xml;

	friend std::ostream& operator<<(std::ostream& strm, const Solution& solution) {
		if ( !solution.first )
			strm << std::endl;

		return strm << solution.xml;
	}
};

class ProblemSolver {
	bool first;
public:
	ProblemSolver(void)
		: first(true)
	{}

	Solution operator()(const Problem& problem) {
		Solution solution;

		solution.first = first;
		first = false;

		solution.xml.sName = "DB";

		std::map<std::string, TableRelation> mapRelations = _FindRelations(problem);

		_AddRootElements(problem.vTables.begin(), problem.vTables.end(), mapRelations, solution.xml);

		return solution;
	}
private:
	void _AddRootElements(const std::vector<TableData>::const_iterator begin, const std::vector<TableData>::const_iterator end, const std::map<std::string, TableRelation>& mapRelations, XMLElement& xmlroot) {
		for ( std::vector<TableData>::const_iterator p = begin; p != end; ++p ) {
			std::map<std::string, TableRelation>::const_iterator pRelation = mapRelations.find(p->sName);

			if ( pRelation != mapRelations.end() ) {
				std::vector<TableData>::const_iterator q = std::find_if(begin, end, std::bind1st(IsTable(), pRelation->second.sReferencedTable));

				for ( std::vector< std::vector<std::string> >::const_iterator d = p->vData.begin(); d != p->vData.end(); ++d ) {
					if ( std::find_if(q->vData.begin(), q->vData.end(), std::bind1st(IsRelated(pRelation->second.mapColumns), *d)) == q->vData.end() )
						xmlroot.vChildElements.push_back(_NewElement(begin, end, mapRelations, *p, d, false));
				}
			}
			else {
				for ( std::vector< std::vector<std::string> >::const_iterator d = p->vData.begin(); d != p->vData.end(); ++d )
					xmlroot.vChildElements.push_back(_NewElement(begin, end, mapRelations, *p, d, false));
			}
		}
		std::sort(xmlroot.vChildElements.begin(), xmlroot.vChildElements.end(), Cmp_XMLElement());
	}

	XMLElement _NewElement(const std::vector<TableData>::const_iterator begin, const std::vector<TableData>::const_iterator end, const std::map<std::string, TableRelation>& mapRelations, const TableData& table, const std::vector< std::vector<std::string> >::const_iterator d, bool nested) {
		XMLElement node;

		node.sName = table.sName;
		if ( nested ) {
			std::map<std::string, TableRelation>::const_iterator p = mapRelations.find(table.sName);

			for ( size_t i = 0; i < table.vColumns.size(); ++i )
				if ( p->second.mapColumns.find(i) == p->second.mapColumns.end() )
					node.mapAttributes.insert(std::make_pair(table.vColumns[i], (*d)[i]));
		}
		else
			for ( size_t i = 0; i < table.vColumns.size(); ++i )
				node.mapAttributes.insert(std::make_pair(table.vColumns[i], (*d)[i]));

		for ( std::map<std::string, TableRelation>::const_iterator p = mapRelations.begin(); p != mapRelations.end(); ++p ) {
			if ( p->second.sReferencedTable == table.sName ) {
				std::vector<TableData>::const_iterator q = std::find_if(begin, end, std::bind1st(IsTable(), p->first));
				IsRelated isRelated(p->second.mapColumns);

				for ( std::vector< std::vector<std::string> >::const_iterator d2 = q->vData.begin(); d2 != q->vData.end(); ++d2 ) {
					if ( isRelated(*d2, *d) )
						node.vChildElements.push_back(_NewElement(begin, end, mapRelations, *q, d2, true));
				}
			}
		}
		std::sort(node.vChildElements.begin(), node.vChildElements.end(), Cmp_XMLElement());

		return node;
	}

	std::map<std::string, TableRelation> _FindRelations(const Problem& problem) {
		std::map<std::string, TableRelation> mapRelations;

		for ( std::vector<TableData>::const_iterator p = problem.vTables.begin(); p != problem.vTables.end(); ++p ) {
			std::vector<std::string> vKeys;

			std::remove_copy_if(p->vColumns.begin(), p->vColumns.end(), std::back_inserter(vKeys), std::not1(IsKeyColumn()));
			if ( vKeys.size() ) {
				std::transform(vKeys.begin(), vKeys.end(), vKeys.begin(), Key2Column());
				for ( std::vector<TableData>::const_iterator q = problem.vTables.begin(); q != problem.vTables.end(); ++q ) {
					std::vector<std::string> vColumns;

					std::remove_copy_if(q->vColumns.begin(), q->vColumns.end(), std::back_inserter(vColumns), IsKeyColumn());
					if ( vColumns.size() ) {
						std::vector<std::string> vForeignKeys;

						std::sort(vKeys.begin(), vKeys.end());
						std::sort(vColumns.begin(), vColumns.end());
						std::set_intersection(vKeys.begin(), vKeys.end(), vColumns.begin(), vColumns.end(), std::back_inserter(vForeignKeys));
						if ( vKeys.size() == vForeignKeys.size() ) {
							TableRelation relation;

							relation.sReferencedTable = p->sName;
							for ( std::vector<std::string>::const_iterator k = vForeignKeys.begin(); k != vForeignKeys.end(); ++k )
								relation.mapColumns.insert(std::make_pair(std::find(q->vColumns.begin(), q->vColumns.end(), *k) - q->vColumns.begin(), std::find_if(p->vColumns.begin(), p->vColumns.end(), std::bind1st(IsSourceColumn(), *k)) - p->vColumns.begin()));

							mapRelations.insert(std::make_pair(q->sName, relation));
						}
					}
				}
			}
		}

		return mapRelations; 
	}
}; 

void main(void) {
	std::transform(std::istream_iterator<Problem>(std::cin), std::istream_iterator<Problem>(), std::ostream_iterator<Solution>(std::cout), ProblemSolver());
}
Greetings,

Jeroen

bryan986
New poster
Posts: 2
Joined: Mon Oct 08, 2007 9:51 am

Post by bryan986 » Mon Oct 08, 2007 10:19 am

I have been working on this one as well but keep getting wrong answer.

Here are some issues I have with the description:

- It doesn't specifically say if spaces are allowed in the headers or data.
We can probably allow spaces without a side effect. I tried this but it didn't help.

- There is an inconsistency in the description, in one spot it says "...opening tag <R #A="a1" B= "b1">..." and then in another it says "...no extra spaces, for instance around ="
I am assuming that the tag example is a typo and that there shouldn't be any extra spaces around the = sign

- The problem does not say if multiple keys are allowed. This wouldn't really make sense anyway, especially in real databases. I suppose it would be possible to implement this.

- It doesn't say if blank columns are allowed in the data section. I would guess they are not. If it does, do we make a tag parameter with an empty string or do we exclude it alltogether?

- If a table references itself, do we include the tag parameter or not?


Gotta get this one solved, lol!!

bryan986
New poster
Posts: 2
Joined: Mon Oct 08, 2007 9:51 am

Post by bryan986 » Fri Oct 19, 2007 5:57 am

Here is my Java code so far, gets a wrong answer:

Code: Select all

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    private HashMap<String,Table> tables;
    private HashMap<String,Table> keys;
    private HashMap<String,ArrayList<Table>> columns;
    
    private boolean showSelfReferenceParameters = true; // Problem does not specify
    private boolean showReferenceColumnAsParameter = false; // Problem says this should be false
    
    public Main(InputStream is) {
        Scanner s = new Scanner(is);
        
        while(s.hasNext()){
            keys = new HashMap();
            tables = new HashMap();
            columns = new HashMap();
            
            String line = null;
            
            //Table setup
            while(s.hasNext()){
                line = s.nextLine();
                
                //Stop setting up tables at the data section
                if(line.equals("data")){
                    break;
                }
                
                String[] tableInfo = line.split("[\\(,\\) ]+");
                
                //First string is the table name, the rest are the columns
                Table t = new Table(tableInfo[0]);
                
                //Process each column in the table
                for(int i=1;i<tableInfo.length;i++){
                    
                    if(tableInfo[i].charAt(0)=='#'){
                        //Column name with # is the key
                        String columnName = tableInfo[i].substring(1);
                        int columnPos = i-1;
                        
                        KeyColumn c = new KeyColumn(columnName,columnPos);
                        t.addColumn(c);
                    }else{
                        //Column without # is a normal column
                        String columnName = tableInfo[i];
                        int columnPos = i-1;
                        
                        Column c = new Column(columnName,columnPos);
                        t.addColumn(c);
                    }
                }
            }
            
            //Find the root Tables (the Tables with no external references)
            ArrayList<Table> roots = new ArrayList();
            //Get all tables
            ArrayList<Table> tableList = new ArrayList(tables.values());
            //Find tables with no references
            for(int i=0;i<tableList.size();i++){
                if(!tableList.get(i).hasReference()){
                    roots.add(tableList.get(i));
                }
            }
            
            //Data section
            while(s.hasNext()){
                line = s.nextLine();
                //Blank line signals the end of a database listing
                if(line.trim().equals("")){
                    break;
                }
                String[] tableData = line.split("[\\(,\\) ]+");
                
                //Get the existing table with this name
                Table t = tables.get(tableData[0]);
                
                //Populate an array with the column data
                ArrayList<String> data = new ArrayList();
                for(int i=0;i<t.getColumnsLength();i++){
                    data.add(tableData[i+1]);
                }
                t.addData(data);
            }
            
            //Print out the xml format
            System.out.println("<DB>");
            for(int i=0;i<roots.size();i++){
                System.out.println(roots.get(i).getXML());
            }
            System.out.print("</DB>");
            
            if(s.hasNext()){
                System.out.println("\n");
            }
        }
    }
    
    private class Table implements Comparable{
        private String name;
        private ArrayList<Column> allColumnsList;
        private HashMap<String,ArrayList<Column>> regularColumns;
        private HashMap<String,KeyColumn> keyColumns;
        private ArrayList<ArrayList<String>> tableData;
        
        public Table(String name){
            this.name=name;
            regularColumns = new HashMap();
            keyColumns = new HashMap();
            allColumnsList = new ArrayList();
            tableData = new ArrayList();
            
            //Add to the global table map
            tables.put(this.name,this);
        }
        
        public void addColumn(Column c){
            //Add to the local column map
            if(!regularColumns.containsKey(c.getName())){
                regularColumns.put(c.getName(),new ArrayList());
            }
            ArrayList<Column> cols = regularColumns.get(c.getName());
            cols.add(c);
            
            //Add to the local column list
            allColumnsList.add(c);
            
            //Add to the global column map
            if(!columns.containsKey(c.getName())){
                columns.put(c.getName(),new ArrayList());
            }
            ArrayList<Table> tbls = columns.get(c.getName());
            if(!tbls.contains(this)){
                tbls.add(this);
            }
        }
        
        public void addColumn(KeyColumn c){
            //Add to the local key column map
            keyColumns.put(c.getName(),c);
            
            //Add to the local column list
            allColumnsList.add(c);
            
            //Add to the global key map
            keys.put(c.getName(),this);
        }
        
        public ArrayList<Column> getColumns(String name){
            return regularColumns.get(name);
        }
        
        public KeyColumn getKeyColumn(String name){
            return keyColumns.get(name);
        }
        
        public Column getColumn(int column) {
            return allColumnsList.get(column);
        }
        
        public int getColumnsLength(){
            return allColumnsList.size();
        }
        
        public String getName(){
            return name;
        }
        
        public void addData(ArrayList<String> data){
            tableData.add(data);
        }
        
        public ArrayList<ArrayList<String>> getData(){
            return tableData;
        }
        
        public boolean hasReference(){
            for(int i=0;i<allColumnsList.size();i++){
                // Check if columns references an existing key
                // Skip over the key columns (They don't reference anything)
                Column c = allColumnsList.get(i);
                if(!c.isKey() && keys.containsKey(c.getName())){
                    return true;
                }
            }
            return false;
        }
        
        // Compare order:
        // 1. Table name
        // 2. Column names
        public int compareTo(Object o){
            Table t = (Table)o;
            
            int nameComp = getName().compareTo(t.getName());
            if(nameComp==0){
                //If the table names are the same, then sort by column names
                for(int i=0;i<allColumnsList.size();i++){
                    int colNameComp = getColumn(i).compareTo(t.getColumn(i));
                    if(colNameComp!=0){
                        return colNameComp;
                    }
                }
                return 0;
            }else{
                return nameComp;
            }
        }
        
        public boolean equals(Object o){
            return compareTo(o)==0;
        }
        
        //Get XML for a root table
        public String getXML(){
            //Data in table must be sorted
            Collections.sort(tableData,new DataComparator());
            
            //Construct the tags
            StringBuilder xml = new StringBuilder();
            
            //Create tags for each row in the table
            for(int rowIndex=0;rowIndex<tableData.size();rowIndex++){
                xml.append(getTag(rowIndex,null));
                if(rowIndex<tableData.size()-1){
                    xml.append("\n");
                }
            }
            
            return xml.toString();
        }
        
        //Get XML for a child table
        public String getXML(Column searchColumn, String searchData){
            //Construct the tags
            StringBuilder xml = new StringBuilder();
            
            //Data in table must be sorted
            Collections.sort(tableData,new DataComparator());
            //Child table must have matching pair of keyColumn and keyData
            
            //Check for matching column
            if(!regularColumns.containsKey(searchColumn.getName())){
                return "";
            }
            //Get a list of matching columns in the table
            ArrayList<Column> cols = regularColumns.get(searchColumn.getName());
            
            //Search each matching column for matching data
            for(int i=0;i<cols.size();i++){
                int colIndex = cols.get(i).getNum();
                //Search through each row of the column for the data
                for(int rowIndex = 0; rowIndex<tableData.size();rowIndex++){
                    if(tableData.get(rowIndex).get(colIndex).equals(searchData)){
                        xml.append(getTag(rowIndex, searchColumn)).append("\n");
                    }
                }
            }
            return xml.toString();
        }
        
        
        //Get xml tag for a particular row
        private String getTag(int rowIndex, Column parentColumn){
            StringBuilder tag = new StringBuilder();
            
            //Tag opening
            tag.append("<").append(getName());
            
            //Show all of the parameters in this row (each column in the row)
            ArrayList<String> rowData = tableData.get(rowIndex);
            for(int colIndex=0;colIndex<rowData.size();colIndex++){
                Column column = getColumn(colIndex);
                
                // Whether or not to show parameters that reference their own table (self reference)
                if(!column.isKey() && keyColumns.containsKey(column.getName()) && !showSelfReferenceParameters){
                    continue;
                }
                
                //Whether or not to show parameters that are references to parent table
                //parentColumn is null if this is a root table
                if(!column.isKey() && parentColumn!=null && column.equals(parentColumn) && !showReferenceColumnAsParameter){
                    continue;
                }
                
                tag.append(" ");
                
                if(column.isKey()){
                    tag.append("#");
                }
                tag.append(column.getName()).append("=\"");
                tag.append(rowData.get(colIndex)).append("\"");
            }
            tag.append(">\n");
            
            //Get all the child elements for each key in this row
            ArrayList<Column> keyList = new ArrayList(keyColumns.values());
            for(int j=0;j<keyList.size();j++){
                Column keyColumn = keyList.get(j);
                //Get the data associated with this key
                //Any child table must have a column with this key and data
                String keyData = rowData.get(keyColumn.getNum());
                
                //Check if there are child tables for this key
                if(columns.containsKey(keyColumn.getName())){
                    ArrayList<Table> subTables = columns.get(keyColumn.getName());
                    //Child tables need to go in order of table name and then column names
                    Collections.sort(subTables);
                    //Get the xml for all the child tables
                    for(int k=0;k<subTables.size();k++){
                        Table t = subTables.get(k);
                        
                        tag.append(t.getXML(keyColumn,keyData));
                    }
                }
            }
            
            //Tag closing
            tag.append("</").append(getName()).append(">");
            
            return tag.toString();
        }
        
        private class DataComparator implements Comparator<ArrayList<String>>{
            public DataComparator(){
            }
            
            public int compare(ArrayList<String> s1, ArrayList<String> s2){
                for(int i=0;i<s1.size();i++){
                    int strComp = s1.get(i).compareTo(s2.get(i));
                    if(strComp!=0){
                        return strComp;
                    }
                }
                return 0;
            }
            
            public boolean equals(ArrayList<String> s1, ArrayList<String> s2){
                return compare(s1,s2)==0;
            }
        }
        
    }
    
    private class Column implements Comparable{
        protected String name;
        protected int num;
        
        public Column(String name, int num){
            this.name=name;
            this.num=num;
        }
        
        public boolean isKey(){
            return false;
        }
        
        public String getName() {
            return name;
        }
        
        public String toString(){
            return name;
        }
        
        public int getNum() {
            return num;
        }
        
        public int compareTo(Object o){
            Column c = (Column)o;
            
            return name.compareTo(c.getName());
        }
        
        public boolean equals(Object o){
            Column c = (Column)o;
            return name.equals(c.getName());
        }
    }
    
    private class KeyColumn extends Column{
        public KeyColumn(String name, int num){
            super(name,num);
        }
        
        public boolean isKey(){
            return true;
        }
    }
    
    public static void main(String[] args){
        new Main(System.in);
    }
    
}

Eduardo790
New poster
Posts: 2
Joined: Wed Sep 07, 2011 2:02 pm

Re: 901 - From Databases To XML

Post by Eduardo790 » Wed Sep 07, 2011 2:05 pm

hi, bryan986,
Action Open = new AbstractAction("Open", new ImageIcon("open.gif")) {
public void actionPerformed(ActionEvent e) {
saveOld();
if(dialog.showOpenDialog(null)==JFi… {
readInFile(dialog.getSelectedFile(…
}
SaveAs.setEnabled(true);
}
};
Action Save = new AbstractAction("Save", new ImageIcon cell phone tracking ("save.gif")) {
public void actionPerformed(ActionEvent e) {
if(!CurrentFile.equals("Untitled"))
saveFile(CurrentFile);

Post Reply

Return to “Volume 9 (900-999)”