Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
If I understand your intention correctly, you have a third-party class which is not a singleton and you are trying to turn it into a singleton by wrapping it in a new singleton class? That won't work. Anyone can still create multiple instances of the third-party class themselves.
Your use of the word "library" is not what developers call a library. It implies that you've written a set of useful classes that can be used by other programmers. What you actually have written is a Java class representing a real-world library.
This works with ASCII, but Character.isAlphabetic() and isDigit() can both return true for various non-ASCII Unicode characters and then you'll get an ArrayIndexOutOfBoundsException.
You can cheat by putting the Morse code for each letter into a single byte instead of a String, by treating the dots and dashes as the bit values 0 and 1. I'm just mentioning it as a point of interest. Although that makes it slightly more efficient, I wouldn't recommend it because it makes the code harder to understand. It may be useful if you are really short of memory, for example if targeting a cheap mobile phone with only a small amount of RAM.
Also, I'm not sure your timings are correct. You seem to have a 500 ms wait between letters, with only an addition 10 ms between words. The space between letters should be a dash duration, and between words should be three times the dash duration.
You could use the method tone(frequency, duration, volume) from stackoverflow.com/a/6700039/638028 . This gives you the flexibility to vary the output speed at runtime, and saves you having to keep all these wav files around.
The best way is to measure the performance impact yourself. Try it with a subset of your data - say the first 100 thousand records. Use this method and then compare it with a dummy method that has a trivial (very fast) implementation, e.g. one that returns true 95% of the time and false once every 20 calls. Then compare the timings between the two. I think you will find very little difference. To improve performance, look at the implementation of the constructor BigDecimal(String) and copy the code that parses the string and leave out the code that creates the object which you don't need.
Yes, but your code is not doing a System.out.println. It is only creating a BigDecimal and then a BigInteger and immediately throwing both away. So, what's the point of creating a BigInteger and then throwing it away? Might as well not create it.
Although the use of a Map makes the code clearer, I doubt it would make it faster. The time complexities that you quote are correct, but they don't tell the whole story. These are only useful when thinking about scalability. For this small collection of letters and numbers, I would expect an array to be much faster than a HashMap, since the data is held in contiguous memory which is going to be in the processor's L1 cache; whereas a HashMap would have to box & unbox between char and Character and use indirection. Don't assume better performance unless you measure.