InvalidArgError for addNewSegment into OrekitEphemerisFile.OrekitSatelliteEphemeris

I’m trying to produce an OEM file in python.

I have been following this example: https://www.orekit.org/static/xref-test/org/orekit/files/general/OrekitEphemerisFileTest.html.

My main issue comes when inserting the states into OrekitEphemerisFile.OrekitSatelliteEphemeris.addNewSegment()

Here is my code:

def single_sat_test(Earth, df_sc):
    orbit = KeplerianOrbit(
                float(df_sc['sma']),   # a - semimajor axis (m)
                float(df_sc['ecc']),   # e - eccentricity
                float(df_sc['inc']),   # i - inclination (rad)
                float(df_sc['omg']),   # ω - arg of perig (rad)
                float(df_sc['raan']),  # RAAN - (rad)
                float(df_sc['tanm']),  # v - true anomaly (rad)
                PositionAngle.TRUE,           # type of anomaly to use
                Earth.frames.inertial,        # orbit definition frame
                df_sc['epoch'],        # epoch
                Earth.mu)                     # Center body gravity constant
    propagtor = KeplerianPropagator(orbit)
    state = propagtor.propagate(absDate)
    state_2 = propagtor.propagate(absDate_1)
    print(state.isOrbitDefined())
    OEM_file = OrekitEphemerisFile()
    # satellite = OEM_file.addSatellite('SC01')
    satellite = OrekitEphemerisFile.OrekitSatelliteEphemeris('SC01')
    print(satellite.getId())
    satellite.addNewSegment([state, state_2])
    print(orbit)
    return orbit

I get this error:

Traceback (most recent call last):

  File "C:\Users\Hubert Khoo\Documents\Sydereal\ArcSim\ArcSim\OEM.py", line 111, in <module>
    orbit = single_sat_test(Earth, df_sc)

  File "C:\Users\Hubert Khoo\Documents\Sydereal\ArcSim\ArcSim\OEM.py", line 105, in single_sat_test
    satellite.addNewSegment([state, state_2])

InvalidArgsError: (<class 'org.orekit.files.general.OrekitEphemerisFile$OrekitSatelliteEphemeris'>, 'addNewSegment', ([<SpacecraftState: SpacecraftState{orbit=Keplerian parameters: {a: 1.277E7; e: 0.0; i: 56.0; pa: 0.0; raan: 14.999999999999998; v: 327036.22732768126;}, attitude=org.orekit.attitudes.Attitude@8ba637c, mass=1000.0, additional={}}>, <SpacecraftState: SpacecraftState{orbit=Keplerian parameters: {a: 1.277E7; e: 0.0; i: 56.0; pa: 0.0; raan: 14.999999999999998; v: 327040.73941691045;}, attitude=org.orekit.attitudes.Attitude@2e37373b, mass=1000.0, additional={}}>],))

I need more clarification on why my arguments are invalid, is the list of spacecraft states not considered a list? I am basing the argument inputs off of this API document : https://www.orekit.org/site-orekit-development/apidocs/org/orekit/files/general/OrekitEphemerisFile.OrekitSatelliteEphemeris.html

My current assumption on how the python wrapper works is that inputting a list of spacecraft states would be enough, with the interpolation, body and timescale being default.

Thank you for taking the time to read this.

I have solved this issue, it is necessary to import ArrayList from java.util, and then add all states into the arraylist.

I found the solution from https://gitlab.com/jorispio/ccsds2czml/-/blob/master/example/single/simple_oem.py

here is the solution code

from java.util import ArrayList as ArrayList

def single_sat_test(Earth, df_sc):
    orbit = KeplerianOrbit(
                float(df_sc['sma']),   # a - semimajor axis (m)
                float(df_sc['ecc']),   # e - eccentricity
                float(df_sc['inc']),   # i - inclination (rad)
                float(df_sc['omg']),   # ω - arg of perig (rad)
                float(df_sc['raan']),  # RAAN - (rad)
                float(df_sc['tanm']),  # v - true anomaly (rad)
                PositionAngle.TRUE,           # type of anomaly to use
                Earth.frames.inertial,        # orbit definition frame
                df_sc['epoch'],        # epoch
                Earth.mu)                     # Center body gravity constant
    propagtor = KeplerianPropagator(orbit)
    state = propagtor.propagate(absDate)
    state_2 = propagtor.propagate(absDate_1)
    java_state_list = ArrayList()
    [java_state_list.add(s) for s in [state,state_2]]
    print(state)
    print(state.isOrbitDefined())
    OEM_file = OrekitEphemerisFile()
    # satellite = OEM_file.addSatellite('SC01')
    satellite = OrekitEphemerisFile.OrekitSatelliteEphemeris('SC01')
    print(satellite.getId())
    satellite.addNewSegment(java_state_list)
    print(orbit)
    return orbit

Do note that you have to import other orekit functions prior to this function, this is not a complete code. I hope this helps someone else. Thank you.