Cleanup use of Guava library
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / ResourceYangTextSchemaSource.java
1 /*
2  * Copyright (c) 2014 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.yangtools.yang.model.repo.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.net.URL;
16 import java.util.Optional;
17 import org.opendaylight.yangtools.concepts.Delegator;
18
19 /**
20  * A resource-backed {@link YinTextSchemaSource}.
21  */
22 final class ResourceYangTextSchemaSource extends YangTextSchemaSource implements Delegator<URL> {
23     private final URL url;
24
25     ResourceYangTextSchemaSource(final SourceIdentifier identifier, final URL url) {
26         super(identifier);
27         this.url = requireNonNull(url);
28     }
29
30     @Override
31     public URL getDelegate() {
32         return url;
33     }
34
35     @Override
36     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
37         return toStringHelper.add("url", url);
38     }
39
40     @Override
41     public InputStream openStream() throws IOException {
42         return url.openStream();
43     }
44
45     @Override
46     public Optional<String> getSymbolicName() {
47         return Optional.of(url.toString());
48     }
49 }