Java2Nrx "educational" question...

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Java2Nrx "educational" question...

maillists (@MQSystems)

Found this piece of java code:

 

import java.io.*;

import java.net.*;

import java.util.*;

import static java.lang.System.out;

 

public class ListNets {

 

    public static void main(String args[]) throws SocketException {

        Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();

        for (NetworkInterface netint : Collections.list(nets))

            displayInterfaceInformation(netint);

    }

 

    static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {

        out.printf("Display name: %s\n", netint.getDisplayName());

        out.printf("Name: %s\n", netint.getName());

        Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();

        for (InetAddress inetAddress : Collections.list(inetAddresses)) {

            out.printf("InetAddress: %s\n", inetAddress);

        }

        out.printf("\n");

     }

}

 

Java2Nrx-ed it to:

 

import java.io.

import java.net.

import java.util.

 

 

class ListNets public 

 

    method main( args=String[] ) static  signals SocketException

        nets = Enumeration /* **nonrx**  <NetworkInterface> ** */

        nets = NetworkInterface.getNetworkInterfaces()

        for (netint = NetworkInterface

         : Collections.list(nets)) displayInterfaceInformation(netint)

 

 

    method displayInterfaceInformation( netint=NetworkInterface ) static  signals SocketException

        say "Display name: " netint.getDisplayName()

        say "Name: " netint.getName()

        inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */

        inetAddresses = netint.getInetAddresses()

        for (inetAddress = InetAddress

         : Collections.list(inetAddresses)) say "InetAddress: " inetAddress

 

        say "\n"

 

when it try to compile this with nrc I get:

 

C:\NetRexx\java2nrx>nrc ListNets

NetRexx portable processor, version NetRexx 3.02, build 172-20130625-1742

Copyright (c) RexxLA, 2011,2013.  All rights reserved.

Parts Copyright (c) IBM Corporation, 1995,2008.

Program ListNets.nrx

12 +++          : Collections.list(nets)) displayInterfaceInformation(netint)

    +++          ^

    +++ Error: Unexpected character found in source: ':' (hexadecimal encoding: 003A)

Compilation of 'ListNets.nrx' failed [one error]

 

 

I re-wrote part of this in another way,so I have the code working now…

but I fail to understand what the bold orange part does or what it is supposed to translate into?

Can someone shed some light on this for me please?

It feels I took the long way home and fail to see the short cut…

 

Working different nrx code but doing the same…

 

import java.io.

import java.net.

import java.util.

 

class ListNetsx public 

 

    method main( args=String[] ) static  signals SocketException

        net_list = Enumeration /* **nonrx**  <NetworkInterface> ** */

        net_list = NetworkInterface.getNetworkInterfaces()

        net_if = NetworkInterface

        loop while net_list.hasMoreElements()

          net_if = (NetworkInterface net_list.nextElement())

        

          inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */

          inetAddresses = net_if.getInetAddresses()

          say "Display name: "||net_if.getDisplayName()

          say "Name: "||net_if.getName()

          inetAddr = InetAddress

          loop while inetAddresses.hasMoreElements()

            inetAddr = (InetAddress inetAddresses.nextElement())

              say inetAddr

          end 

        end

 

 

Michael

 

 

 

 

 

 


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Java2Nrx "educational" question...

alansam
Michael,

As of Java 5 the looping construct [for] was enhanced to provide a "loop over" capability for members of the Collection classes.  The Java syntax above is shorthand for:

    for (Iterator i = Collections.list(nets).iterator(); i.hasNext();) {
      NetworkInterface netint = (NetworkInterface) i.next();
      displayInterfaceInformation(netint);
    }

Regards,
Alan.


On 10 May 2014 06:00, <[hidden email]> wrote:

Found this piece of java code:

 

import java.io.*;

import java.net.*;

import java.util.*;

import static java.lang.System.out;

 

public class ListNets {

 

    public static void main(String args[]) throws SocketException {

        Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();

        for (NetworkInterface netint : Collections.list(nets))

            displayInterfaceInformation(netint);

    }

 

    static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {

        out.printf("Display name: %s\n", netint.getDisplayName());

        out.printf("Name: %s\n", netint.getName());

        Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();

        for (InetAddress inetAddress : Collections.list(inetAddresses)) {

            out.printf("InetAddress: %s\n", inetAddress);

        }

        out.printf("\n");

     }

}

 

