Comparing TreePaths using equals()

hello,
  I am trying to use the equals() method on two TreePaths...
one path is obtained like....
TreePath test_path = new TreePath(tree.getSelectionPath());
the other path is got from a vector of all the paths on my Jtree.
this vector is built by the code below
public void getPaths(JTree tree, TreePath parent, Vector list) {
        list.add(parent);
        // Create paths for all children
        TreeNode node = (TreeNode)parent.getLastPathComponent();
        if (node.getChildCount() >= 0) {
            for (Enumeration e1=node.children(); e1.hasMoreElements(); ) {
                TreeNode nt = (TreeNode)e1.nextElement();
                TreePath path = parent.pathByAddingChild(nt);
                getPaths(tree, path, list);
problem is when i try this....
for(i=0; i<list.size(); i++){
               TreePath pop_path = (TreePath)list.elementAt(i);
               if(test_path.equals(pop_path)){
                    System.out.println(test_path.toString() + " equals " + pop_path.toString() );
               else{
                    System.out.println(test_path.toString() + " no equals " + pop_path.toString() );
I get this output.....
[[Files and Dirs to Backup, /home/mohadib/test_dir1]]jd path
[[Files and Dirs to Backup, /home/mohadib/test_dir1]] no equals [Files and Dirs to Backup]
[[Files and Dirs to Backup, /home/mohadib/test_dir1]] no equals [Files and Dirs to Backup, /home/mohadib/test_dir1]
[[Files and Dirs to Backup, /home/mohadib/test_dir1]] no equals [Files and Dirs to Backup, /home/mohadib/test_dir1, /home/mohadib/test_dir1/z]
[[Files and Dirs to Backup, /home/mohadib/test_dir1]] no equals [Files and Dirs to Backup, /home/mohadib/test_dir1, /home/mohadib/test_dir1/jason]
[[Files and Dirs to Backup, /home/mohadib/test_dir1]] no equals [Files and Dirs to Backup, /home/mohadib/test_dir1, /home/mohadib/test_dir1/jason, /home/mohadib/test_dir1/jason/test.class]
i dont know where the extra [] are coming from around the first path...i regexed
them out and still did not get a match. Could some one tell me what im
missing?
thanks,
jd

Thank you that was helpful. So, if i regex out the extra [] then
why is this...
[Files and Dirs to Backup, /home/mohadib/test_dir1] no equals [Files and Dirs to Backup, /home/mohadib/test_dir1]
here is the code i used...
String path_reg = new String(tree.getSelectionPath().toString());
          System.out.println(path_reg + "before");
          String clean_reg_string2 = new String(path_reg.replaceAll("^\\[", ""));
          String clean_reg_string1 = new String(clean_reg_string2.replaceAll("\\]$", ""));
          TreePath test_path = new TreePath(clean_reg_string1);
          System.out.println(test_path.toString() + "jd path");
          TreeNode root = (TreeNode)tree.getModel().getRoot();
          Vector list = new Vector(0);
          getPaths(tree, new TreePath(root), list);
          int i;
          for(i=0; i<list.size(); i++){
               TreePath pop_path = (TreePath)list.elementAt(i);
               if(test_path.equals(pop_path)){
                    System.out.println(test_path.toString() + " equals " + pop_path.toString() );
               else{
                    System.out.println(test_path.toString() + " no equals " + pop_path.toString() );
          }thanks,
jd

Similar Messages

  • Error in using .equals in JSP

    i'm using .equals to compare string value but every time i refresh the page it returns an error.
    <%@include file = "connection/dbconnect.js"%>
    <select name="List_Type" style="width:150px;height:23px" class="styleFieldEntry">
    <%if(request.getParameter("Found")==null || request.getParameter("Type1")==""){%>
    <option value="" selected>All</option>
    <%}else{%>
    <option value="" selected>All</option>
    <%}%>
    <%rs = statement.executeQuery("SELECT Type1 From somain group by Type1 order by Type1 ");
    rs.next();
    while (rs.next())
    { if(request.getParameter("List_Type").equals(rs.getString("Type1"))){%>
    <option value="<%=rs.getString("Type1")%>" selected><%=rs.getString("Type1")%></option>
    <%}else{%>
    <option value="<%=rs.getString("Type1")%>"><%=rs.getString("Type1")%></option>
    <%}}%>
    </select>      Error:
    exception
    org.apache.jasper.JasperException
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    java.lang.NullPointerException
         org.apache.jsp.inventory.soFind_jsp._jspService(org.apache.jsp.inventory.soFind_jsp:143)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

    This is very hard to read
    insert standard rant about mixing ugly scriptlet code into a JSP like this.
    Recommend the use of JSTL to reduce scriptlet code.
    Also comment on how SQL should never be in a JSP, but rather be in a bean somewhere.
    Particularly if it is a static list, that doesn't depend on any parameters.
    And why call rs.getString("Type1") four seperate times? Call it once and reuse the variable.
    I can't see the reason for that first if statement, as it does the same thing on either branch of the if.
    Also, you have an extra rs.next() that you might not need.
    [ end rants]
    Oh - your null pointer exception.
    It could be coming from several places:
    Most likely is request.getParameter("List_Type").equals...
    If the parameter List_Type is not present, then it will fail.
    Also you have request.getParameter("Type1")=="")
    that should be
    if (request.getParameter("Type1")==null || request.getParameter("Type1".equals("")

  • Comparing layers for equality

    Is it possible to compare two different layers to see if they are in fact the same image?
    I'm actually working on a game at the moment. The game map was created by using game sprites created by other people. For example, I found 5 different pictures of trees, and copy pasted them into photoshop multiple times to create a forest. I have 100 trees in my photoshop document, but in reality, they are all made up of only 5 images. I want to save out each of these trees into a format usable by my game engine. I want to save each layer as an image, but avoid saving duplicates. Thus the need to compare layers for equality.
    Is it possible to do this within a photoshop script? Thanks for any help you can provide.

    but wouldn't this only work in the instance of them being on top of each other?
    That bit of code presumes:
    The layers are in the same document
    The layers are the only two layers visible
    The content of the layers is aligned.
    The layers have simple content (no layer masks, vector masks, layer styles)
    There may be other assumptions that I'm making, but this is all that I can think of.
    For the trees/forest problem, I would iterate though the tree-layers.
    Create a new document that is as large as the largest tree-layer in the forest.
    Hide the background layer.
    Copy the first layer to the new document.
    Copy the second layer to the new doc
    Do the layer comparison code from above my previous post
    If the layers are the same, delete the new one.
    Go to the next layer in the forest document.
    Copy and compare the new layer against each layer in the new document.
    Delete it if it's a dupe.
    When you're done, the new document should have only the unique trees.

  • Compare Strings using JSTL

    How can I compare strings with JSTL? One string is a stored date and the other is a generated date. My goal is to set the correct date in a dropdown menu with date values (yyyy-MM-dd) by comparing the current date with the stored.
    Code
    <%
    Calendar cal = Calendar.getInstance(timezone, locale);
    Format fm = new SimpleDateFormat("yyyy-MM-dd");
    String date2 = (String) fm.format(cal.getTime()); %>
    <c:set var="date1" value="${mb.date}" />   // from database lookup (MySQL Date)
    <p><c:out value="${date1}"/>=<%=date2%>:<c:out value="${date1 == '<%=date2%>' }" /></p>The result is:
    2004-08-03 = 2004-08-03 : false

    well, about this:
    <%
    Calendar cal = Calendar.getInstance(timezone, locale);
    Format fm = new SimpleDateFormat("yyyy-MM-dd");
    String date2 = (String) fm.format(cal.getTime());
    pageContext.setAttribute("date2",date2);
    %>
    <c:set var="date1" value="${mb.date}" />   // from database lookup (MySQL Date)
    <p><c:out value="${date1}"/> .equals <%=date2%>:<c:out value="${date1eq date2}" /></p>I try to use the EL 'eq' like you would use '.equals()' in regular java, and EL '==' like regular java '==' And since we are comparing Strings here, which are objects, we would use .equals rather than ==, since == compares refernce and .equals compares value...

  • How to compare dates using javascript?

    Hi,
    I have to compare dates using javascript. The dates are in format "mm/dd/yy" for eg "10/09/06".
    I have written a script to compare the dates but the problem I 'm facing is with the year.
    For example if I compare "10/09/06" with "10/04/98", then "10/04/98" is coming out to be greater than "10/09/06" because it is considering year "98" to be greater than "06".
    Please advice/suggest.
    Thanks in advance...

    Dude, you're here in a Java forum, not in a Javascript forum. Those are two entirely different languages.
    The answer in Java is to use java.text.SimpleDateFormat to convert String to Date and use java.util.Date and/or java.util.Calendar to compare dates.

  • Can we use equals method in JSTL

    hia all,
    is there is possible to use equals method in JSTL c:when tag. if so please give me an example or else please tell me some solution.
    regards
    subramanian

    Have you tried it anyway? Where exactly are you talking about with "contents"?
    Remember that the == operator in JSTL isn't the same as the == operator in Java. In JSTL it invokes the Object#equals() method behind the scenes, while in Java it checks the equality of the reference.

  • Comparing objects for equality with UDT's

    Hi.
    I was wondering how Oracle does comparison for equality of objects that contains parameters of user defined types.
    Suppose I have an object with a parameters whose types are:
    1) number,
    2) varchar2,
    3) nested table type,
    4) associative array
    and I want to compare two such objects for equality. Would Oracle compare all parameters of this 2 compared objects field-by-field (and dig recursive to "leafs"), or would it compare only 1), 2) and doas nothing with 3) and 4)?
    Must I declare an order method for such comparison?

    You didn't specify a version - this is correct for 10.2, I'm not sure if it has changed in 11g.
    By default it will compare for exact equality - i.e that every attribute is the same. You can also only do it in SQL, not PL/SQL. Also can only do = and <> - you cannot do < or > etc.
    You need to create a MAP or ORDER method on the type to do any more sophisticated comparison (Same as in most object oriented languages). Documentation is here http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14260/adobjbas.htm#sthref211

  • Trying to compare string array using equals not working

    Hi,
    im prolly being really dumb here, but i am trying to compare 2 string arrays using the following code:
    if(array.equals(copymearray))
    System.out.println("they match");
    else
    {System.out.println("dont match");}
    the trouble is that even though they do match i keep getting dont match, can anyone tell me why?

    try
    if (Arrays.equals(array, copymearray))
    System.out.println("they match");
    else
    {System.out.println("dont match");}

  • Using equals() to compare strings

    It was told in a previous post that when comparing two strings to use the equals()
    So rather than doing something like this
    package relationships;
    public class Starter {
         public static void main(String[] args){
              String foo = "foo";
              String bar = "bar";
              if(foo == bar){
                   System.out.println("Strings are logically equal");
              } else if(foo != bar){
                   System.out.println("Strings are not logically equal");
    }Where the console would output "Strings are not logically equal" How would I do this using the equals() (other then using else)
    package relationships;
    public class Starter {
         public static void main(String[] args){
              String foo = "foo";
              String bar = "bar";
              if(foo.equals(bar)){
                   System.out.println("Strings are logically equal");
              } else if( /* WHAT GOES HERE? */ ){
                   System.out.println("Strings are not logically equal");
    }I know to test if they are equal just to go like this foo.equals(bar) but what would I put in the else if?
    else if( /* WHAT GOES HERE? */ )

    Where the console would output "Strings are not
    logically equal" How would I do this using the
    equals() (other then using else)You don;t need anything else. If it is not true it is false there isn't a third boolean value of maybe or perhaps.

  • Comparing dates for equality using API

    Hello,
    I was wondering if you could help me understand if it is possible for me to compare two dates for equality.
    I am looking to only compare the date and the month. So, if I am checking "today" with another objects Date for equality, it obviously fails because the compareTo and the equals method of both Date and Calendar, I think, are comparing even the timestamps.
    here is something I wrote for testing, which obviously is of no use
    Calendar today = Calendar.getInstance();
    Calendar later = Calendar.getInstance();
    later.set(Calendar.HOUR, 03);
    System.out.println(today.getTime());
    System.out.println(later.getTime());
    if(today.equals(later)){
       System.out.println("BIG BANG");
    if(today.compareTo(later)<0)
       System.out.println("Today Date is Lesser than my Date");
    else if(today.compareTo(later)>0)
       System.out.println("Today Date is Greater than my date");
    else
       System.out.println("Both Dates are equal");   
    Date today = new Date();
    Date myDate = new Date();
    myDate.setHours(23);
    System.out.println(today);
    System.out.println(myDate);
    if(today.compareTo(myDate)<0)
       System.out.println("Today Date is Lesser than my Date");
    else if(today.compareTo(myDate)>0)
       System.out.println("Today Date is Greater than my date");
    else
       System.out.println("Both Dates are equal");   
       So is then the only way left, is using the simple date formatter and going about things ?

    package forums;
    import java.util.Calendar;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    public class CalendarExample
      private static final DateFormat DF = new SimpleDateFormat("yyyy-MM-dd");
      public static void main(String[] args) {
        Calendar today = Calendar.getInstance();
        Calendar later = Calendar.getInstance();
        later.set(Calendar.HOUR, 3);
        System.out.println("today="+DF.format(today.getTime()));
        System.out.println("later="+DF.format(later.getTime()));
        System.out.println("isSameDayAndMonth(today, later) = "+isSameDayAndMonth(today, later));
        System.out.println("\n");
        Calendar tomorrow = Calendar.getInstance();
        tomorrow.set(Calendar.DATE, tomorrow.get(Calendar.DATE)+1);
        System.out.println("today="+DF.format(today.getTime()));
        System.out.println("tomorrow="+DF.format(tomorrow.getTime()));
        System.out.println("isSameDayAndMonth(today, tomorrow) = "+isSameDayAndMonth(today, tomorrow));
        System.out.println("\n");
      public static boolean isSameDayAndMonth(Calendar a, Calendar b) {
        return a.get(Calendar.DATE) == b.get(Calendar.DATE)
            && a.get(Calendar.MONTH) == b.get(Calendar.MONTH)
    }You're welcome... Javas standard date libraries leave a lot be desired. I recommend you try Joda, which is [a long standing JSR, which has never gotten up|http://www.theserverside.com/news/thread.tss?thread_id=44248].

  • Comparing dynamic fields of objects using equals and hashCode methods

    To compare the different objects of the same class with their contents like jobTitleId, classificationId, deptId & classificationId was to be done and do some manipulations later using Set and Map. I was able to do that by simply overriding the equals and hashCode methods of Object class and was able to fetch the information (like in the following Map).
        Map<LocationData, List<LocationData>>
    The following is the class I used (its been shown to you so that it can be referred for my problem statement):
    LocationData class
        package com.astreait.bulkloader;
        public class LocationData {    
            String locId, deptId, jobTitleId, classificationId;
            @Override  
            public boolean equals(Object obj) {        
                LocationData ld = (LocationData)obj;       
                return this.deptId.equals(ld.deptId) && this.jobTitleId.equals(ld.jobTitleId) && this.classificationId.equals(ld.classificationId) &&
        this.locId.equals(ld.locId);   
            @Override  
            public int hashCode() {        
                return deptId.hashCode() + jobTitleId.hashCode() + classificationId.hashCode() +locId.hashCode();  
    Problem:
    I'm already known to which all fields of this object I need to make the comparison.
    i.e I'm bound to use the variables named classificationId, deptId, jobTitleId & locId etc.
    Need:
    I need to customize this logic such that the fields Names (classificationId, deptId, jobTitleId & locId etc) can be pulled dynamically along with their values. So, as far as my understanding I made use of 2 classes (TableClass and ColWithData) such that the List of ColWithData is there in TableClass object.
    I'm thinking what if I override the same two methods `equals() & hashCode();`
    such that the same can be achieved.
        TableClass class #1
        class TableClass{
            List<ColWithData> cwdList;
            @Override
            public boolean equals(Object obj) {
                boolean returnVal = false;
                        // I need to have the logic to be defined such that
                        // all of the dynamic fields can be compared
                return returnVal;
            @Override
            public int hashCode() {
                int returnVal = 0;
                        // I need to have the logic to be defined such that
                        // all of the dynamic fields can be found for their individual hashCodes
                return returnVal;
    ColWithData class #2
        class ColWithData{
            String col; // here the jobTitleId, classificationId, deptId, locId or any other more fields info can come.
            String data; // The corresponding data or value for each jobTitleId, classificationId, deptId, locId or any other more fields.
    Please let me know if I'm proceeding in the right direction or I should make some any other approach. If it is ok to use the current approach then what should be performed in the equals and hashCode methods?
    Finally I need to make the map as: (Its not the concern how I will make, but can be considered as my desired result from this logic)
        Map<TableClass, List<TableClass>> finalMap;

    Hello,
    What is the relation with the Oracle Forms tool ?
    Francois

  • Comparing picture using matix

    Dear all,
    I am new to LabView and I want to know whether it is able to compare pictures.
    The Program should work like this:
    I open a picture (eg. "A.bmp") and compare it with another picture ( "B.bmp"), using their matrix (similar to IMREAD in Matlab).
    If both matix are alike, then a pop up or a screen will show "A.bmp" is equivalent to "B.bmp".
    If not, it will continue to compare with another picture.
    I was wondering how can I convert the picture to matrix using Labview.
    Could someone pls enlighten me on this. Thank you in advance.
    Regards,
    Tay

    Hi Tay,
    First the program determines the number of pixels in each image and halts if they are not the same (this is the outer most case statement).  If they are the same, then it proceed to subtract one image from the other on a pixel by pixel basis, leaving you with an array containing the difference (equal in size to the image).  Then the program compares each element in the difference array to 0, this produces an array of booleans (true if the element is zero, false if the element is not zero).  If any element in the array is false, the images must not be identical.  I converted the booleans to a 0 or a 1 and sum up the array, if the array sum is zero the images must be identical.
    Read the online help on the .bmp read VI.  You will see that the cluster contains several pieces of information on the image.  (Also, the way the color information is encoded in the data is interesting)  I extracted the element called "Image", which is the image data.  You can get at the size of the image too from the cluster information.  Left click on the unbundle by name where is says image, and you can choose any piece of information.
    Using the evaluation copy you have of 8.0, use Save as to save as version 7.1, I think you can do that but I have not tried it.
    Let me know if I can be of more help,
    Chris
    Chris Reyerson
    Optical Systems Engineer
    Arete Associates
    Tucson, AZ

  • Dos command to compare files using adobe acrobat pro 9.

    Hi,
    I am using Adobe Acrobat Pro 9, through its utility i am comparing two pdfs using its GUI. Now i want to compare two pdfs through Dos prompt using Adobe Acrobat Pro 9. Is there any Dos command to compare two pdfs using Adobe Acrobat Pro 9.
    Regards 

    I don't think so.

  • How to submit a batch compare job using a unix script and cron?

    I understand I can setup a unix script to be used to schedule a database compare job. I'm not sure how to get past the popup log in window tho... When I use the command line and include the -id<myid> the OMS login window pops up requesting login password and service. This won't do if I do not want to run this interactive. I cannot find any syntax for the command line other than --id<adminid>  How to I include the password and service?
    Thanks ;)
    Laurie

    I had the same problem.
    My shell looks like (baseline_ELITE.sh):
    ocm login -idsysman
    ocm capture -l BL_ELITE -idsysman
    I don't have the ocm logout.
    First, run the baseline_ELITE.sh, it will ask you about the password. The next times, it never ask again for the password, but take in account don't use the ocm logout.
    Humberto Gomez
    OCP Dev2k, 8i, 9i
    [email protected]

  • Is it safe to use equals on BC entities?

    Hello,
    I have an entity with two accessors to another entity. I need to check whether both accessors "point" to the same entity. Is it safe to use:
      // in employee entity
      if (getDept1().equals(getDept2()) {
      }Will accessors always point to the same entity instance when the corresponding db table row's foreign keys pair point to the same row in master table?
    Rado

    Apple encourages you to disable java (not javascript) on OS X Leopard because it's currently causing problems with websites which exploit that bug the outdated java versions have, to control your computer, that is a trojan.
    It isn't an updated java version for 10.5. I have got the same problem so I am thinking in buying a 10.6 OS X version which currently has an updated security 'patch' for java.

Maybe you are looking for

  • BI-Purchasing reports help

    Hello, I am tasked on implementing standard BI reports for Purchasing in SAP.  Can anyone in the forum provide me details of any standard BI report that are relevant to Purchasing? Any links, documents and guides that will help me on implementing thi

  • How can I add a condition to the MIN function?

    is there a MIN "conditional" function, something like a MIN.IF (just like AVERAGE.IF), to find the minimum value meeting a certain condition? Or, what should I do to obtain the same result? Thank you!

  • Customisation of SAP Program

    I am trying to customise standard SAP program SAPM07DR. While I can copy it to a Z* Program,  I am unable to create a Transaction code because the screens do not exist in the copied program. How can I create the Transction code OR how can I copy the

  • After Effects opens in trial mode?

    bought after effects monthly, but when i start up ae, it still tells me my trial has expired, even if im logged in. help??

  • Previews of files are wrong when I try to open them

    My Mac (Grey/Blue Power PC G4) is 10.3.9 using Photoshop CS version 8. The problem is when I try to open files from a card reader. When I try to go to File Open then select on a preview icon, the preview image is totally different from the actual fil