Skip to content

Package: MultiSegmentUtil

MultiSegmentUtil

nameinstructionbranchcomplexitylinemethod
getMultiSegment(VDomainModelReference)
M: 0 C: 25
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.view.spi.multisegment.model;
15:
16: import java.util.Optional;
17:
18: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
19: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReferenceSegment;
20:
21: /**
22: * Utility methods for dealing with {@link VMultiDomainModelReferenceSegment multi segments}.
23: *
24: * @author Lucas Koehler
25: *
26: */
27: public final class MultiSegmentUtil {
28:
29:         // This is a utility class that should not be instantiated
30:         private MultiSegmentUtil() {
31:         }
32:
33:         /**
34:          * Gets the last segment of the given {@link VDomainModelReference DMR} and casts it to a
35:          * {@link VMultiDomainModelReferenceSegment multi segment}.
36:          *
37:          * @param dmr The {@link VDomainModelReference} to extract the multi segment from
38:          * @return The multi segment, or nothing if the dmr's last segment is not a multi segment
39:          */
40:         public static Optional<VMultiDomainModelReferenceSegment> getMultiSegment(VDomainModelReference dmr) {
41:•                if (dmr != null && dmr.getSegments().size() > 0) {
42:                         final VDomainModelReferenceSegment lastSegment = dmr.getSegments().get(dmr.getSegments().size() - 1);
43:•                        if (lastSegment instanceof VMultiDomainModelReferenceSegment) {
44:                                 return Optional.of((VMultiDomainModelReferenceSegment) lastSegment);
45:                         }
46:                 }
47:                 return Optional.empty();
48:         }
49: }