Results 1 to 20 of 20
  1. #1
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default cant understand what this means

    hello
    i am doing a assignment in java for the database and i am stuck in the assignment. Please help me understand this statement

    private final List<Comparable []> tuples= new ArrayList<Comparable []> ();

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    The question is far too generic for me to list the array of comparables.
    My Hobby Project: LegacyClone

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    The statement merely declares and initializes a List of arrays as an ArrayList of arrays.
    Each array contains objects that we don't know much about except that they all implement the Comparable interface. The variable tuples will always be pointing to this initialized list.

  4. #4
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default

    this is too much confusing,, can u please explain it to me,,
    i am a new programmer to java and I am having a lot of difficulties in making this project,, and have to submit by tomorrow,, please help

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Perhaps you can get better help if you provide more context for your question. Where did you see this line? How are you supposed to be using this? Anything you know, let us know.

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You are going to fail your project then. You should have started your project earlier when you had the time to learn about all these concepts. Now you've suddenly got all these new terms and new concepts that you must grasp and use in a project to be submitted tomorrow.
    No one is going to be able to teach you all you need to understand today.
    At least you've leaned the lesson of never postponing for tomorrow what you can do today.

  7. #7
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default

    Yes u are right,, but right now i need help more than critisizm,, if you cant help me,, then dont try to ,,, anyways if u want to help me please participate,,

    @fubarable,,i m using this line to get the list of tuples in the table,, which are given as

    private final List<Comparable []> tuples= new ArrayList<Comparable []> ();

    right now i am stuck in the 'comparable' interface in this line,, i have another hint of code,, but i dont no how to use it to get it working


    Comparable [] values0 = { "Star_Wars" , 1977, 124, "T", "Fox", 12345 };
    this line is i think is used in the programm

  8. #8
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Each element of the 'tuples' list is an array of Comparables. Comparable is an interface that classes can implement so their objects can be compared. The list can contain arrays of any object that implements the Comparable interface. String implements the Comparable interface, so Strings can be in the arrays.

  9. #9
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    you never say what you are having trouble with... you just said you're stuck on a line without saying a thing about what's wrong with it, what you think is wrong with it, what you've tried, etc.

    it's hard for people to give you useful help when we don't even know what you understand.

  10. #10
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default

    import static java.lang.System.*;
    import java.io.*;
    import java.util.*;


    /************************************************** ***************************************
    * This class implements relational database tables (including attribute names, domains
    * and a list of tuples. Five basic relational algebra operators are provided: project,
    * select, union and minus. The insert data manipulation operator is also provided.
    * Missing are update and delete data manipulation operators, primary keys, duplicate
    * elimination and indexes.
    */
    public class Table implements Serializable, Cloneable
    {
    /** Serializable class version number.
    */
    private static final long serialVersionUID = 11L;

    /** Counter for naming temporary tables.
    */
    private static int count = 0;

    /** Table name.
    */
    private final String name;

    /** Array of attribute names.
    */
    private final String [] attribute;

    /** Array of attribute domains: a domain may be
    * real: Double, Float; integer: Long, Integer, Short, Byte; string: String
    */
    private final Class [] domain;

    /** Collection of tuples.
    */
    private final List<Comparable []> tuples;


    /************************************************** ***********************************
    * Construct an empty table from the meta-data specifications.
    * @param name The name of the relation.
    * @param attribute String containing attributes names
    * @param domain String containing attribute domains (data types).
    */
    public Table (String name, String [] attribute, Class [] domain)
    {
    this.name = name;
    this.attribute = attribute;
    this.domain = domain;
    this.tuples = new ArrayList<Comparable []> ();

    } // Table


    /************************************************** ***********************************
    * Construct an empty table from the raw string specifications.
    * @param name The name of the relation.
    * @param attributes String containing attributes names
    * @param domains String containing attribute domains (data types).
    */
    public Table (String name, String attributes, String domains)
    {
    this.name = name;
    this.attribute = attributes.split (" ");
    this.domain = findClass (domains.split (" "));
    this.tuples = new ArrayList<Comparable []> ();

    } // Table


    /************************************************** ***********************************
    * Construct an empty table using the meta-data of an existing table.
    * @param tab The table supplying the meta-data.
    * @param suffix The suffix appended to create new table name.
    */
    public Table (Table tab, String suffix)
    {
    this (tab.name + suffix, tab.attribute, tab.domain);

    } // Table


    /************************************************** ***********************************
    * Project the tuples onto a lower dimension by keeping only the given attributes.
    * #usage movie.project ("title year studioName")
    * @param attributeList Attributes to project onto.
    * @return Table of projected tuples.
    */
    public Table project (String attributeList)
    {
    out.println ("" + name + " . project ( " + attributeList + " )");

    String [] pAttribute = attributeList.split (" ");
    Class [] colDomain = extractDom (match (pAttribute), domain);
    Table result = new Table (name + count++, pAttribute, colDomain);

    for (int i = 0; i < tuples.size (); i++) {

    //\\//\\ TO BE IMPLEMENTED //\\//\\

    } // for

    return result;

    } // project


    /************************************************** ***********************************
    * Select the tuples satisfying the given condition.
    * A condition is written as infix expression consists of
    * 6 comparison operators: "==", "!=", "<", "<=", ">", ">="
    * 2 Boolean operators: "&", "|" (from high to low precedence)
    * #usage movie.select ("1979 < year & year < 1990")
    * @param condition Check condition for tuples.
    * @return Table with tuples satisfying the condition.
    */
    public Table select (String condition)
    {
    out.println ("" + name + " . select ( " + condition + " )");

    Table result = new Table (name + count++, attribute, domain);

    String [] postfix = infix2postfix (condition.split (" "));

    for (Comparable [] tup : tuples) {
    if (evalTup (postfix, tup)) {
    result.tuples.add (tup);
    } // if
    } // for

    return result;

    } // select


    /************************************************** ***********************************
    * Union this table and table 2.
    * #usage movie.union (show)
    * @param table2 The rhs table in the union operation.
    * @return Table representing the union.
    */
    public Table union (Table table2)
    {
    out.println ("" + name + " . union ( " + table2.name + " )");

    Table result = new Table (name + count++, attribute, domain);

    //\\//\\ TO BE IMPLEMENTED //\\//\\

    return result;

    } // union


    /************************************************** ***********************************
    * Take the difference of this table and table 2.
    * #usage movie.minus (show)
    * @param table2 The rhs table in the minus operation.
    * @return Table representing the difference.
    */
    public Table minus (Table table2)
    {
    out.println ("" + name + " . minus ( " + table2.name + " )");

    Table result = new Table (name + count++, attribute, domain);

    //\\//\\ TO BE IMPLEMENTED //\\//\\

    return result;

    } // minus


    /************************************************** ***********************************
    * Insert a tuple to the table.
    * #usage movie.insert ("'Star_Wars'", 1977, 124, "T", "Fox", 12345)
    * @param tuple Array of attribute values.
    * @return Whether insertion was successful.
    */
    public boolean insert (Comparable [] tup)
    {
    out.println ("insert ( " + tup + " )");

    if (typeCheck (tup)) {
    tuples.add (tup);
    return true;
    } else {
    return false;
    } // if

    } // insert


    /************************************************** ***********************************
    * Print the table.
    */
    public void print ()
    {
    out.println ("\n\n Table " + name);
    for (String a : attribute) {
    out.print (" " + a + " ");
    } // for
    out.println ();
    for (Comparable [] tup : tuples) {
    out.print ("[");
    for (Comparable attr : tup) {
    out.print (attr + " ");
    } // for
    out.println ("]");
    } // for

    } // print


    /************************************************** ***********************************
    * Get the column position for the given attribute name.
    * @param attr The given attribute name.
    * @return The column position.
    */
    private int columnPos (String attr)
    {
    for (int i = 0; i < attribute.length; i++) {
    if (attribute [i].equals (attr)) {
    return i;
    } // if
    } // for

    return -1; // not found

    } // columnPos


    /************************************************** ***********************************
    * Check whether the tuple satisfies the condition.
    * @param pCondition The postfix expression for the condition
    * @param tup The tuple to check.
    * @return Whether to keep the tuple.
    */
    private boolean evalTup (String [] pCondition, Comparable [] tup)
    {
    if (pCondition == null) {
    return true;
    } // if

    Stack<Object> s = new Stack<Object> ();

    //\\//\\ TO BE IMPLEMENTED //\\//\\
    s.push (Boolean.TRUE);

    return (Boolean) s.pop ();

    } // evalTup


    /************************************************** ***********************************
    * Convert an infix expression to a postfix expression. This implementation does not
    * handle parentheses.
    * @param infix A tokenized infix expression.
    * @return The resultant tokenized postfix expression.
    */
    private String [] infix2postfix (String [] infix)
    {
    String [] postfix = null;
    if (infix != null && infix.length > 0) {
    postfix = new String [infix.length];
    } // if

    //\\//\\ TO BE IMPLEMENTED //\\//\\

    return postfix;

    } // infix2postfix


    /************************************************** ***********************************
    * Match the column and attribute names to determine the domains.
    * @param column Array of column names.
    * @return Array of column index position.
    */
    private int [] match (String [] column)
    {
    int [] colPos = new int [column.length];

    for (int j = 0; j < column.length; j++) {
    boolean matched = false;
    for (int k = 0; k < attribute.length; k++) {
    if (column [j].equals (attribute [k])) {
    matched = true;
    colPos [j] = k;
    } // for
    } // for
    if ( ! matched) {
    out.println ("match: domain not found for " + column [j]);
    } // if
    } // for

    return colPos;

    } // match


    /************************************************** ***********************************
    * Check the size of the tuple (number of elements in list) as well as the type of
    * each value to ensure it is from the right domain.
    * @param tup The tuple as a list of attribute values.
    * @return Whether the tuple has the right size and values that comply
    * with the given domains.
    */
    private boolean typeCheck (Comparable [] tup)
    {

    //\\//\\ TO BE IMPLEMENTED //\\//\\

    return true;

    } // typeCheck


    /************************************************** ***********************************
    * Find the classes in the "java.lang" package with given names.
    * @param className Array of class name (e.g., {"Integer", "String"})
    * @return Array of Java classes.
    */
    private Class [] findClass (String [] className)
    {
    Class [] classArray = new Class [className.length];

    for (int i = 0; i < className.length; i++) {
    try {
    classArray [i] = Class.forName ("java.lang." + className [i]);
    } catch (ClassNotFoundException ex) {
    out.println ("findClass: " + ex);
    } // try
    } // for

    return classArray;

    } // findClass


    /************************************************** ***********************************
    * Extract the corresponding domains.
    * @param colPos Column positions to extract.
    * @param group Where to extract from.
    * @return The extracted domains.
    */
    private Class [] extractDom (int [] colPos, Class [] group)
    {
    Class [] obj = new Class [colPos.length];

    for (int j = 0; j < colPos.length; j++) {
    obj [j] = group [colPos [j]];
    } // for

    return obj;

    } // extractDom


    /************************************************** ***********************************
    * Main method for testing purpose only.
    * @param args Command-line arguments.
    */
    public static void main (String [] args)
    {
    out.println ("----------------------------------------------------------------------");
    Comparable [] values0 = { "Star_Wars" , 1977, 124, "T", "Fox", 12345 };
    Comparable [] values1 = { "Star_Wars_2", 1980, 124, "T", "Fox", 12345 };
    Comparable [] values2 = { "Rocky", 1985, 200, "T", "Universal", 12125 };
    Comparable [] values3 = { "Rambo", 1978, 100, "T", "Universal", 32355 };

    out.println ("\n----------------------- CreateTable movie ----------------------------");
    Table movie = new Table ( "movie", "title year length inColor studioName producerCno",
    "String Integer Integer String String Integer");
    out.println ("------------------------------------------------------------------------");
    movie.insert (values0);
    movie.insert (values1);
    movie.insert (values2);
    movie.print ();

    out.println ("\n----------------------- CreateTable cinema ---------------------------");
    Table cinema = new Table ("cinema", "title year length inColor studioName producerCno",
    "String Integer Integer String String Integer");
    cinema.insert (values1);
    cinema.insert (values2);
    cinema.insert (values3);
    cinema.print ();

    out.println ("\n----------------------- Test Project ---------------------------------");
    Table t_project = movie.project ("title year");
    t_project.print ();

    out.println ("\n----------------------- Test Select ----------------------------------");
    Table t_select = movie.select ("title == 'Star_Wars'");
    t_select.print ();

    out.println ("\n----------------------- Test Union -----------------------------------");
    Table t_union = movie.union (cinema);
    t_union.print ();

    out.println ("\n----------------------- Test Minus -----------------------------------");
    Table t_minus = movie.minus (cinema);
    t_minus.print ();

    } // main


    } // Table class

  11. #11
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default

    this is the whole programm, i am having trouble with the specific parts which says to be implemented,, if u can help me figure out these parts,, i have done most of the work,, but im stuck in specific places
    thanks in advance

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    1) Use code tags when posting code, since without them, your code is close to unreadable.
    2) You need to tell us more about how you're stuck, what you've tried, etc...

  13. #13
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default

    I am trying to find out what the comparable is doing inside the list<> interface and what is the function of this comparable array in this program

  14. #14
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    If you could edit your post and put the tags [code] and [/code] around them, it would be very helpful, as Fubarable said. If you could also give us an idea of what you think would work, that would help as well.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  15. #15
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by hasysf View Post
    Yes u are right,, but right now i need help more than critisizm,, if you cant help me,, then dont try to ,,, anyways if u want to help me please participate,,

    ...
    I have already tried to help. I answered your question fully.
    No problem, I'll just add you to my ignore list.

  16. #16
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    private final List<Comparable []> tuples= new ArrayList<Comparable []> ();
    ok, lets do this one part at a time.
    private - this is the scope. As private, it can only be used in this Class or it's nested classes
    final - it will not be modified
    List - the generic super-type which is extended by ArrayList and others
    <> - Generics, specifies the type of data contained in the structure
    Comparable - an interface. Anything that realizes this interface implements a compareTo() method. Thats all it means.
    [] - an array
    <Comparable []> - Specifies the data type as an array of objects that realize Comparable
    tuples - your object name
    new - instantiation
    ArrayList - part of the collections framework. Basically a dynamic array (or dynamic vector).
    ArrayList<Comparable []> - create an ArrayList that will be filled with arrays of Comparable objects. So, in english/pseudocode, you could read the statement as:

    define a private unchanging list of comparable arrays, call it tuples, then create the tuples object and store an ArrayList of Comparable arrays there. You could have also written it like this:
    Java Code:
    private final ArrayList<Comparable []> tuples= new ArrayList<Comparable []> ();
    Though, I agree with everyone else -- the day before this is due is a recipe for failure. You should have an understanding of this syntax weeks before an assignment is due (or at least days).

    Good luck, I hope it becomes clear to you :D

  17. #17
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by quad64bit View Post
    ...
    define a private unchanging list of comparable arrays, call it tuples, then create the tuples object and store an ArrayList of Comparable arrays there. ...
    Wrong. It's not a list of Comparable arrays. It's a list of arrays that contain Comparable objects. Read the first responses already posted in this thread. No need to try to repeat the answers.

  18. #18
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default

    thanks to every one,, it really helps
    i hope u guys dont mind my ignorance

  19. #19
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    It's a list of arrays that contain Comparable objects.
    Correct, that is what I was trying to say, apparently it was misinterpreted. When I say make an int array, I mean int[] which is an array of int's, not an array that is itself comparable (is that even possible with regular arrays [] ?). I meant the same by Comparable array (array of comparables) but I can see how that could be confused.

    Thanks for addressing my semantics.

    P.S. The OP was asking some of the same questions, so I summed everything together into one post that examined the statement piece by piece. I apologize if someone felt I was stepping on toes, I was simply trying to provide a different approach to help the OP. If you didn't like my post, that is fair, but lets let the original poster decide if I was helpful or not.
    Last edited by quad64bit; 09-05-2009 at 03:59 PM.

  20. #20
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by quad64bit View Post
    Correct, that is what I was trying to say, apparently it was misinterpreted. When I say make an int array, I mean int[] which is an array of int's, not an array that is itself comparable (is that even possible with regular arrays [] ?). I meant the same by Comparable array (array of comparables) but I can see how that could be confused.

    Thanks for addressing my semantics.
    My fault then. I read English semantics not pseudo code semantics in that statement.

Similar Threads

  1. what does this means HTTP Status 500 -
    By gissah in forum New To Java
    Replies: 0
    Last Post: 03-28-2009, 04:27 AM
  2. [SOLVED] what does the colon means?
    By PureAwesomeness in forum New To Java
    Replies: 3
    Last Post: 02-04-2009, 06:17 AM
  3. what does this error means?
    By tiiim83 in forum New To Java
    Replies: 2
    Last Post: 01-06-2009, 04:17 PM
  4. Does anyone know what these error means?
    By minifish in forum New To Java
    Replies: 2
    Last Post: 11-04-2008, 05:37 AM
  5. Need Help Can anyone explain what this means
    By Clemenza1983 in forum New To Java
    Replies: 6
    Last Post: 02-16-2008, 04:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •