2

I am retrieving GeoPoints from a database and organize them for usage in frontend. The GeoPoints are aggregated in segments, the segments in layers, the layers are mapped to drive ids and that map is maped to car ids. The frontend displays all of that nicely, with Tooltips and such.

My REST GetMapping method looks like this.

public ResponseEntity<Map<Integer, Map<Integer, List<List<List<double[]>>>>>>

For new colleagues, this is insanely hard to understand. But I can't think of any other way to do it. Should I create dummy child classes of Map and List just so I can write something like

public ResponseEntity<CarMap<Integer, DriveMap<Integer, Layers<Segments<GeoPoints<double[]>>>>>>

How is something like this handled typically?

8
  • But I can't think of any other way to do it.  You can. Imagine yourself how would you implement the client for such abomination.
    – Laiv
    Jan 31, 2018 at 19:38
  • are the geopoints really double[], or are they actually a (lat, long) pair? (or (lat, long, height) triple). And there is no metadata about the segments or layers?
    – Caleth
    Feb 1, 2018 at 10:07
  • @Caleth they could be a pair, but they are just being taken out from the database and then included in the response. And since the dataset can be fairly big, additional transforming shoould probably avoided. No there, is no metadata for segments and layers. Simply accumulators ( aka lists)
    – phil294
    Feb 1, 2018 at 11:25
  • What's the structure of the database? I would expect it to be able to populate a simple DTO from the column set. How does the DB know into which segment and layer a measurement goes?
    – Caleth
    Feb 1, 2018 at 11:45
  • @Caleth database table is plain rows of drive-id/lat/long/time values. Those are selected that are visible in the desired viewport. Then, backend iterates through them. When the drive goes outside of the viewport, a new layer is created. When the time difference between two points is higher than expected, a record gap is assumed and next points are mapped on a new segment. Hope that is not too confusing. In short: processing of waypoints depending on input parameters. Cheers
    – phil294
    Feb 1, 2018 at 13:16

1 Answer 1

7

For new colleagues, this is insanely hard to understand

Yeah, no kidding. I'm surprised anyone understands it.

Why are you not using actual classes?

public ResponseEntity<List<Car>> myMethod { ... }

class Car
{
    private final int id;
    private final List<Drive> drives;
}

class Drive
{
    private final int id;
    private final List<Layer> layers;
}

class Layer
{
    private final List<Segment> segments;
}

class Segment
{
    private final List<GeoPoint> geopoints;
}

class GeoPoint
{
    private final List<Double> points;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.