Java2Nrx-ed it to:

 

import java.io.

import java.net.

import java.util.

 

 

class ListNets public 

 

    method main( args=String[] ) static  signals SocketException

        nets = Enumeration /* **nonrx**  <NetworkInterface> ** */

        nets = NetworkInterface.getNetworkInterfaces()

        for (netint = NetworkInterface

         : Collections.list(nets)) displayInterfaceInformation(netint)

 

 

    method displayInterfaceInformation( netint=NetworkInterface ) static  signals SocketException

        say "Display name: " netint.getDisplayName()

        say "Name: " netint.getName()

        inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */

        inetAddresses = netint.getInetAddresses()

        for (inetAddress = InetAddress

         : Collections.list(inetAddresses)) say "InetAddress: " inetAddress

 

        say "\n"

 

when it try to compile this with nrc I get:

 

C:\NetRexx\java2nrx>nrc ListNets

NetRexx portable processor, version NetRexx 3.02, build 172-20130625-1742

Copyright (c) RexxLA, 2011,2013.  All rights reserved.

Parts Copyright (c) IBM Corporation, 1995,2008.

Program ListNets.nrx

12 +++          : Collections.list(nets)) displayInterfaceInformation(netint)

    +++          ^

    +++ Error: Unexpected character found in source: ':' (hexadecimal encoding: 003A)

Compilation of 'ListNets.nrx' failed [one error]

 

 

I re-wrote part of this in another way,so I have the code working now…

but I fail to understand what the bold orange part does or what it is supposed to translate into?

Can someone shed some light on this for me please?

It feels I took the long way home and fail to see the short cut…

 

Working different nrx code but doing the same…

 

import java.io.

import java.net.

import java.util.

 

class ListNetsx public 

 

    method main( args=String[] ) static  signals SocketException

        net_list = Enumeration /* **nonrx**  <NetworkInterface> ** */

        net_list = NetworkInterface.getNetworkInterfaces()

        net_if = NetworkInterface

        loop while net_list.hasMoreElements()

          net_if = (NetworkInterface net_list.nextElement())

        

          inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */

          inetAddresses = net_if.getInetAddresses()

          say "Display name: "||net_if.getDisplayName()

          say "Name: "||net_if.getName()

          inetAddr = InetAddress

          loop while inetAddresses.hasMoreElements()

            inetAddr = (InetAddress inetAddresses.nextElement())

              say inetAddr

          end 

        end

 

 

Michael

 

 

 

 

 

 


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: Java2Nrx "educational" question...

Kermit Kiser
Alan forgot to mention that NetRexx 3.01 included an enhancement of the "LOOP" instruction allowing use of "OVER" with Java collections. A simple NetRexx code equivalent with "loop over" is this:

class ListNets public

    method main( args=String[] ) static  signals SocketException

        nets = Enumeration /* **nonrx**  <NetworkInterface> ** */
        nets = NetworkInterface.getNetworkInterfaces()

       netint = NetworkInterface
       loop netint over Collections.list(nets)
         displayInterfaceInformation(netint)
        end

    method displayInterfaceInformation( netint=NetworkInterface ) static  signals SocketException

        say "Display name: " netint.getDisplayName()
        say "Name: " netint.getName()

        inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */
        inetAddresses = netint.getInetAddresses()

        inetAddress = InetAddress
        loop inetAddress over Collections.list(inetAddresses)
             say "InetAddress: " inetAddress
           end

        say "\n"


On 5/10/2014 11:26 AM, Alan Sampson wrote:
Michael,

As of Java 5 the looping construct [for] was enhanced to provide a "loop over" capability for members of the Collection classes.  The Java syntax above is shorthand for:

    for (Iterator i = Collections.list(nets).iterator(); i.hasNext();) {
      NetworkInterface netint = (NetworkInterface) i.next();
      displayInterfaceInformation(netint);
    }

Regards,
Alan.


On 10 May 2014 06:00, <[hidden email]> wrote:

Found this piece of java code:

 

import java.io.*;

import java.net.*;

import java.util.*;

import static java.lang.System.out;

 

public class ListNets {

 

    public static void main(String args[]) throws SocketException {

        Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();

        for (NetworkInterface netint : Collections.list(nets))

            displayInterfaceInformation(netint);

    }

 

