crotwell / seisFile

A library for reading and writing seismic file formats in java.
GNU Lesser General Public License v3.0
27 stars 20 forks source link

No set method for SeqNum in DataHeader object #1

Closed telecoder closed 8 years ago

telecoder commented 8 years ago

It's not possible to modify the Sequence Number for and already created DataHeader object, it can only be set at creation time.

DataHeader header = new DataHeader(SEQ, 'D', false);

If you are creating a lot of MiniSeed objects for streaming data from single station it would be more efficient to reuse a single DataHeader object and change the SeqNum for it than create a new object every time.

crotwell commented 8 years ago

What you are describing is dangerous, if you reuse the header and then change the sequence number in it, it would change it for all the records that shared that header. Object creation of this type in java is pretty efficient, and i feel making a new object is better to avoid potential bugs.

telecoder commented 8 years ago

I understand your point, but then why there are set method for all the other properties? to me they are even more critical than the sequence number.

header = new DataHeader(SEQ, 'D', false); header.setStationIdentifier(stationID); header.setChannelIdentifier(channelID); header.setNetworkCode(networkCode); header.setLocationIdentifier(locationID); header.setSampleRate(samplingRate);

crotwell commented 8 years ago

The reason was that otherwise the constructor would end up with a large number of parameters. There is no code enforcement, but using the same setter twice on the same DataHeader is bad for the same reason.

But the main point is that your reason for wanting to add a setter, reuse of the object, is dangerous. Those 3 items in the constructor are needed by the superclass constructor, so they kind of need to be in the DataHeader constructor. They should never change once set in the constructor, so there is no reason to have a setter.