GregorianCalendar method add(int,int) in websphere5.1

This bug report landed in my lap. The program is registering payments, and when user is registering multiple payments he gets the duedate set to 1970 from the second payment and on. Someone wrote on the bug report "method add(int,int) in GregorianCalendar doesn't work in WebSphere 5.1".
So, when t>0 in the following code, things go haywire. Anyone have experience with this?
dueDateG.clear();
dueDateG.setLenient(false);
dueDateG.setTime(dueDate);
if (t==0)   addMonth = 0;
else        addMonth = freq;
dueDateG.add(Calendar.MONTH, addMonth);
date = dueDateG.getTime();
dueDate = date;

By "Websphere 5.1" are you meaning Websphere Application Server 5.1 or Websphere Application Developer 5.1?
The former (as known as WAS) uses IBM JDK 1.4.X (I believe that's 1.4.1); the later (as known as WSAD) can be used with any version of WAS starting from 4.X I believe.
Some things can have problems when you're using IBM JDK's instead of Sun's, for instance trying to use the javax.crypto.* classes, that are different from Sun's; but I don't know if GregorianCalendar has problems. The first thing to do is insulate the code that you sent and try running it in IBM's and Sun's JDK. If you get problems only with IBM's JDK, you'll need to rewrite your code.

Similar Messages

  • Cannot find symbl method update Date(int,java.util.Date)

    I get following error
    cannot find symbl method update Date(int,java.util.Date) on compling class called GuestDataBean at line ( rowSet.updateDate( 4, guest.getDate() ); ).
    GustBean.java. I need help on why I get it.
    // JavaBean to store data for a guest in the guest book.
    package com.deitel.jhtp6.jsp.beans;
    import java.util.*;
    public class GuestBean
       private String firstName;
       private String lastName;
       private String email;
       private Date date;
       private String message;
       //Constructors
       public GuestBean(){
            public GuestBean(String firstname, String lastname, String email,Date date,String message){
                 this.firstName=firstname;
                 this.lastName=lastName;
                 this.email=email;
                 this.date=date;
                 this.message=message;
       // set the guest's first name
       public void setFirstName( String name )
          firstName = name; 
       } // end method setFirstName
       // get the guest's first name
       public String getFirstName()
          return firstName; 
       } // end method getFirstName
       // set the guest's last name
       public void setLastName( String name )
          lastName = name; 
       } // end method setLastName
       // get the guest's last name
       public String getLastName()
          return lastName; 
       } // end method getLastName
       // set the guest's email address
       public void setEmail( String address )
          email = address;
       } // end method setEmail
       // get the guest's email address
       public String getEmail()
          return email; 
       } // end method getEmail
       public void setMessage( String mess)
          message = mess;
       } // end method setEmail
       // get the guest's email address
       public String getMessage()
          return message; 
       } // end method getEmail
       public void setDate( Date dat )
          date = dat;
       } // end method setEmail
       // get the guest's email address
       public Date getDate()
          return date; 
       } // end method getEmail
    } // end class GuestBean
    GuestDataBean.java/**
    * @(#)GuestDataBean.java
    * @author
    * @version 1.00 2008/7/18
    // Class GuestDataBean makes a database connection and supports
    // inserting and retrieving data from the database.
    package com.deitel.jhtp6.jsp.beans;
    import java.sql.SQLException;
    import javax.sql.rowset.CachedRowSet;
    import java.util.ArrayList;
    import com.sun.rowset.CachedRowSetImpl; // CachedRowSet implementation
    import java.sql.*;
    public class GuestDataBean
       private CachedRowSet rowSet;
       // construct TitlesBean object
       public GuestDataBean() throws Exception
          // load the MySQL driver
          Class.forName( "org.gjt.mm.mysql.Driver" );
          // specify properties of CachedRowSet
          rowSet = new CachedRowSetImpl(); 
          rowSet.setUrl( "jdbc:mysql://localhost:3306/virsarmedia" );
          rowSet.setUsername( "root" );
          rowSet.setPassword( "" );
           // obtain list of titles
          rowSet.setCommand(
             "SELECT firstName, lastName, email,date,message FROM guest" );
          rowSet.execute();
       } // end GuestDataBean constructor
       // return an ArrayList of GuestBeans
       public ArrayList< GuestBean > getGuestList() throws SQLException
          ArrayList< GuestBean > guestList = new ArrayList< GuestBean >();
          rowSet.beforeFirst(); // move cursor before the first row
          // get row data
          while ( rowSet.next() )
             GuestBean guest = new GuestBean();
             guest.setFirstName( rowSet.getString( 1 ) );
             guest.setLastName( rowSet.getString( 2 ) );
             guest.setEmail( rowSet.getString( 3 ) );
             guest.setDate( rowSet.getDate( 4 ) );
             guest.setMessage( rowSet.getString( 5 ) );
             guestList.add( guest );
          } // end while
          return guestList;
       } // end method getGuestList
       // insert a guest in guestbook database
       public void addGuest( GuestBean guest ) throws SQLException
          rowSet.moveToInsertRow(); // move cursor to the insert row
          // update the three columns of the insert row
          rowSet.updateString( 1, guest.getFirstName() );
          rowSet.updateString( 2, guest.getLastName() );
          rowSet.updateString( 3, guest.getEmail() );
          rowSet.updateDate( 4, guest.getDate() );
          rowSet.updateString( 5, guest.getMessage() );
          rowSet.insertRow(); // insert row to rowSet
          rowSet.moveToCurrentRow(); // move cursor to the current row
          rowSet.commit(); // propagate changes to database
       } // end method addGuest
    } // end class GuestDataBean

    This isn't a JSP question, it better belongs in the JavaProgramming, or JDBC forums.
    But the problem is because the updateDate method uses a java.sql.Date object and you are giving it a java.util.Date object. You have to convert from java.util.Date to java.sql.Date. See: [the api for java.sql.Date|http://java.sun.com/javase/6/docs/api/java/sql/Date.html] .
    Edited by: stevejluke on Jul 21, 2008 5:43 PM

  • Operator + cannot be applied to operands of type 'method group and 'int'

    Hello I have a problem that I'm trying to fire a bullet everytime I pressed the spacebar key, but I have this problem that is cropping up.
     if ((e.KeyCode == Keys.Space) && (playerOne.Bullet.Alive == false))
                                playerOne.Bullet.Alive = true;
                                playerOne.Bullet.getX = playerOne.getXposition + 15;
                                playerOne.Bullet.getY = playerOne.getYposition + 10;
    It says in the error list: "Opeartor '+' cannot be applied to operands of type 'method group' and 'int'", I have no clue. I'm also new to programming.

    I want to get the bullet to shoot where the player is, here is the code:
    class Player
            // attributes here  -   Int other words data types and variables:
            int health = 3;
            float xPosition;
            float yPosition;
            Bitmap playerGraphics;
            int score = 0;
            bool leftPressed;
            bool rightPressed;
            float Width = 50;
            public Bullet Bullet = new Bullet();
            // functions here:
            public void Init()
                // Get Player_Bat.png from resources, so that we can work with it:
                playerGraphics = new Bitmap(Green_Aliens.Properties.Resources.Player_Bat);
                health = 3;
                score = 0;
                xPosition = 375;
                yPosition = 540;
                leftPressed = false;
                rightPressed = false;
                Bullet Bullet = new Bullet();
            public float getWidth()
                return Width;
            public void toggleLeftPressed()
                if (leftPressed == true)
                    leftPressed = false;
                else
                    leftPressed = true;
            public void toggleRightPressed()
                if (rightPressed == true)
                    rightPressed = false;
                else
                    rightPressed = true;
            public bool getLeftPressed()
                return leftPressed;
            public bool getRightpressed()
                return rightPressed;
            public Bitmap getGraphics()
                return playerGraphics;
            public float getXposition()
                return xPosition;
            public float getYposition()
                return yPosition;
            public int getHealth()
                return health;
            public int getScore()
                return score;
            public void moveLeft()
                xPosition -= 10;
            public void moveRight()
                xPosition += 10;
            public void loseLife()
                health--;
            public void adScore(int valueAdd)
                score += valueAdd;
            //Resets the player to the start position:
            public void resetPosition()
                xPosition = 400;
                yPosition = 550;

  • Why JTextArea.select(int,int) not Highlight in java 1.4

    Hi guys
    Does anybody know why JTextArea.select(int, int) not Highlight the selected text in java 1.4. But java 1.3 works. Does java 1.4 change to use other method to hightlight the selected text in JTextArea? Thanks in advance.
    Regards,
    Mark.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SelTest extends JPanel {
      private JTextArea area;
      public SelTest() {
        setLayout( new BorderLayout() );
        area = new JTextArea( "This is a sample text", 20, 20 );
        JButton btn = new JButton( "Select" );
        btn.addActionListener( new ActionListener(){
          public void actionPerformed( ActionEvent ae ){
            selectText2();
        add( area, BorderLayout.CENTER );
        add( btn, BorderLayout.SOUTH );
      private void selectText2(){
        area.requestFocus(); // MOST IMPORTANT
        area.select( 1, 4 );
        System.out.println("selcted : " + area.getSelectedText() );
      public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        f.getContentPane().add( new SelTest() );
        f.pack();
        f.setVisible( true );
    }

  • SetSize(int,int) not working in JTextPane.. Please help

    Hi,
    I want to set size of JTextPane so that by default it should show atleast 2 lines.
    I am using setSize(int, int) , but its not working.
    Can anybody help me?

    hi
    From onwards, I will take care of it.. I will put my query in particular category only.
    Actually I tried this one also...
    Following is my method in which I want to set size of JtextPane
    public JPanel initComponents(Vector columnNames, Vector dbNames, Vector data) {
    fieldrefs = new JTextComponent[columnNames.size()];
    JPanel content = new JPanel();
    content.setLayout(new GridBagLayout());
    content.setSize(900,900);
    // Create Menubar
    JMenuBar menuBar = createMenuBar();
    setJMenuBar(menuBar);
    GridBagConstraints gbc = new GridBagConstraints();
    //some code
    gbc.gridx = 2;
    gbc.gridy = 0;
    gbc.insets = new Insets(SG_SwingUtilities.BORDER_COMP, // (top, left, bottom, right)
    SG_SwingUtilities.BORDER_COMP, 0, 0);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    JLabel pathLabel = new JLabel(stringPath);
    Font font = new Font(null, Font.BOLD, 12);
    pathLabel.setFont(font);
    content.add(pathLabel, gbc);
    // Insert all the fields.
    for (int i = 0, j = 0; i < columnNames.size(); i++, j += 2) {
    int gridy = i + 1;
    String label = (String) columnNames.elementAt(i); // Name of column.
    gbc = new GridBagConstraints();
    gbc.gridy = gridy;
    gbc.insets = new Insets(SG_SwingUtilities.BORDER_COMP, SG_SwingUtilities.BORDER_COMP, 0, 0);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    content.add(new JLabel(label), gbc);
    if ((i == 4 || i == 5) || (i == 2 && (isMacroNode || isSystemNode))) {
    // tagstart and tagend are expanded in HORIZONTAL direction.
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    if(i==5)
         styledDocEnd = new DefaultStyledDocument();
    fieldrefs[i] = new JTextPane(styledDocEnd);
    }else
    styledDocStart = new DefaultStyledDocument();
    fieldrefs[i] = new JTextPane(styledDocStart);
    if (i == 5) {
         textarea2 = new JTextPane(styledDocEnd); // I want to set this JtextPane size      
    textarea2 = (JTextPane)fieldrefs;
         fieldrefs[i].setSize(100,500);
    tagEndField = new JPanel(new GridBagLayout());
    content.add(tagEndField, gbc);
    normalComponent2 = new JScrollPane(fieldrefs[i]);
    setNormalMode(2);
    // my code
    else {
    // TagStart      
         textarea1 = new JTextPane(styledDocStart); // I want to set this JtextPane size
         textarea1 = (JTextPane)fieldrefs[i];//me
         fieldrefs[i].setSize(100,500);
    tagStartField = new JPanel(new GridBagLayout());
    content.add(tagStartField, gbc);
    normalComponent1 = new JScrollPane(fieldrefs[i]);
    setNormalMode(1);
    /// my code
    fieldrefs[i].addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent me) {
    // DOUBLE (left) CLICK
    if (data != null && !data.isEmpty()) {
    if (data.elementAt(j) != null) {
    String insertData = data.elementAt(j) + "";
    insertData = insertData.replaceAll("\\&\\{\\}", ""); // remove dummy ref
    insertData = insertData.replaceAll("\r", "");
    fieldrefs[i].setText(insertData);
    if(i==4 || i==2)
    insertLineBreaks(textarea1);
    updateColors(textarea1.getText(),true); //me
    if(i==5)
    insertLineBreaks(textarea2);
         updateColors(textarea2.getText(),false); //me
    else if (i == 5) {
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    fieldrefs[i] = new JTextArea(3, 10);
    fieldrefs[i].setForeground(new Color(0, 0, 255));
    // ((JTextArea) fieldrefs[i]).setLineWrap(true);
    if (data != null && !data.isEmpty()) {
    if (data.elementAt(j) != null) {
    String insertData = data.elementAt(j) + "";
    insertData = insertData.replaceAll("\\&\\{\\}", ""); // remove dummy ref
    fieldrefs[i].setText(insertData);
    content.add(new JScrollPane(fieldrefs[i]), gbc);
    else {
    fieldrefs[i] = new JTextArea(2, 10); // description field.
    ((JTextArea) fieldrefs[i]).setLineWrap(true);
    if (data != null && !data.isEmpty()) {
    if (data.elementAt(j) != null) {
    fieldrefs[i].setText(data.elementAt(j) + "");
    content.add(new JScrollPane(fieldrefs[i]), gbc);
    //code
    return content;
    } // initComponents
    protected JTextComponent[] fieldrefs = null; is taken from super class
    Message was edited by:
    ring

  • SocketInputStream.read(byte[], int, int) extremely slow

    Hi everyone,
    I'm trying to send several commands to a server and for each command read one or more lines as response. To do that I'm using a good old Socket connection. I'm reading the response lines with BufferedReader.readLine, but it's very slow. VisualVM says, that SocketInputStream.read(byte[], int, int) is consuming most of the cpu time. A perl script, which does the same job, finishes in no time. So it's not a problem with the server.
    I'm runnning java version "1.6.0_12"
    Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
    Java HotSpot(TM) Server VM (build 11.2-b01, mixed mode) on Linux henni 2.6.25-gentoo-r7 #3 SMP PREEMPT Sat Jul 26 19:35:54 CEST 2008 i686 Intel(R) Core(TM)2 Duo CPU E6550 @ 2.33GHz GenuineIntel GNU/Linux and here's my code
    private List<Response> readResponse() throws IOException {
            List<Response> responses = new ArrayList<Response>();
            String line = "";
            while ( (line = in.readLine()) != null) {
                int code = -1;
                try {
                    code = Integer.parseInt(line.substring(0, 3));
                    line = line.substring(4);
                } catch (Exception e) {
                    code = -1;
                // TODO create different response objects ?!?
                NotImplemented res = new NotImplemented(code, line);
                responses.add(res);
                // we received an "end of response" line and can stop reading from the socket
                if(code >= 200 && code < 300) {
                    break;
            return responses;
        }Any hints are appreciated.
    Best regards,
    Henrik

    Though it's almost an sscce I posted there, I will try to shrink it a little bit:
    Dummy server:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    public class Server {
        public Server() throws IOException {
            ServerSocket ss = new ServerSocket(2011);
            Socket sock = ss.accept();
            BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
            PrintStream ps = new PrintStream(sock.getOutputStream());
            ps.println("200 Welcome on the dummy server");
            String line = "";
            while(line != null) {
                line = br.readLine();
                ps.println("200 Ready.");
        public static void main(String[] args) throws IOException {
            new Server();
    }the client:
    import java.io.IOException;
    import java.io.PrintStream;
    import java.net.InetSocketAddress;
    import java.net.Socket;
    import java.net.UnknownHostException;
    import java.util.Scanner;
    import de.berlios.vch.Config;
    public class Client {
        private Socket socket;
        private PrintStream out;
        private Scanner scanner;
        public Client(String host, int port, int timeout, String encoding)
            throws UnknownHostException, IOException {
            socket = new Socket();
            InetSocketAddress sa = new InetSocketAddress(host, port);
            socket.connect(sa, timeout);
            out = new PrintStream(socket.getOutputStream(), true, encoding);
            scanner = new Scanner(socket.getInputStream(), encoding);
        public synchronized void send(String cmd) throws IOException {
            // send command to server
            out.println(cmd);
            // read response lines
            readResponse();
        public void readResponse() throws IOException {
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                System.out.println(line);
                int code = -1;
                try {
                    code = Integer.parseInt(line.substring(0, 3));
                    line = line.substring(4);
                } catch (Exception e) {
                    code = -1;
                if (code >= 200 && code < 300) {
                    break;
        public static void main(String[] args) {
            try {
                Client con = new Client("localhost", 2011, 500, "utf-8");
                con.readResponse();
                con.send("version 0.1");
                con.send("menu = new menu Feeds");
                con.send("menu.EnableEvent close");
                con.send("menu.SetColorKeyText -red 'Öffnen'");
                for (int i = 0; i < 100; i++) {
                    String groupId = "group"+i;
                    long start = System.currentTimeMillis();
                    con.send(groupId+" = menu.AddNew OsdItem '"+groupId+"'");
                    con.send(groupId+".EnableEvent keyOk keyRed");
                    long stop = System.currentTimeMillis();
                    System.out.println((stop-start)+"ms");
            } catch (Exception e) {
                e.printStackTrace();
    }This code makes me believe, it's not a java problem, but some system setting of my os.

  • JFrame.setSize(int, int) - how set window dimensions?

    Hello,
    In my simpliest swing apps I can't set window dimensions by setSize(int, int). What am I doing wrong?
    //v 1.3
    import javax.swing.*;   
    public class HelloWorldSwing {
        public static void main(String[] args) {
            JFrame frame = new JFrame("HelloWorldSwing");
            final JLabel label = new JLabel("Hello World");
            frame.getContentPane().add(label);
         frame.setSize(200, 200); //won't change anything??
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
    }

    .pack() is resizing the frame. Move setSize() after it.

  • CreateStatement(int, int) performance

    Hi, I have some performance problems with the method createStatement(int, int) when using it on large tables (containing about 2,000,000 records). Does anyone already had the same prob?
    I use the createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)
    The DB used is DB2/400 on IBM iSeries.
    How is that method implemented? Does it fetch all elements??? Does it creates temp indexes??? I'm forced to use that method to be able to use a ResultSet.absolute(int) after...
    I've read somewhere that depending on the JDBC driver, we better use a count(*) in the sql query than a ResultSet.last() then ResultSet.getRow() because the last() will fetch all records. Maybe is it the same problem?
    Or maybe does anyone know if there's an equivalent of the absolute(int) in sql?
    Could anyone help me to find a solution for better performances?

    Indeed my question was not very clear sorry.
    Here's the context :
    In a web app, a user wants to make a search on client members, let's say the table has about 2,000,000 records of data.
    I have to display a page navigation system, let's say the user can display 50 records by page. He must be able to navigate through page 1 to the last page back and forward and with a step of 2 or more, and he can always reach the first and last page in a single click.
    That's why I used a scrollable ResultSet so I could use the rs.absolute(i) to position the cursor on the page I want to display, instead of doing rs.next() until I reach the correct position.
    That system works fine as long as there's not too much records. But unfortunately, some search without any criteria can give the total table, and I'm not in position to say there must be restriction on the search. The client is king.
    So I just wondered if there's a solution with good performance to doing so?
    My english is not very fluent so I hope it's understable ^^

  • Units of parameters width and height  passed in drawRect(int,int,int,int)

    Units of parameters width and height passed in drawRect(int,int,int,int)

    Units of parameters width and height passed in drawRect(int,int,int,int)They are just units in the User Space. Since you can change the
    scale of the AffineTransform associated with your graphics object,
    you can't be more specific than that.
    Initially the claim is that the units are 96 per inch, but that isn't true.
    For example, change the resolution of your screen and run the code
    again!

  • Hilfe Method Add

    hallo Leute,
    ich habe ein Problem ich versuche meine texteDatei mit diesem code Segment zu lesen:
    dim Proname, Provalue
    File.Formatter.Linefeeds = vbNewline
    File.Formatter.Delimiters = ":"
    While (File.position<>File.Size)
    ProName = File.GetNextStringValue(eString) 
    ProValue = File.GetNextStringValue(eString)
    Call Root.Properties.Add(ProName, ProValue) 
    Call File.Skipline
    Wend
    aber ich bekomme immer diese Fehlermeldung :" der Text ist kein gültig Wert für das Argument Name der Methode Add" 
    wie kann ich dies Fehler beheben?
    Grüss 

    Hallo Titi1680,
    das Problem liegt wohl darin, dass die Add-Funktion auf eine Variable, die nicht im Gültigkeitsbereich liegt, zugreift. Ich habe Deinen Code angepasst, aber nicht getestet. Bitte lass mich wissen, ob es klappt.
    dim Proname, Provalue
    File.Formatter.Linefeeds = vbNewline
    File.Formatter.Delimiters = ":"
    Proname = File.GetNextStringValue(eString)
    Provalue = File.GetNExtStringValue(eString)
    while (Not IsNull(Proname) And Not IsEmpty(Provalue))
      Call Root.Properties.Add(ProName, ProValue)
      Call File.Skipline
      Proname = File.GetNextStringValue(eString)
      Provalue = File.GetNExtStringValue(eString)
    Wend
    Grüße
    Regards
    MY

  • Differing charts of accounts: INT - INT

    Hi
      While assigning company code to credit control area the following error is coming
    " Differing charts of accounts: INT - INT "
    How to solve this.
    Thanks
    Anto

    Hi Joseph,
    One would think that this will be something done by your functional folks.
    This area falls under their part.
    If they are talking about a total client copy from 000, then that may be something wiith which you can help them.
    Hope that helps.
    Abhi

  • Puzzel- Method to optimize int[ ][ ]of int[ ][ ]'s

    I'm righting a class that takes an int[][], initially filled with 0 or null. A rectangular block is added to the int[][] with a value of 1 - 9. Another rectangular block is added to the int[][] with a different value from the first, usually the next int (2). The current setting is
    final static int width = 47;
    final static int height = 3800;
    public int[][] grid = new int[47][3800];
    I have a method addBlock(int blockWidth, int blockHeight) which adds a block to the grid. However it doesn't properly optimize the grid to fit the most efficient number of blocks. It simply adds a block to the top left corner of the grid (where the top left is grid[0][0]) and checks to make sure the next block does not overflow the width bound of 47. If it does it simply places the block at the first available grid where the grid value = 0 and does not overflow the bounds. It doesn't check to make sure that it isn't overriding other blocks, and it doesn't move existing block to make room for new blocks.
    What I am looking for is a way to keep individual blocks together. There could come a situation where two blocks with the same value touch. In this case what would happen?
    Also how do you move blocks once they have been added to the grid?
    Finally, is there an existing algarythm for doing a best fit on a grid of grids?
    Suggestions, other places to look, code, websites to check or any valuable information would be greatly appreciated.
    If needed I could post the existing source, which stacks the grids from the upper left corner and works down. I have a viewer written already which reads in an int[][] and displays it in 9 colors, however I can easily expand the color recognition to as many colors as needed.

    Hi again,
    even if the sequential adding of block will not lead to an optimized layout of the templates on the bolt, we can improve the algorithm given by robert19791 - starting from the top left position of the bolt working towards the right bottom we can say the following:
    The top-left corner of each rectangle is on the right or bottom edge of another rectangle except for the first one added. So, when we search for a position, we will do it along these edges of all the rectangles added before. The test, if it fits in a certain position, can be done with an intersection check with all other already added rectangles, which right or bottom edges are not left or top of the tested position. Ofcourse the rectangle to add must be inside the bolt.
    This will reduce the postions to check and also give a solution for the overlapping problem Robert has mentioned. In those cases where the fit test fails, it should be tested, how large the overlapping area is - if it is not so big, it is perhaps a good idea to shift the rectangle, which would be overlapped otherwise. During such a shift operation the rule of the top-left-corner sitting on the right or bottom edge of another rectangle can be broken, instead the rule is, that an edge is in contact with another rectangle's edge.
    Ok, this for now
    greetings Marsian

  • SAX-ContentHandler -characters methods gets wrong int end sometimes

    Hi
    I am having problems with SAX-ContentHandler -characters methods. It gets wrong int end values time to time ---means that it chops up my strings when it reads large XML files.
    Is there any way to correct it? Any suggestions will be very helpful. Thank you.
    My code is below.
    public class MyContentHandlerDemo extends Thread implements ContentHandler{
    private ArrayList hitList = new ArrayList(1000);
    private ArrayList hitId = new ArrayList(1000);
    private ArrayList hspNum = new ArrayList(1000);
    private ArrayList hitLength = new ArrayList(1000);
    private ArrayList queryFrom = new ArrayList(1000);
    private ArrayList hspith = new ArrayList(1000);
    private ArrayList idith = new ArrayList(1000);
    private String localname;
    private Locator locator;
    private int know=1;
    private int knowid=1;
    private int knowlength=1;
    private int knowhitlength=1;
    private int knowhspnum=1;
    private int knowhspnumadd=1;
    private int knowhspnumlength=1;
    private int knowquery=1;
    private int knowqueryfrom=1;
    private int processon =1;
    private int processcount = 0;
    private int hspithnum=0;
    private int idithnum=0;
    String allstr;
    String addseq;
    char [] allchar;
    int icount=0;
    int lengthsum=0;
    public synchronized void setDocumentLocator(Locator locator) {
    System.out.println(" * setDocumentLocator() called");
    // We save this for later use if desired.
    this.locator = locator;
    public synchronized void startDocument() throws SAXException {
    System.out.println("Parsing begins...");
    public synchronized void endDocument() throws SAXException {
    try {
    FileOutputStream outputfileDemo;
    PrintStream printoutDemo;
    outputfileDemo= new FileOutputStream("apoe500.fasta");
    printoutDemo=new PrintStream(outputfileDemo);
    FileOutputStream reSaxfile;
    PrintStream printoutReSax;
    reSaxfile= new FileOutputStream("reSax.txt");
    printoutReSax=new PrintStream(reSaxfile);
    int m = hitList.size();
    for (int k=0; k < m; k++) {
    int comp = (((hitList.get(k)).toString()).length());
    String strComp = Integer.toString(comp);
    String hitleng = (hitLength.get(k)).toString();
    if(strComp.compareTo(hitleng)!=0)
    {System.out.println("Warning: Length is different at hit number (-1) " + hitId.get(k));}
    for (int l=0; l < hspith.size(); l++){
    printoutReSax.println((hspith.get(l)).toString());
    outputfileDemo.close();
    printoutDemo.close();
    reSaxfile.close();
    printoutReSax.close();
    } catch (IOException e) {
    System.out.println("IOException errors");
    System.out.println("...Parsing ends.");
    public synchronized void processingInstruction(String target, String data)
    throws SAXException {
    //System.out.println("PI: Target:" + target + " and Data:" + data);
    public synchronized void startPrefixMapping(String prefix, String uri) {
    //System.out.println("Mapping starts for prefix " + prefix +
    // " mapped to URI " + uri);
    public synchronized void endPrefixMapping(String prefix) {
    //System.out.println("Mapping ends for prefix " + prefix);
    public synchronized void startElement(String namespaceURI, String localName,
    String rawName, Attributes atts)
    throws SAXException {
    localname =localName;
    int which =100;
    if (localname.equals("Hit_id")) {which = 0;}
    if (localname.equals("Hsp_num")) {which = 1;}
    if (localname.equals("Hsp_hseq")) {which = 2;}
    if (localname.equals("Hsp_align-len")) {which =3;}
    if (localname.equals("Hsp_query-from")) {which =4;}
    switch (which){
    case 0: knowid=0;
    //icount=icount+1;
    break;
    case 1: knowhspnum=0;icount=icount+1;
    break;
    case 2: know=0; //icount=icount+1;
    break;
    case 3: knowlength=0; //icount=icount+1;
    break;
    case 4: knowquery=0; //icount=icount+1;
    break;
    default: knowid=1; know=1; knowlength=1; knowhspnum=1;knowhitlength=1;knowquery=1;
    public synchronized void endElement(String namespaceURI, String localName,
    String rawName)
    throws SAXException {
    //System.out.println("endElement: " + localName + "\n");
    public synchronized void characters(char[] ch, int start, int end)
    throws SAXException {
    String s = new String(ch, start, end);
    int process=100;
    if (knowid==0) {process=0;}
    if (knowhspnum==0){process=1;}
    if (know==0) {process=2;}
    if (knowlength==0) {process=3;}
    if(knowquery==0){process=4;}
    switch(process){
    case 0:
    idithnum = idithnum+1;
    //int start1 = start;
    //int end1 = end;
    //char [] datahold1 = new char[end1];
    //for (int i=0;i<end1;i++){
    //datahold1=ch[start1+i];
    //warn if the length is differernt
    int n=s.length();
    allchar = new char[n+1];
    allchar[0] = '>';
    for (int i=0; i<n; i++){
    allchar[i+1]=s.charAt(i);
    allstr = new String(allchar);
    hitId.add(allstr);
    knowid=1;
    processon=1;
    break;
    case 1:
    hspNum.add(s);
    if ((s.compareTo(Integer.toString(1)))!=0){
    String hspallstr = new String (allstr.concat(s));
    hitId.add(hspallstr);
    knowhspnum=1;
    processon=1;
    break;
    case 2:
    hitList.add(s);
    know=1;
    processon=1;
    break;
    case 3:
    hitLength.add(s);
    knowlength=1;
    processon=1;
    break;
    case 4:
    queryFrom.add(s);
    knowquery=1;
    processon=1;
    break;
    default: processon=0;
    public synchronized void ignorableWhitespace(char[] ch, int start, int end)
    throws SAXException {
    String s = new String(ch, start, end);
    public synchronized void skippedEntity(String name) throws SAXException {

    I put some more codes in characters(). Then I got OutOfMemory: Java Heap Error.
    I probably have to write something in startElement() to limit input for characters() method.
    Could anyone help me? I need to limit inputs for charactes() in startElement().
    I added some codes in characters() method
    public synchronized void characters(char[] ch, int start, int end)
            throws SAXException {
            String s;
            StringBuffer stringbuf1;
            String finalstring1;
            int process=100;
            if (knowid==0) {process=0;}
            if (knowhspnum==0){process=1;}
            if (know==0) {process=2;}
            if (knowlength==0) {process=3;}
            if(knowquery==0){process=4;}
            switch(process){
            case 0:
            //s = new String(ch, start, end);
            idithnum = idithnum+1;
            //int start1 = start;
            //int end1 = end;
            //char [] datahold1 = new char[end1];
            stringbuf1 = new StringBuffer();
            while(ch!=null){
            stringbuf1.append(ch);   
            finalstring1 = stringbuf1.toString();
            //warn if the length is differernt
            int n=finalstring1.length();
            allchar = new char[n+1];
            allchar[0] = '>';
            for (int i=0; i<n; i++){
            allchar[i+1]=finalstring1.charAt(i);
            allstr = new String(allchar);
            hitId.add(allstr);
            knowid=1;
            processon=1;
            break;
            case 1:
            //s = new String(ch, start, end);
            stringbuf1 = new StringBuffer();
            while(ch!=null){
            stringbuf1.append(ch);   
            finalstring1 = stringbuf1.toString();
            hspNum.add(finalstring1);
            if ((finalstring1.compareTo(Integer.toString(1)))!=0){
            String hspallstr = new String (allstr.concat(finalstring1));
            hitId.add(hspallstr);
            //System.out.println(allstr);
            knowhspnum=1;
            processon=1;
            break;
            case 2:
            //s = new String(ch, start, end);
            //int lengthend=end;
            stringbuf1 = new StringBuffer();
            while(ch!=null){
            stringbuf1.append(ch);   
            finalstring1 = stringbuf1.toString();
            checklength:
            while(know==0){
            if(lengthend!=new Integer((hitLength.get(hitLength.size()-1)).toString())){
            String s1=new String(ch, start, end);
            s = (((hitList.get((hitList.size())-1)).toString()).concat(s1));
            hitList.add(s);know=1;
            break;
            hitList.add(finalstring1);
            processon=1;
            break;
            case 3:
            //s = new String(ch, start, end);
            stringbuf1 = new StringBuffer();
            while(ch!=null){
            stringbuf1.append(ch);   
            finalstring1 = stringbuf1.toString();
            hitLength.add(finalstring1);
            knowlength=1;
            processon=1;
            break;
            case 4:
            //s = new String(ch, start, end);
            stringbuf1 = new StringBuffer();
            while(ch!=null){
            stringbuf1.append(ch);   
            finalstring1 = stringbuf1.toString();
            queryFrom.add(finalstring1);
            knowquery=1;
            processon=1;
            break;
            default: processon=0;

  • How do you invoke a method with native int array argument?

    Hi,
    Will someone help me to show me a few codes samples on how to invoke a method which has only one argument, an int [] array.
    For exampe:
    public void Method1(int [] intArray) {...};
    Here is some simple code fragment I used:
    Class<?> aClass = Class.forName("Test2");
    Class[] argTypes = new Class[] {int[].class};
    Method method = aClass.getDeclaredMethod("Method_1", argTypes);
    int [] intArray = new int[] {111, 222, 333};
    Object [] args = new Object[1];
    args[0] = Array.newInstance(int.class, intArray);
    method.invoke(aClass, args);I can compile without any error, but when runs, it died in the "invoke" statement with:
    Exception in thread "main" java.lang.IllegalArgumentException: object is not an instance of declaring class
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at Test1.invoke_Method_1(Test1.java:262)
         at Test1.start(Test1.java:33)
         at Test1.main(Test1.java:12)
    Any help is greatly appreciated!
    Jeff

    Sorry, my bad. I was able to invoke static methods and instance methods with all data types except native int, short, double and float, not sure the proper ways to declare them.
    After many frustrating hours, I posted the message for help, but at that time, my mind was so numb that I created a faulted example because I cut and pasted the static method invocation example to test the instance method passing int array argument.
    As your post suggested, "args[0] = intArray;", that works. Thanks!
    You know, I did tried passing the argument like that first, but because I was not declaring the type properly, I ended up messing up the actual passing as well as the instantiation step.
    I will honestly slap my hand three times.
    jml

  • Little method problem! int cannot be de-referrenced

    I have a object array of a class called rooms.
    I declared it at the beginning of the code and used it many times.
    Room[] rooms = new Room[houseRooms];
    private static void displayResults(int rooms[], int i )
              System.out.println("Room " +(i+1)+"\n width = " +rooms.getWidth()+ " length= " +rooms[i].getLength()+ ", Area = " +rooms[i].findArea() );
    As you see i am trying to input that parameter array of an object class... but its not letting me specify it self to be an integer so that i could use it. Maybe there is a way around?

    I have a object array of a class called rooms.
    I declared it at the beginning of the code and used it
    many times.
    Room[] rooms = new Room[houseRooms];
    private static void displayResults(int rooms[], int i
    System.out.println("Room " +(i+1)+"\n width = "
    +rooms.getWidth()+ " length= "
    +rooms[i].getLength()+ ", Area = "
    +rooms[i].findArea() );
    You have a field (a member variable) called rooms that is an array of Room.
    Inside displayResults you have a method variable (i.e., a local variable) call rooms taht is an array of int.
    When you refer to "rooms" which one will you be talking about?
    If you're inside displayResults (or any other method that has a local "rooms" variable, then the local one will hide the field. So in that context, rooms is an array of int, not an array of Room.
    What is that array of ints supposed to represent in the displayResults method? Did you really mean for it to be an array of Rooms? If you do need an array of ints, then you have two choices:
    1) Change the name of the method parameter, so it doesn't hide the member variable.
    2) Use "this.rooms" to refer to the member when you're inside the method.
    I recommend #1.
    Also, to the other poster, you can't extend int  because it's a primitive, and you can't extend Integer because it's final. Integer and int are not the same. However, with autoboxing/unboxing in 1.5, the switch between them can be transparent much of the time, from my understanding.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for