The data that is present most closely resembles a map of header to rest of value. This should point one in the direction of a Map
rather than a List
.
Of the data that is presented, there are two groupings of the data - the first 13 fields, and all the rest. The presentation of the all the rest is to be used in a sorted order. For this, one looks at the SortedMap interface and sees the TreeMap as one if its implementations.
The 13 field data can be used as a little known map type - the EnumMap.
With the EnumMap
, one would first define the enumerations of the fields in the order desired.
public enum Headers {
SSN,
NAME;
}
One then gets the associated code that looks something like (lacking the looping over the data):
SortedMap<String, String> other = new TreeMap<String, String>();
EnumMap<Headers, String> headers = new EnumMap<Headers, String>(Headers.class);
try {
headers.put(Headers.valueOf(key), value);
} catch (IllegalArgumentException e) {
other.put(key, value);
}
If the header is present in the enum, put it in the headers
map, otherwise put it in the other
map.
At this point, one can then iterate over the headers
EnumMap and then the other
TreeMap printing out the key and value pairs. Or present a new object that itself extends Iterable
and makes an iterator
that first walks the EnumMap and then the SortedMap.
The enum
provides easy extensibility of the code (if you want to do validation checking, one can associate it with the enum. See the Java tutorial on Enum Types to see some more things one can do with it (associate a method with the enum itself, associate values (Pattern
? an instance of a class that has an interface providing a boolean validate(String arg)
? display formatting code?) to further extend it.
Why do we call Java open source, when development or contributions are not decentralized?
The definition of "Open Source" provided by the Open Source Initiative makes no mention of accepting contributions, or how software should be developed.
You can read it here:
The term "open source" has no fixed definition. It means different things to different people.
The other point to make is that the word "Java" means lots of things:
- It is a programming language
- It is a specification of that programming language
- It is an implementation of that language (compilers, core JVM, etc)
- It is an implementation of a language plus a large "standard library"
- It is a family of implementations of language + libraries (SE, ME ... EE)
- There is OpenJDK Java versus Oracle Java ... which have different licenses.
- There are multiple vendor Java implementations based on the Oracle / Sun code base.
- There are others, like GNU Classpath Java, Apache Harmony Java (historical) Android Java, various 3rd-party Java compilers (Jikes, the Eclipse compiler, etc)
- etcetera
So, when you say "we call Java open source", that is an over-generalization ... and in many cases wrong.
Does (OpenJDK) Java qualify as Open Source ?
Yes. According to the definition linked above.
According to your personal definition of open source, maybe no. But I doubt that your personal definition would get much support. Even in the Free Software community.
You might be confusing Open Source (or open source) with "The Open Source Way". The latter is described as:
"a way of thinking about how people collaborate within a community to achieve common goals and interests."
... but there is no "definitional requirement" that Open Source software be developed that way. Or open source software either.
Best Answer
In typical usage, an "array" can mean either a single-dimensional array, or a multidimensional array. Also, in mathematics, a matrix is a 2-dimensional array while a vector is a 1-dimensional array.