Skip to content

Package: BazaarVariant

BazaarVariant

nameinstructionbranchcomplexitylinemethod
builder()
M: 11 C: 10
48%
M: 1 C: 2
67%
M: 1 C: 2
67%
M: 1 C: 3
75%
M: 0 C: 1
100%
builder(Collection)
M: 11 C: 12
52%
M: 1 C: 2
67%
M: 1 C: 2
67%
M: 1 C: 3
75%
M: 0 C: 1
100%
createBazaarImpl()
M: 11 C: 13
54%
M: 1 C: 2
67%
M: 1 C: 2
67%
M: 1 C: 3
75%
M: 0 C: 1
100%
static {...}
M: 0 C: 24
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
toString()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2018 Christian W. Damus 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: * Christian W. Damus - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.bazaar.internal;
15:
16: import java.util.Collection;
17:
18: import org.eclipse.emfforms.bazaar.Bazaar;
19: import org.eclipse.emfforms.bazaar.Vendor;
20:
21: /**
22: * Enumeration of {@link Bazaar} variants, especially for creation of
23: * test subjects.
24: *
25: * @author Christian W. Damus
26: */
27: public enum BazaarVariant {
28:         /** The base implementation. */
29:         BASE,
30:         /** The thread-safe implementation. */
31:         THREAD_SAFE;
32:
33:         /**
34:          * Create an internal bazaar implementation to test.
35:          *
36:          * @return the bazaar implementation
37:          *
38:          * @throws IllegalArgumentException if my variant is not a kind of {@link BazaarImpl}
39:          * but some other kind of {@link Bazaar}
40:          */
41:         public <T> BazaarImpl<T> createBazaarImpl() {
42:•                switch (this) {
43:                 case BASE:
44:                         return new BazaarImpl<T>();
45:                 case THREAD_SAFE:
46:                         return new ThreadSafeBazaar<T>();
47:                 default:
48:                         throw new IllegalArgumentException("no such BazaarImpl: " + this); //$NON-NLS-1$
49:                 }
50:         }
51:
52:         /**
53:          * Create a bazaar builder to test.
54:          *
55:          * @return the bazaar builder
56:          */
57:         public <T> Bazaar.Builder<T> builder() {
58:•                switch (this) {
59:                 case BASE:
60:                         return Bazaar.Builder.empty();
61:                 case THREAD_SAFE:
62:                         return Bazaar.Builder.<T> empty().threadSafe();
63:                 default:
64:                         throw new IllegalArgumentException("no such builder: " + this); //$NON-NLS-1$
65:                 }
66:         }
67:
68:         /**
69:          * Create a bazaar builder to test, with initial vendors.
70:          *
71:          * @return the bazaar builder
72:          */
73:         public <T> Bazaar.Builder<T> builder(Collection<? extends Vendor<? extends T>> vendors) {
74:•                switch (this) {
75:                 case BASE:
76:                         return Bazaar.Builder.with(vendors);
77:                 case THREAD_SAFE:
78:                         return Bazaar.Builder.with(vendors).threadSafe();
79:                 default:
80:                         throw new IllegalArgumentException("no such builder: " + this); //$NON-NLS-1$
81:                 }
82:         }
83:
84:         @Override
85:         public String toString() {
86:                 return name().toLowerCase().replace('_', '-');
87:         }
88: }