    static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {

        out.printf("Display name: %s\n", netint.getDisplayName());

        out.printf("Name: %s\n", netint.getName());

        Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();

        for (InetAddress inetAddress : Collections.list(inetAddresses)) {

            out.printf("InetAddress: %s\n", inetAddress);

        }

        out.printf("\n");

     }

}

 

Java2Nrx-ed it to:

 

import java.io.

import java.net.

import java.util.

 

 

class ListNets public 

 

    method main( args=String[] ) static  signals SocketException

        nets = Enumeration /* **nonrx**  <NetworkInterface> ** */

        nets = NetworkInterface.getNetworkInterfaces()

        for (netint = NetworkInterface

         : Collections.list(nets)) displayInterfaceInformation(netint)

 

 

    method displayInterfaceInformation( netint=NetworkInterface ) static  signals SocketException

        say "Display name: " netint.getDisplayName()

        say "Name: " netint.getName()

        inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */

        inetAddresses = netint.getInetAddresses()

        for (inetAddress = InetAddress

         : Collections.list(inetAddresses)) say "InetAddress: " inetAddress

 

        say "\n"

 

when it try to compile this with nrc I get:

 

C:\NetRexx\java2nrx>nrc ListNets

NetRexx portable processor, version NetRexx 3.02, build 172-20130625-1742

Copyright (c) RexxLA, 2011,2013.  All rights reserved.

Parts Copyright (c) IBM Corporation, 1995,2008.

Program ListNets.nrx

12 +++          : Collections.list(nets)) displayInterfaceInformation(netint)

    +++          ^

    +++ Error: Unexpected character found in source: ':' (hexadecimal encoding: 003A)

Compilation of 'ListNets.nrx' failed [one error]

 

 

I re-wrote part of this in another way,so I have the code working now…

but I fail to understand what the bold orange part does or what it is supposed to translate into?

Can someone shed some light on this for me please?

It feels I took the long way home and fail to see the short cut…

 

Working different nrx code but doing the same…

 

import java.io.

import java.net.

import java.util.

 

class ListNetsx public 

 

    method main( args=String[] ) static  signals SocketException

        net_list = Enumeration /* **nonrx**  <NetworkInterface> ** */

        net_list = NetworkInterface.getNetworkInterfaces()

        net_if = NetworkInterface

        loop while net_list.hasMoreElements()

          net_if = (NetworkInterface net_list.nextElement())

        

          inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */

          inetAddresses = net_if.getInetAddresses()

          say "Display name: "||net_if.getDisplayName()

          say "Name: "||net_if.getName()

          inetAddr = InetAddress

          loop while inetAddresses.hasMoreElements()

            inetAddr = (InetAddress inetAddresses.nextElement())

              say inetAddr

          end 

        end

 

 

Michael

 

 

 

 

 

 


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Java2Nrx "educational" question...

alansam
Yep I did forget to mention LOOP OVER which is a pretty neat enhancement to NetRexx and way more expressive than the Java equivalent.

Note though that even with the for (Iterator...) syntax, java2nrx still has a hard time converting the code into instantly compiled NetRexx; it inserts the Iterator declaration between the loop and while statements.

loop i = Iterator
        i = Collections.list(nets).iterator()   while i.hasNext()  

NetRexx doesn't like the import static java.lang.System.out; clause, use of System.out.printf(String, ...) [not impossible to overcome but messy & not very Rexx like], variable names that are the same as type names and the way args is declared as main(String args[]) either.

I took a little extra time and recoded the Java as follows:

import java.io.*;
import java.net.*;
import java.util.*;
 
public class ListNets2 {
 
  public static void main(String[] args) throws SocketException {
    Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
    Iterator netsIter = Collections.list(nets).iterator();
    while (netsIter.hasNext()) {
      NetworkInterface netint = (NetworkInterface) netsIter.next();
      displayInterfaceInformation(netint);
    }
  }

  static void displayInterfaceInformation(NetworkInterface netint) /*throws SocketException*/ {
    System.out.println("Display name: " + netint.getDisplayName());
    System.out.println("Name: " + netint.getName());
    Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
    Iterator netaddrIter = Collections.list(inetAddresses).iterator();
    while (netaddrIter.hasNext()) {
      InetAddress inetAddress_ = (InetAddress) netaddrIter.next();
      System.out.println("InetAddress: " + inetAddress_);
    }
    System.out.println();
   }
}

which renders the following NetRexx:

import java.io.
import java.net.
import java.util.

class ListNets2 public  

    method main( args=String[] ) static  signals SocketException
        nets = Enumeration /* **nonrx**  <NetworkInterface> ** */
        nets = NetworkInterface.getNetworkInterfaces()
        netsIter = Iterator
        netsIter = Collections.list(nets).iterator()
        loop while netsIter.hasNext()
            netint = NetworkInterface
            netint = (NetworkInterface) netsIter.next()
            displayInterfaceInformation(netint)

        end 


    method displayInterfaceInformation( netint=NetworkInterface ) static 
        System.out.println("Display name: " || netint.getDisplayName())
        System.out.println("Name: " || netint.getName())
        inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */
        inetAddresses = netint.getInetAddresses()
        netaddrIter = Iterator
        netaddrIter = Collections.list(inetAddresses).iterator()
        loop while netaddrIter.hasNext()
            inetAddress_ = InetAddress
            inetAddress_ = (InetAddress) netaddrIter.next()
            System.out.println("InetAddress: " || inetAddress_)

        end 
        System.out.println()

it still doesn't compile due to the (NetworkInterface) and (InetAddress) casts but that's easily resolved by removing the surrounding parentheses.  Once those tweaks are applied the code compiles and runs.

Good luck,
Alan.


On 10 May 2014 12:54, Kermit Kiser <[hidden email]> wrote:
Alan forgot to mention that NetRexx 3.01 included an enhancement of the "LOOP" instruction allowing use of "OVER" with Java collections. A simple NetRexx code equivalent with "loop over" is this:


class ListNets public

    method main( args=String[] ) static  signals SocketException

        nets = Enumeration /* **nonrx**  <NetworkInterface> ** */
        nets = NetworkInterface.getNetworkInterfaces()

       netint = NetworkInterface
       loop netint over Collections.list(nets)
         displayInterfaceInformation(netint)
        end


    method displayInterfaceInformation( netint=NetworkInterface ) static  signals SocketException

        say "Display name: " netint.getDisplayName()
        say "Name: " netint.getName()

        inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */
        inetAddresses = netint.getInetAddresses()

        inetAddress = InetAddress
        loop inetAddress over Collections.list(inetAddresses)
             say "InetAddress: " inetAddress
           end

        say "\n"



On 5/10/2014 11:26 AM, Alan Sampson wrote:
Michael,

As of Java 5 the looping construct [for] was enhanced to provide a "loop over" capability for members of the Collection classes.  The Java syntax above is shorthand for:

    for (Iterator i = Collections.list(nets).iterator(); i.hasNext();) {
      NetworkInterface netint = (NetworkInterface) i.next();
      displayInterfaceInformation(netint);
    }

Regards,
Alan.


On 10 May 2014 06:00, <[hidden email]> wrote:

Found this piece of java code:

 

import java.io.*;

import java.net.*;

import java.util.*;

import static java.lang.System.out;

 

public class ListNets {

 

    public static void main(String args[]) throws SocketException {

        Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();

        for (NetworkInterface netint : Collections.list(nets))

            displayInterfaceInformation(netint);

    }

 

    static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {

        out.printf("Display name: %s\n", netint.getDisplayName());

        out.printf("Name: %s\n", netint.getName());

        Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();

        for (InetAddress inetAddress : Collections.list(inetAddresses)) {

            out.printf("InetAddress: %s\n", inetAddress);

        }

        out.printf("\n");

     }

}

 

Java2Nrx-ed it to:

 

import java.io.

import java.net.

import java.util.

 

 

class ListNets public 

 

    method main( args=String[] ) static  signals SocketException

        nets = Enumeration /* **nonrx**  <NetworkInterface> ** */

        nets = NetworkInterface.getNetworkInterfaces()

        for (netint = NetworkInterface

         : Collections.list(nets)) displayInterfaceInformation(netint)

 

 

    method displayInterfaceInformation( netint=NetworkInterface ) static  signals SocketException

        say "Display name: " netint.getDisplayName()

        say "Name: " netint.getName()

        inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */

        inetAddresses = netint.getInetAddresses()

        for (inetAddress = InetAddress

         : Collections.list(inetAddresses)) say "InetAddress: " inetAddress

 

        say "\n"

 

when it try to compile this with nrc I get:

 

C:\NetRexx\java2nrx>nrc ListNets

