I am still learning how to translate C# code using LinQ into standard Java. I am currently working on the following.
// For reference
private SortedSet<Message> _set = new SortedSet<Message>(new MessageSentTimeStampComparer())
List<Message> messages = new List<Message>();
//
lock (_setLock)
{
messages.AddRange(_set.Where((m) => long.Parse(m.Attribute[0].Value) < epochWindowTime));
_set.RemoveWhere((m) => long.Parse(m.Attribute[0].Value) < epochWindowTime);
}
If I understand this correctly, these two lines of code both iterate over the entire SortedSet _set.
The first line adds all of the messages in _set where attribute 0 of each message is less than the epochWindowTime.
The second line removes any message from _set where the message's attribute 0 is less than the epochWindowTime.
If I were to replicate this functionality in Java I would do something like the following
_setLock.lock();
Iterator<Message> _setIter = _set.iterator();
//TODO
while(_setIter.hasNext())
{
Message temp = _setIter.next();
Long value = Long.valueOf(temp.getAttributes().
get("Timestamp"));
if(value.longValue() < epochWindowTime)
{
messages.add(temp);
_set.remove(temp);
}
}
_setLock.unlock();
Is my understanding and implementation correct?