Nice TWiki > Dev > NiceCasts (r1.1) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Dev . { Changes | Index | Search | Go }
here are some examples where I had to use casts in my project
Daniel asked me to make this list in order to optimize the compiler.

      JOptionPane.showMessageDialog(cast(flowWindow),
         cast("Errors in flow.\nFlow byte code could not be generated.\nFlow will be saved without byte code."),
         cast("Error"),
         JOptionPane.ERROR_MESSAGE);
flowWindow extends JInternalFrame

      Rectangle rect = this.getHandlesBoundsRect();
      int width = cast(rect.getWidth());
      int height = cast(rect.getHeight());
getters return double


   java.util.List<Handle> handles = new ArrayList();
   ...
      ConnectionHandle ch;
      ch = cast(handles.get(handles.size()-1));
ConnectionHandle extends Handle


   public class ConnectionHandle extends Handle
      implements ConnectorListener
   {
      ...
   }

   java.util.List<ConnectionHandle> connectionHandles = this.getHandles().filter(asConnectionHandle);
   ConnectionHandle connectionHandle = connectionHandles.get(connectionHandleIndex);
   ?java.util.List<ConnectorListener> connectorListeners = conn.getConnectorListeners();
   if (connectorListeners != null  &&  notNull(connectorListeners).contains(cast(connectionHandle))) {...}
In the last line I check the existence of a ConnectorListener in a List of ConnectorListeners. The local instance connectionHandle implements ConnectorListener.


      ?Figure figure = getFrontFlowWindowDrawArea().getDrawing().getFigureExcept(
                  mousePos, this);
      if (figure == null)   return;
      Flowlet flowlet = cast(notNull(figure));
Flowlet extends Figure


      for (Iterator<ConnectorListener> iter = notNull(connectorListeners).iterator(); iter.hasNext();) {
         ConnectorListener ltnr = iter.next();
         
         if (figure.getHandles().contains(cast(ltnr))) {
            iter.remove();
            //println(" deleted: " + ltnr);
         }
      }


   getFromConnection(state) {
      java.util.List<Connection> followings = this.getFromConnections();
      
      for (int i = 0; i < followings.size(); i++) {
         DecisionConnection connection = cast(followings.get(i));
         if (connection.getState() == state) {
            return connection;
         }
      }
      return null;
   }
DecisionConnection extends Connection

more to come...

-- AlexGreif - 22 Apr 2003

Topic NiceCasts . { Edit | Attach | Ref-By | Printable | Diffs | r1.24 | > | r1.23 | > | r1.22 | More }
Revision r1.1 - 22 Apr 2003 - 16:21 GMT - AlexGreif
Parents: WebHome
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.