2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.xpath.api;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.ImmutableList;
14 import java.util.Iterator;
15 import java.util.List;
16 import java.util.Objects;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.YangConstants;
22 * Function call invocation. Function names without a prefix are mapped into {@link YangConstants#RFC6020_YIN_MODULE},
23 * as they are required to be mapped into YANG as per RFC7950 definitions.
25 * @author Robert Varga
28 public sealed class YangFunctionCallExpr implements YangExpr {
29 private static final class WithArgs extends YangFunctionCallExpr {
30 private static final long serialVersionUID = 1L;
32 private final ImmutableList<YangExpr> arguments;
34 WithArgs(final QName name, final List<YangExpr> arguments) {
36 this.arguments = ImmutableList.copyOf(arguments);
40 public List<YangExpr> getArguments() {
45 private static final long serialVersionUID = 1L;
47 private final QName name;
49 private YangFunctionCallExpr(final QName name) {
50 this.name = requireNonNull(name);
53 public static YangFunctionCallExpr of(final QName name) {
54 return new YangFunctionCallExpr(name);
57 public static YangFunctionCallExpr of(final QName name, final YangExpr argument) {
58 return new WithArgs(name, ImmutableList.of(argument));
61 public static YangFunctionCallExpr of(final QName name, final List<YangExpr> arguments) {
62 return arguments.isEmpty() ? of(name) : new WithArgs(name, arguments);
65 public final QName getName() {
69 public List<YangExpr> getArguments() {
70 return ImmutableList.of();
74 public final int hashCode() {
75 return Objects.hash(getName(), getArguments());
79 public final boolean equals(final @Nullable Object obj) {
80 return this == obj || obj instanceof YangFunctionCallExpr other && getName().equals(other.getName())
81 && getArguments().equals(other.getArguments());
85 public final String toString() {
86 final StringBuilder sb = new StringBuilder().append(getName()).append('(');
87 final Iterator<YangExpr> it = getArguments().iterator();
90 while (it.hasNext()) {
91 sb.append(", ").append(it.next());
94 return sb.append(')').toString();