Skip to main content
Klitos Kyriacou's user avatar
Klitos Kyriacou's user avatar
Klitos Kyriacou's user avatar
Klitos Kyriacou
  • Member for 9 years, 1 month
  • Last seen more than 1 year ago
  • United Kingdom
comment
Create another Singleton object from a Singleton class
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.
comment
Create another Singleton object from a Singleton class
The closeCacheConnection method is not the opposite of getConnection, so there's no need to use the Double-Checked Locking Idiom for that.
awarded
awarded
revised
Basic Java library to hold books
Removed tag "library" because this isn't a library in the sense intended by this tag.
Loading…
comment
Basic Java library to hold books
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.
suggested
Approve
awarded
comment
Roman numerals to Arabic number
What is romans? Is it a List<String> that is always exactly 15 elements in size? What if the user enters a different-sized number?
awarded
comment
Morse code translator GUI
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.
comment
Morse code translator GUI
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.
comment
Morse code translator GUI
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.
comment
Morse code translator GUI
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.
comment
Using BigDecimal to validate epoch timestamp in exponential notation
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.
awarded
comment
Using BigDecimal to validate epoch timestamp in exponential notation
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.
Loading…
comment
Morse code translator GUI
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.