Results 1 to 2 of 2
  1. #1
    nijs9 is offline Member
    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Default Tranlsate C# to Java

    I'm translating some c# code to Java. Ther is one function with problems:

    Java Code:
    private static List<Node> sortNodesByDistance(List<Node> l, Node start, boolean wayBack)
        {
            List<Node> sorted = new ArrayList<Node>();
            List<DistanceStart> temp = new ArrayList<DistanceStart>();
    
            int i = 0;
    
            for (Node n : l)
            {
                DistanceStart d = new DistanceStart();
                d.id = n.getID();
                d.positionInList = i;
                d.distance = GeoCalculations.calculateDistance(start.getLat(), start.getLon(), n.getLat(), n.getLon());
                temp.add(d);
                i++;
            }
    
            temp.Sort(delegate(DistanceStart d1, DistanceStart d2)
            {
                return d1.distance.CompareTo(d2.distance);
            });
    
            for (DistanceStart d : temp)
            {
                sorted.Add(l[d.positionInList]);
            }
    
            if (wayBack)
            {
                sorted.Reverse();
            }
    
            return sorted;
        }
    Can anyone help me to get Java equivalent of this code? Thanks!

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    936
    Rep Power
    2

    Default Re: Tranlsate C# to Java

    By the looks of it, you can almost copy/paste it, adjust some naming (Add -> add), and you're done. but as long as you don't have alternatives for GeoCalculations.calculateDistance(...) and the delegate(...) method, converting is futile.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •