@Override
  public Track createTrack(Cursor cursor) {
    int idIndex = cursor.getColumnIndexOrThrow(TracksColumns._ID);
    int nameIndex = cursor.getColumnIndexOrThrow(TracksColumns.NAME);
    int descriptionIndex = cursor.getColumnIndexOrThrow(TracksColumns.DESCRIPTION);
    int categoryIndex = cursor.getColumnIndexOrThrow(TracksColumns.CATEGORY);
    int startIdIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTID);
    int stopIdIndex = cursor.getColumnIndexOrThrow(TracksColumns.STOPID);
    int startTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME);
    int stopTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STOPTIME);
    int numPointsIndex = cursor.getColumnIndexOrThrow(TracksColumns.NUMPOINTS);
    int totalDistanceIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE);
    int totalTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME);
    int movingTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.MOVINGTIME);
    int minLatIndex = cursor.getColumnIndexOrThrow(TracksColumns.MINLAT);
    int maxLatIndex = cursor.getColumnIndexOrThrow(TracksColumns.MAXLAT);
    int minLonIndex = cursor.getColumnIndexOrThrow(TracksColumns.MINLON);
    int maxLonIndex = cursor.getColumnIndexOrThrow(TracksColumns.MAXLON);
    int maxSpeedIndex = cursor.getColumnIndexOrThrow(TracksColumns.MAXSPEED);
    int minElevationIndex = cursor.getColumnIndexOrThrow(TracksColumns.MINELEVATION);
    int maxElevationIndex = cursor.getColumnIndexOrThrow(TracksColumns.MAXELEVATION);
    int elevationGainIndex = cursor.getColumnIndexOrThrow(TracksColumns.ELEVATIONGAIN);
    int minGradeIndex = cursor.getColumnIndexOrThrow(TracksColumns.MINGRADE);
    int maxGradeIndex = cursor.getColumnIndexOrThrow(TracksColumns.MAXGRADE);
    int mapIdIndex = cursor.getColumnIndexOrThrow(TracksColumns.MAPID);
    int tableIdIndex = cursor.getColumnIndexOrThrow(TracksColumns.TABLEID);
    int iconIndex = cursor.getColumnIndexOrThrow(TracksColumns.ICON);

    Track track = new Track();
    TripStatistics tripStatistics = track.getTripStatistics();
    if (!cursor.isNull(idIndex)) {
      track.setId(cursor.getLong(idIndex));
    }
    if (!cursor.isNull(nameIndex)) {
      track.setName(cursor.getString(nameIndex));
    }
    if (!cursor.isNull(descriptionIndex)) {
      track.setDescription(cursor.getString(descriptionIndex));
    }
    if (!cursor.isNull(categoryIndex)) {
      track.setCategory(cursor.getString(categoryIndex));
    }
    if (!cursor.isNull(startIdIndex)) {
      track.setStartId(cursor.getLong(startIdIndex));
    }
    if (!cursor.isNull(stopIdIndex)) {
      track.setStopId(cursor.getLong(stopIdIndex));
    }
    if (!cursor.isNull(startTimeIndex)) {
      tripStatistics.setStartTime(cursor.getLong(startTimeIndex));
    }
    if (!cursor.isNull(stopTimeIndex)) {
      tripStatistics.setStopTime(cursor.getLong(stopTimeIndex));
    }
    if (!cursor.isNull(numPointsIndex)) {
      track.setNumberOfPoints(cursor.getInt(numPointsIndex));
    }
    if (!cursor.isNull(totalDistanceIndex)) {
      tripStatistics.setTotalDistance(cursor.getFloat(totalDistanceIndex));
    }
    if (!cursor.isNull(totalTimeIndex)) {
      tripStatistics.setTotalTime(cursor.getLong(totalTimeIndex));
    }
    if (!cursor.isNull(movingTimeIndex)) {
      tripStatistics.setMovingTime(cursor.getLong(movingTimeIndex));
    }
    if (!cursor.isNull(minLatIndex)
        && !cursor.isNull(maxLatIndex)
        && !cursor.isNull(minLonIndex)
        && !cursor.isNull(maxLonIndex)) {
      int bottom = cursor.getInt(minLatIndex);
      int top = cursor.getInt(maxLatIndex);
      int left = cursor.getInt(minLonIndex);
      int right = cursor.getInt(maxLonIndex);
      tripStatistics.setBounds(left, top, right, bottom);
    }
    if (!cursor.isNull(maxSpeedIndex)) {
      tripStatistics.setMaxSpeed(cursor.getFloat(maxSpeedIndex));
    }
    if (!cursor.isNull(minElevationIndex)) {
      tripStatistics.setMinElevation(cursor.getFloat(minElevationIndex));
    }
    if (!cursor.isNull(maxElevationIndex)) {
      tripStatistics.setMaxElevation(cursor.getFloat(maxElevationIndex));
    }
    if (!cursor.isNull(elevationGainIndex)) {
      tripStatistics.setTotalElevationGain(cursor.getFloat(elevationGainIndex));
    }
    if (!cursor.isNull(minGradeIndex)) {
      tripStatistics.setMinGrade(cursor.getFloat(minGradeIndex));
    }
    if (!cursor.isNull(maxGradeIndex)) {
      tripStatistics.setMaxGrade(cursor.getFloat(maxGradeIndex));
    }
    if (!cursor.isNull(mapIdIndex)) {
      track.setMapId(cursor.getString(mapIdIndex));
    }
    if (!cursor.isNull(tableIdIndex)) {
      track.setTableId(cursor.getString(tableIdIndex));
    }
    if (!cursor.isNull(iconIndex)) {
      track.setIcon(cursor.getString(iconIndex));
    }
    return track;
  }
Exemplo n.º 2
0
  // test Track attributes
  public void testTrackAttributes() {
    Location l = new Location("Location Test Attridutes id", "Location Test Name");
    Track t = new Track("Test id", "Test Name", "Test Type", l);
    Assert.assertEquals("Location Track id", "Test id", t.getId());
    Assert.assertEquals("Location Track Name", "Test Name", t.getName());
    Assert.assertEquals("Location Track Type", "Test Type", t.getTrackType());
    Assert.assertEquals("Location", l, t.getLocation());

    t.setName("New Test Name");
    Assert.assertEquals("Location Track set Name", "New Test Name", t.getName());

    t.setComment("New Test Comment");
    Assert.assertEquals("Location Track set Comment", "New Test Comment", t.getComment());

    t.setMoves(40);
    Assert.assertEquals("Location Track Moves", 40, t.getMoves());

    t.setLength(400);
    Assert.assertEquals("Location Track Length", 400, t.getLength());

    t.setReserved(200);
    Assert.assertEquals("Location Track Reserved", 200, t.getReserved());

    t.setUsedLength(100);
    Assert.assertEquals("Location Track Used Length", 100, t.getUsedLength());

    t.setTrainDirections(Track.NORTH);
    Assert.assertEquals("Location Track Direction North", Track.NORTH, t.getTrainDirections());

    t.setTrainDirections(Track.SOUTH);
    Assert.assertEquals("Location Track Direction South", Track.SOUTH, t.getTrainDirections());

    t.setTrainDirections(Track.EAST);
    Assert.assertEquals("Location Track Direction East", Track.EAST, t.getTrainDirections());

    t.setTrainDirections(Track.WEST);
    Assert.assertEquals("Location Track Direction West", Track.WEST, t.getTrainDirections());

    t.setTrainDirections(Track.NORTH + Track.SOUTH);
    Assert.assertEquals(
        "Location Track Direction North+South", Track.NORTH + Track.SOUTH, t.getTrainDirections());

    t.setTrainDirections(Track.EAST + Track.WEST);
    Assert.assertEquals(
        "Location Track Direction East+West", Track.EAST + Track.WEST, t.getTrainDirections());

    t.setTrainDirections(Track.NORTH + Track.SOUTH + Track.EAST + Track.WEST);
    Assert.assertEquals(
        "Location Track Direction North+South+East+West",
        Track.NORTH + Track.SOUTH + Track.EAST + Track.WEST,
        t.getTrainDirections());

    t.setRoadOption("New Test Road Option");
    Assert.assertEquals(
        "Location Track set Road Option", "New Test Road Option", t.getRoadOption());

    t.setDropOption("New Test Drop Option");
    Assert.assertEquals(
        "Location Track set Drop Option", "New Test Drop Option", t.getDropOption());

    t.setPickupOption("New Test Pickup Option");
    Assert.assertEquals(
        "Location Track set Pickup Option", "New Test Pickup Option", t.getPickupOption());
  }