Mass-migrate to java.util.Optional
[mdsal.git] / dom / mdsal-dom-spi / src / main / java / org / opendaylight / mdsal / dom / spi / SimpleDOMMountPoint.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.dom.spi;
9
10 import com.google.common.collect.ClassToInstanceMap;
11 import com.google.common.collect.ImmutableClassToInstanceMap;
12 import java.util.Optional;
13 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
14 import org.opendaylight.mdsal.dom.api.DOMService;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17
18 public final class SimpleDOMMountPoint implements DOMMountPoint {
19
20     private final YangInstanceIdentifier identifier;
21     private final ClassToInstanceMap<DOMService> services;
22     private final SchemaContext schemaContext;
23
24     private SimpleDOMMountPoint(final YangInstanceIdentifier identifier,
25             final ClassToInstanceMap<DOMService> services, final SchemaContext ctx) {
26         this.identifier = identifier;
27         this.services = ImmutableClassToInstanceMap.copyOf(services);
28         this.schemaContext = ctx;
29     }
30
31     public static SimpleDOMMountPoint create(final YangInstanceIdentifier identifier,
32             final ClassToInstanceMap<DOMService> services, final SchemaContext ctx) {
33         return new SimpleDOMMountPoint(identifier, services, ctx);
34     }
35
36     @Override
37     public YangInstanceIdentifier getIdentifier() {
38         return identifier;
39     }
40
41     @Override
42     public SchemaContext getSchemaContext() {
43         return schemaContext;
44     }
45
46     @Override
47     public <T extends DOMService> Optional<T> getService(final Class<T> cls) {
48         return Optional.ofNullable(services.getInstance(cls));
49     }
50 }