diff options
author | Pierre-Charles David | 2021-03-12 08:32:03 +0000 |
---|---|---|
committer | Laurent Fasani | 2021-04-16 07:14:21 +0000 |
commit | e8511048850caa495eb4dcc4f640a2f5fa346d5b (patch) | |
tree | 91851d57517c51abbe4d56edbe444feb7056897c | |
parent | 4b3d140fd4ee0568b2a5a69479993d782c32d4d4 (diff) | |
download | org.eclipse.sirius-e8511048850caa495eb4dcc4f640a2f5fa346d5b.tar.gz org.eclipse.sirius-e8511048850caa495eb4dcc4f640a2f5fa346d5b.tar.xz org.eclipse.sirius-e8511048850caa495eb4dcc4f640a2f5fa346d5b.zip |
[cleanup] Remove Guava & Option usage in SessionTransientAttachment
Change-Id: If0436aad093ea36b86b4bdfffa317ec6a256eee3
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
2 files changed, 12 insertions, 20 deletions
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionManagerImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionManagerImpl.java index 4ec666509a..a08f28696c 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionManagerImpl.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionManagerImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2020 THALES GLOBAL SERVICES. + * Copyright (c) 2008, 2021 THALES GLOBAL SERVICES. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -206,8 +206,8 @@ public class SessionManagerImpl extends SessionManagerEObjectImpl implements Ses } // Handle explicit SessionTransientAttachment if (found == null) { - Option<SessionTransientAttachment> attachment = SessionTransientAttachment.getSessionTransientAttachement(any); - if (attachment.some()) { + Optional<SessionTransientAttachment> attachment = SessionTransientAttachment.of(any); + if (attachment.isPresent()) { found = attachment.get().getSession(); } } @@ -240,9 +240,9 @@ public class SessionManagerImpl extends SessionManagerEObjectImpl implements Ses @Override public Session getSession(final Resource semanticResource) { Session found = null; - Option<SessionTransientAttachment> attachment = SessionTransientAttachment.getSessionTransientAttachement(semanticResource); + Optional<SessionTransientAttachment> attachment = SessionTransientAttachment.of(semanticResource); - if (attachment.some()) { + if (attachment.isPresent()) { found = attachment.get().getSession(); } if (found == null) { diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionTransientAttachment.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionTransientAttachment.java index 8fa9d38462..568f3fc33d 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionTransientAttachment.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionTransientAttachment.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2021 THALES GLOBAL SERVICES. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,16 +12,12 @@ *******************************************************************************/ package org.eclipse.sirius.business.internal.session; -import java.util.Iterator; +import java.util.Objects; +import java.util.Optional; import org.eclipse.emf.common.notify.Notifier; import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.sirius.business.api.session.Session; -import org.eclipse.sirius.ext.base.Option; -import org.eclipse.sirius.ext.base.Options; - -import com.google.common.collect.Iterators; -import com.google.common.collect.Sets; /** * This adapter might be used as a marker to retrieve a {@link Session} from any @@ -40,7 +36,7 @@ import com.google.common.collect.Sets; */ public class SessionTransientAttachment extends AdapterImpl { - private Session session; + private final Session session; /** * Create a new session attachment. @@ -49,7 +45,7 @@ public class SessionTransientAttachment extends AdapterImpl { * the session to attach. */ public SessionTransientAttachment(Session session) { - this.session = session; + this.session = Objects.requireNonNull(session); } /** @@ -70,12 +66,8 @@ public class SessionTransientAttachment extends AdapterImpl { * the instance to inspect. * @return an optional SessionTransientAttachment. */ - public static Option<SessionTransientAttachment> getSessionTransientAttachement(Notifier eObj) { - Iterator<SessionTransientAttachment> it = Iterators.filter(Sets.newLinkedHashSet(eObj.eAdapters()).iterator(), SessionTransientAttachment.class); - if (it.hasNext()) { - return Options.newSome(it.next()); - } - return Options.newNone(); + public static Optional<SessionTransientAttachment> of(Notifier eObj) { + return eObj.eAdapters().stream().filter(SessionTransientAttachment.class::isInstance).map(SessionTransientAttachment.class::cast).findFirst(); } } |