NetRexx portable processor, version NetRexx 3.02, build 172-20130625-1742

Copyright (c) RexxLA, 2011,2013.  All rights reserved.

Parts Copyright (c) IBM Corporation, 1995,2008.

Program ListNets.nrx

12 +++          : Collections.list(nets)) displayInterfaceInformation(netint)

    +++          ^

    +++ Error: Unexpected character found in source: ':' (hexadecimal encoding: 003A)

Compilation of 'ListNets.nrx' failed [one error]

 

 

I re-wrote part of this in another way,so I have the code working now…

but I fail to understand what the bold orange part does or what it is supposed to translate into?

Can someone shed some light on this for me please?

It feels I took the long way home and fail to see the short cut…

 

Working different nrx code but doing the same…

 

import java.io.

import java.net.

import java.util.

 

class ListNetsx public 

 

    method main( args=String[] ) static  signals SocketException

        net_list = Enumeration /* **nonrx**  <NetworkInterface> ** */

        net_list = NetworkInterface.getNetworkInterfaces()

        net_if = NetworkInterface

        loop while net_list.hasMoreElements()

          net_if = (NetworkInterface net_list.nextElement())

        

          inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */

          inetAddresses = net_if.getInetAddresses()

          say "Display name: "||net_if.getDisplayName()

          say "Name: "||net_if.getName()

          inetAddr = InetAddress

          loop while inetAddresses.hasMoreElements()

            inetAddr = (InetAddress inetAddresses.nextElement())

              say inetAddr

          end 

        end

 

 

Michael

 

 

 

 

 

 


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: Java2Nrx "educational" question...

duvangrd
In reply to this post by maillists (@MQSystems)

Please remove me from this list.

 

Thank you.

 

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of [hidden email]
Sent: Saturday, May 10, 2014 8:00 AM
To: IBM Netrexx
Subject: [Ibm-netrexx] Java2Nrx "educational" question...

 

Found this piece of java code:

 

import java.io.*;

import java.net.*;

import java.util.*;

import static java.lang.System.out;

 

public class ListNets {

 

    public static void main(String args[]) throws SocketException {

        Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();

        for (NetworkInterface netint : Collections.list(nets))

            displayInterfaceInformation(netint);

    }

 

    static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {

        out.printf("Display name: %s\n", netint.getDisplayName());

        out.printf("Name: %s\n", netint.getName());

        Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();

        for (InetAddress inetAddress : Collections.list(inetAddresses)) {

            out.printf("InetAddress: %s\n", inetAddress);

        }

        out.printf("\n");

     }

}

 

Java2Nrx-ed it to:

 

import java.io.

import java.net.

import java.util.

 

 

class ListNets public 

 

    method main( args=String[] ) static  signals SocketException

        nets = Enumeration /* **nonrx**  <NetworkInterface> ** */

        nets = NetworkInterface.getNetworkInterfaces()

        for (netint = NetworkInterface

         : Collections.list(nets)) displayInterfaceInformation(netint)

 

 

    method displayInterfaceInformation( netint=NetworkInterface ) static  signals SocketException

        say "Display name: " netint.getDisplayName()

        say "Name: " netint.getName()

        inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */

        inetAddresses = netint.getInetAddresses()

        for (inetAddress = InetAddress

         : Collections.list(inetAddresses)) say "InetAddress: " inetAddress

 

        say "\n"

 

when it try to compile this with nrc I get:

 

C:\NetRexx\java2nrx>nrc ListNets

NetRexx portable processor, version NetRexx 3.02, build 172-20130625-1742

Copyright (c) RexxLA, 2011,2013.  All rights reserved.

Parts Copyright (c) IBM Corporation, 1995,2008.

Program ListNets.nrx

12 +++          : Collections.list(nets)) displayInterfaceInformation(netint)

    +++          ^

    +++ Error: Unexpected character found in source: ':' (hexadecimal encoding: 003A)

Compilation of 'ListNets.nrx' failed [one error]

 

 

I re-wrote part of this in another way,so I have the code working now…

but I fail to understand what the bold orange part does or what it is supposed to translate into?

Can someone shed some light on this for me please?

It feels I took the long way home and fail to see the short cut…

 

Working different nrx code but doing the same…

 

import java.io.

import java.net.

import java.util.

 

