drac yang

Ranch Hand
+ Follow
since Apr 19, 2013
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by drac yang

Prosenjit Banerjee wrote:
I have understood the rule. But what can be the motivation behind it? I mean, if there is a possibility of some data to be lost if the programmer is not very careful, does not that go against the motto of Java?

considering the probability of such sort of carelessness, i think it's more worthwhile to keep the cleanness of the java system.
5 years ago
maybe you should remember the fact in particular: instance's member variables are decided by instance's type.
5 years ago
if concerning NumberFormat,

according to java se 6 documentation:
Decimal formats are generally not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.

Dave Tolls wrote:Looking at that page in Google Books I assume it's the units it's using.
The other examples given have a timing variable ending in _secs, a cache size ending in _mb and a download throttle ending in _kbps.

I will say I disagree with the whole underscore thing.
What's wrong with delaySeconds?

And I also dislike picking out instance variables by things like sticking an underscore at the start.

yes, you are right, at least in java world we nearly never use underscore for a variable name(prefer camel case), maybe except for the static final ones.

but anyway, do you know the "cw"?
5 years ago
in the book of <<the art of readable code>>, page 16, there's a suggestion for naming variables
angle -> degree_cw

what i want to know is what does the "cw" mean? thanks.
5 years ago

Henry Wong wrote:

Well, since you are already looking at the source code, look a bit further down, at the writeObject() and readObject() methods respectively. These are the methods that serializes and deserializes the HashSet.

Notice that these methods call the default methods -- which will serialize/deserialize everything but not the static or transient fields. Then, later in the methods, the map is serialized/deserialized by the methods.


after your detailed explaining, i think i got it, thanks a lot.

in this case, i think, if the serialize/deserialize process of the HashSet does not involve the invocation of its own readObject/writeObject, then it just cannot transfer the data of the HashSet.
but in which situation will this happen?

look at this code:

i guess eventually the HashSet property of person object has been "writeObject"ed by using the writeObject method of HashSet, right?

5 years ago

Henry Wong wrote:
Keep in mind, that "transient" does *not* mean that it will not be serialized. Marking something as transient just means that the default mechanism does not serialize the field. In this case, the map is still serialized, the developer of the HashSet class just chose to serialize it differently.

Again, just test it. You will see that serializing and deserializing a hashset work fine.


thank you very much, i tried, and succeeded in deserializing the HashSet object, serialize process is as follows:

but I'm still wondering why it could be deserialized since the map of the HashSet is transient.
or how can the transient map functions by the transient modifier?
5 years ago

Henry Wong wrote:The reason the underlying map is transient is because the developers chose to serialize the elements of the map with the readObject() and writeObject() methods. Perhaps, it is more efficient to do so, instead of letting the default implementation do it?

Regardless, have you tried it? If so, you will see that it works. The elements do get serialized and deserialized.


what if the developers just want to choose to serialize the hashset itself because it's much more convenient? for what reason the api designers do not allow them to do so?
5 years ago
public class HashSet<E>
   extends AbstractSet<E>
   implements Set<E>, Cloneable, java.io.Serializable
   static final long serialVersionUID = -5024744406713321676L;

   private transient HashMap<E,Object> map;

since map contains the data of the HashSet, now map has been transient,  is it still meaningful for HashSet to be serializable?
5 years ago
Set: [destinationFromPlaying, varActivity]

from what i learned, they are differernt strings, aren't they?
5 years ago
and rlist should be referenced elsewhere besides RetentionBot constructor so that it can be used for any more meaningful purpose after it's been stuffed an element of SimUnit instance.
5 years ago

Dave Tolls wrote:Using a criteria may be the key point, but until you can figure out the SQL you would right outside of a Criteria you won't get very far.

So (assuming K. Holgate's query is correct, which is something you'd need to test) you would be looking at a Subquery method, probably the eq() one.

thank you, i'll have to check more related criteria materials.

Dave Tolls wrote:What is the ORDER BY which defines what row is 'first'?

ORDER BY value, if only we can get the first result in the group.
and the most important thing i.e. my original question is how to fulfill this requirement by hibernate criteria.

Roel De Nijs wrote:And what's the expected output if you have a 5th record like:

id name value group
5 a3 1 a

yes, you are right, my provided conditions are insufficient, we can use order by.
key point here is how to fulfill this by hibernate criteria?

K. Holgate wrote:

You could do this with a self-join if you prefer.

thanks, how can I fulfill this by hibernate criteria?