Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
142 views
in Technique[技术] by (71.8m points)

java - Parameter class of headers?

I have a design question: I want to write to a CSV file some data.

I have separate class to write data to CSV.

My problem is with the data and how to represent it:

  • This data is composed of two lines of constant headers (main and secondary) and data lines that their values is changing.
  • A line of headers is just a coma separated line of string values, my question is how to save these values?

For the parameter lines I created a parameters class that has a method: getLine.

For example:

Electrical params, , , Environment params
Voltage, Current, Resistance, Temperature, Humidity
2.3, 1.2, 0.5, 25c, 84%

The empty cells are for the CSV to look good. My questions is about the first two lines: What is the recommended way to treat the headers?

Should I create a headers class? Two classes (One for main and one for secondary)? Other?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Depends on how complex of a problem you are trying to solve. If you just need to keep track of a list of headers, then just keep it as a list of strings.

If you want a hierarchy of headers maybe a Header class and Subheader class?

public class Header {
  public String getName() {...}
  public ArrayList<Subheader> getSubheaders() {...}
  public int[] getColumnRange() {...}
}

public class Subheader {
  public String getName() {...}
  public int getColumn() {...}
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...