class ListNetsx public 

 

    method main( args=String[] ) static  signals SocketException

        net_list = Enumeration /* **nonrx**  <NetworkInterface> ** */

        net_list = NetworkInterface.getNetworkInterfaces()

        net_if = NetworkInterface

        loop while net_list.hasMoreElements()

          net_if = (NetworkInterface net_list.nextElement())

        

          inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */

          inetAddresses = net_if.getInetAddresses()

          say "Display name: "||net_if.getDisplayName()

          say "Name: "||net_if.getName()

          inetAddr = InetAddress

          loop while inetAddresses.hasMoreElements()

            inetAddr = (InetAddress inetAddresses.nextElement())

              say inetAddr

          end 

        end

 

 

Michael

 

 

 

 

 

 


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Java2Nrx "educational" question...

maillists (@MQSystems)
In reply to this post by alansam

Thanks both of you for the additional insights!

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Alan Sampson
Sent: zaterdag 10 mei 2014 22:24
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] Java2Nrx "educational" question...

 

Yep I did forget to mention LOOP OVER which is a pretty neat enhancement to NetRexx and way more expressive than the Java equivalent.

 

Note though that even with the for (Iterator...) syntax, java2nrx still has a hard time converting the code into instantly compiled NetRexx; it inserts the Iterator declaration between the loop and while statements.

 

loop i = Iterator

        i = Collections.list(nets).iterator()   while i.hasNext()  

 

NetRexx doesn't like the import static java.lang.System.out; clause, use of System.out.printf(String, ...) [not impossible to overcome but messy & not very Rexx like], variable names that are the same as type names and the way args is declared as main(String args[]) either.

 

I took a little extra time and recoded the Java as follows:

 

import java.io.*;

import java.net.*;

import java.util.*;

 

public class ListNets2 {

 

  public static void main(String[] args) throws SocketException {

    Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();

    Iterator netsIter = Collections.list(nets).iterator();

    while (netsIter.hasNext()) {

      NetworkInterface netint = (NetworkInterface) netsIter.next();

      displayInterfaceInformation(netint);

    }

  }

 

  static void displayInterfaceInformation(NetworkInterface netint) /*throws SocketException*/ {

    System.out.println("Display name: " + netint.getDisplayName());

    System.out.println("Name: " + netint.getName());

    Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();

    Iterator netaddrIter = Collections.list(inetAddresses).iterator();

    while (netaddrIter.hasNext()) {

      InetAddress inetAddress_ = (InetAddress) netaddrIter.next();

      System.out.println("InetAddress: " + inetAddress_);

    }

    System.out.println();

   }

}

 

which renders the following NetRexx:

 

import java.io.

import java.net.

import java.util.

 

class ListNets2 public  

 

    method main( args=String[] ) static  signals SocketException

        nets = Enumeration /* **nonrx**  <NetworkInterface> ** */

        nets = NetworkInterface.getNetworkInterfaces()

        netsIter = Iterator

        netsIter = Collections.list(nets).iterator()

        loop while netsIter.hasNext()

            netint = NetworkInterface

            netint = (NetworkInterface) netsIter.next()

            displayInterfaceInformation(netint)

 

        end 

 

 

    method displayInterfaceInformation( netint=NetworkInterface ) static 

        System.out.println("Display name: " || netint.getDisplayName())

        System.out.println("Name: " || netint.getName())

        inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */

        inetAddresses = netint.getInetAddresses()

        netaddrIter = Iterator

        netaddrIter = Collections.list(inetAddresses).iterator()

        loop while netaddrIter.hasNext()

            inetAddress_ = InetAddress

            inetAddress_ = (InetAddress) netaddrIter.next()

            System.out.println("InetAddress: " || inetAddress_)

 

        end 

        System.out.println()

 

it still doesn't compile due to the (NetworkInterface) and (InetAddress) casts but that's easily resolved by removing the surrounding parentheses.  Once those tweaks are applied the code compiles and runs.

 

Good luck,
Alan.

 

On 10 May 2014 12:54, Kermit Kiser <[hidden email]> wrote:

Alan forgot to mention that NetRexx 3.01 included an enhancement of the "LOOP" instruction allowing use of "OVER" with Java collections. A simple NetRexx code equivalent with "loop over" is this:



