All pastes #259535 Raw Edit

Anonymous

public text v1 · immutable
#259535 ·published 2006-11-27 15:26 UTC
rendered paste body
/*
 * primitiveDB.java
 *
 * Created on 27. November 2006, 15:41
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package javaapplication5;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author kj09
 */
public class primitiveDB {
    public ArrayList db;
    private ArrayList entry;
    /** Creates a new instance of primitiveDB */
    public primitiveDB() {
        db = new ArrayList();
        entry = new ArrayList();
    }
    public void add(int row, int col, String data){
        System.out.println("Data added to DB - Column: "+col+" Row: "+row+" Data: "+data);
        //Maybe this row is already existing in DB?
        if(db.size() >= row){ //Yes, this entry already exists.
            entry = (ArrayList) db.get(row);
            //Erase it, we dont want duplicates
            db.remove(entry);
            entry.add(col, entry);
            //Write it back:
            db.add(entry);
        } else { //No, no entry exists.
        entry = null;
        entry.add(col, data);
        db.add(entry); //Take that to the db
        }
    }
    public int getLastRow(){ //The LastRow of this db (ID)
        return(db.size());
    }
    public int getLastCol(int row){ //The LastColumn of a row (ID)
        entry = (ArrayList) db.get(row);
        return(entry.size());
    }
    
}