Java conversion to NetRexx

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

Java conversion to NetRexx

gpatrick
This is partial Java code:
private static void printAddressInfo(String name, InetAddress... hosts) throws Exception

How does one convert the "InetAddress... hosts" to NetRexx syntax for the method, such as,
method printAddressInfo(name=String, ........) signals Exception

And also for this piece of Java code:
for(InetAddress host : hosts)

I'd guess a loop in NetRexx but unclear how it would syntactically look?
Reply | Threaded
Open this post in threaded view
|

Re: Java conversion to NetRexx

alansam
The ... syntax in Java is really just shorthand for passing an array so:

private static void printAddressInfo(String name, InetAddress... hosts) could be converted to method printAddressInfo(name = String, hosts = InetAddress[]) private static

Here's a worked example:

Java

import java.net.InetAddress;

public class TJDotty {
  public TJDotty() {
    return;
  }

  private static void printAddressInfo(String name, InetAddress... hosts) {
    System.out.println(name);
    int ix = 0;
    for (InetAddress host : hosts) {
      ix += 1;
      System.out.printf("%03d: %s%n", new Integer(ix), host.toString());
    }
    return;
  }

  public static void main(String[] args) {
    try {
    InetAddress localHost = InetAddress.getByName("localhost");
    InetAddress googleHost = InetAddress.getByName("google.com");
    printAddressInfo("Hosts", localHost, googleHost);
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
    return;
  }
}

NetRexx

/* NetRexx */
options replace format comments java crossref symbols nobinary

import java.net.InetAddress

RexxMain(arg)
return

method printAddressInfo(name = String, hosts = InetAddress[]) private static
  say name
  ix = 0
  loop host over hosts
    ix = ix + 1
    System.out.printf("%03d: %s%n", [Object Integer(ix), host.toString()]) -- simulate the ... syntax for printf
    end host
  return

method RexxMain(arg) public static
  do
    localHost = InetAddress.getByName("localhost")
    googleHost = InetAddress.getByName("google.com")
    printAddressInfo("Hosts", [InetAddress localHost, googleHost])
  catch ex = Exception
    ex.printStackTrace
  end
  return

Output (from both programs):

Hosts
001: localhost/127.0.0.1



On 22 October 2013 12:38, gpatrick <[hidden email]> wrote:
This is partial Java code:
private static void printAddressInfo(String name, InetAddress... hosts)
throws Exception

How does one convert the "InetAddress... hosts" to NetRexx syntax for the
method, such as,
method printAddressInfo(name=String, ........) signals Exception

And also for this piece of Java code:
for(InetAddress host : hosts)

I'd guess a loop in NetRexx but unclear how it would syntactically look?




--
View this message in context: http://ibm-netrexx.215625.n3.nabble.com/Java-conversion-to-NetRexx-tp4026816.html
Sent from the ibm-netrexx mailing list archive at 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: Java conversion to NetRexx

gpatrick
Awesome!  Thank you!