class ListNets public

    method main( args=String[] ) static  signals SocketException

        nets = Enumeration /* **nonrx**  <NetworkInterface> ** */
        nets = NetworkInterface.getNetworkInterfaces()

       netint = NetworkInterface
       loop netint over Collections.list(nets)
         displayInterfaceInformation(netint)
        end



    method displayInterfaceInformation( netint=NetworkInterface ) static  signals SocketException

        say "Display name: " netint.getDisplayName()
        say "Name: " netint.getName()

        inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */
        inetAddresses = netint.getInetAddresses()

        inetAddress = InetAddress
        loop inetAddress over Collections.list(inetAddresses)
             say "InetAddress: " inetAddress
           end

        say "\n"



On 5/10/2014 11:26 AM, Alan Sampson wrote:

Michael,

 

As of Java 5 the looping construct [for] was enhanced to provide a "loop over" capability for members of the Collection classes.  The Java syntax above is shorthand for:

 

    for (Iterator i = Collections.list(nets).iterator(); i.hasNext();) {

      NetworkInterface netint = (NetworkInterface) i.next();

      displayInterfaceInformation(netint);

    }

 

Regards,
Alan.

 

On 10 May 2014 06:00, <[hidden email]> wrote:

Found this piece of java code:

 

import java.io.*;

import java.net.*;

import java.util.*;

import static java.lang.System.out;

 

public class ListNets {

 

    public static void main(String args[]) throws SocketException {

        Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();

        for (NetworkInterface netint : Collections.list(nets))

            displayInterfaceInformation(netint);

    }

 

    static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {

        out.printf("Display name: %s\n", netint.getDisplayName());

        out.printf("Name: %s\n", netint.getName());

        Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();

        for (InetAddress inetAddress : Collections.list(inetAddresses)) {

            out.printf("InetAddress: %s\n", inetAddress);

        }

        out.printf("\n");

     }

}

 

Java2Nrx-ed it to:

 

import java.io.

import java.net.

import java.util.

 

 

class ListNets public 

 

    method main( args=String[] ) static  signals SocketException

        nets = Enumeration /* **nonrx**  <NetworkInterface> ** */

        nets = NetworkInterface.getNetworkInterfaces()

        for (netint = NetworkInterface

         : Collections.list(nets)) displayInterfaceInformation(netint)

 

 

    method displayInterfaceInformation( netint=NetworkInterface ) static  signals SocketException

        say "Display name: " netint.getDisplayName()

        say "Name: " netint.getName()

        inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */

        inetAddresses = netint.getInetAddresses()

        for (inetAddress = InetAddress

         : Collections.list(inetAddresses)) say "InetAddress: " inetAddress

 

        say "\n"

 

when it try to compile this with nrc I get:

 

C:\NetRexx\java2nrx>nrc ListNets

NetRexx portable processor, version NetRexx 3.02, build 172-20130625-1742

Copyright (c) RexxLA, 2011,2013.  All rights reserved.

Parts Copyright (c) IBM Corporation, 1995,2008.

Program ListNets.nrx

12 +++          : Collections.list(nets)) displayInterfaceInformation(netint)

    +++          ^

    +++ Error: Unexpected character found in source: ':' (hexadecimal encoding: 003A)

Compilation of 'ListNets.nrx' failed [one error]

 

 

I re-wrote part of this in another way,so I have the code working now…

but I fail to understand what the bold orange part does or what it is supposed to translate into?

Can someone shed some light on this for me please?

It feels I took the long way home and fail to see the short cut…

 

Working different nrx code but doing the same…

 

import java.io.

import java.net.

import java.util.

 

class ListNetsx public 

 

    method main( args=String[] ) static  signals SocketException

        net_list = Enumeration /* **nonrx**  <NetworkInterface> ** */

        net_list = NetworkInterface.getNetworkInterfaces()

        net_if = NetworkInterface

        loop while net_list.hasMoreElements()

          net_if = (NetworkInterface net_list.nextElement())

        

          inetAddresses = Enumeration /* **nonrx**  <InetAddress> ** */

          inetAddresses = net_if.getInetAddresses()

          say "Display name: "||net_if.getDisplayName()

          say "Name: "||net_if.getName()

          inetAddr = InetAddress

          loop while inetAddresses.hasMoreElements()

            inetAddr = (InetAddress inetAddresses.nextElement())

              say inetAddr

          end 

        end

 

 

Michael

 

 

 

 

 

 


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



 

--
Can't tweet, won't tweet!

 

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
 

 


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



 

--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/