Permalink
Browse files

Polish

Issues: SWF-1532
  • Loading branch information...
1 parent 54a300e commit 22289e4bf30b61129e116013fec2bee20f597570 @rstoyanchev rstoyanchev committed Apr 6, 2012
@@ -109,7 +109,8 @@ public void setLockTimeoutSeconds(int lockTimeoutSeconds) {
// implementing conversation manager
public Conversation beginConversation(ConversationParameters conversationParameters) throws ConversationException {
- return getConversationContainer().createConversation(conversationParameters, createConversationLock());
+ ConversationLock lock = new JdkConcurrentConversationLock(lockTimeoutSeconds);
+ return getConversationContainer().createConversation(conversationParameters, lock);
}
public Conversation getConversation(ConversationId id) throws ConversationException {
@@ -126,10 +127,6 @@ public ConversationId parseConversationId(String encodedId) throws ConversationE
// hooks for subclassing
- protected ConversationLock createConversationLock() {
- return new JdkConcurrentConversationLock(lockTimeoutSeconds);
- }
-
protected ConversationContainer createConversationContainer() {
return new ConversationContainer(maxConversations, sessionKey);
}
@@ -102,30 +102,25 @@ protected Model merge(Model child, Model parent) {
parent = new LinkedList<T>(parent);
Collections.reverse(parent);
}
- for (T element : parent) {
- if (!mergeElement(child, element)) {
- addElement(child, element, addAtEnd);
- }
+ for (T parentModel : parent) {
+ addOrMerge(child, parentModel, addAtEnd);
}
return child;
}
- private <T extends Model> boolean mergeElement(LinkedList<T> child, T element) {
- for (T childElement : child) {
- if (childElement.isMergeableWith(element)) {
- childElement.merge(element);
- return true;
+ private <T extends Model> void addOrMerge(LinkedList<T> list, T modelToMerge, boolean addAtEnd) {
+ for (T model : list) {
+ if (model.isMergeableWith(modelToMerge)) {
+ model.merge(modelToMerge);
+ return;
}
}
- return false;
- }
-
- @SuppressWarnings("unchecked")
- private <T extends Model> void addElement(LinkedList<T> child, T element, boolean addAtEnd) {
+ @SuppressWarnings("unchecked")
+ T copy = (T) modelToMerge.createCopy();
if (addAtEnd) {
- child.addLast((T) element.createCopy());
+ list.addLast(copy);
} else {
- child.addFirst((T) element.createCopy());
+ list.addFirst(copy);
}
}

0 comments on commit 22289e4

Please sign in to comment.