# NegationNode

Artifact: [androidx.appsearch:appsearch](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/ast/NegationNode.java+class:androidx.appsearch.ast.NegationNode) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

*** ** * ** ***


```
@ExperimentalAppSearchApi
public final class NegationNode implements Node
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/androidx/appsearch/ast/Node` that stores a child node to be logically negated with a negative sign ("-") or 'NOT'.

The child node stored in this node will be negated in a query search, which means search will return all documents that do not match the sub-expression represented by the child node. For example, if the child node is a `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` containing "foo", the resulting node will be treated as the query \`-foo\` or alternatively \`NOT foo\`.

This node should correspond to \`(NOT WS \| MINUS) simple\` in [Google AIP EBNF Filtering Definition](https://google.aip.dev/assets/misc/ebnf-filtering.txt).

This API may change in response to feedback and additional changes.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode#NegationNode(androidx.appsearch.ast.Node)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/ast/Node childNode)` Constructor for a `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode` that takes in a child node of any `https://developer.android.com/reference/androidx/appsearch/ast/Node` type. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object.html o)` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/ast/Node` | `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode#getChild()()` Retrieve the child node of this Node. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/appsearch/ast/Node>` | `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode#getChildren()()` Retrieve the child node of this Node as a list containing the only child node. |
| `int` | `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode#hashCode()()` |
| `void` | `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode#setChild(androidx.appsearch.ast.Node)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/ast/Node child)` Set the child node that the `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode` holds. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode#toString()()` Get the string representation of `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode`. |

## Public constructors

### NegationNode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public NegationNode(@NonNull Node childNode)
```

Constructor for a `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode` that takes in a child node of any `https://developer.android.com/reference/androidx/appsearch/ast/Node` type.

The resulting NegationNode represents the logical negation of its child node. For example if the child node represents \`foo AND bar\` then the resulting NegationNode represents \`-(foo AND bar)\` or alternatively \`NOT (foo AND bar)\`

This constructor is NOT a copy constructor. Passing in a `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode` will make that `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode` a child of another `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode`, NOT a new `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode` with the same child as the original `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/ast/Node childNode` | The `https://developer.android.com/reference/androidx/appsearch/ast/Node` representing some query to be logically negated. |

## Public methods

### equals

```
public boolean equals(Object o)
```

### getChild

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public @NonNull Node getChild()
```

Retrieve the child node of this Node.

This method will return the child node as a `https://developer.android.com/reference/androidx/appsearch/ast/Node` but could be of any type that implements `https://developer.android.com/reference/androidx/appsearch/ast/Node`. The caller should check what type the child node is and cast it to that type accordingly.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/ast/Node` | The child `https://developer.android.com/reference/androidx/appsearch/ast/Node` representing a query that is being logically negated that could be cast to a type that implements `https://developer.android.com/reference/androidx/appsearch/ast/Node` |

### getChildren

```
public @NonNull List<Node> getChildren()
```

Retrieve the child node of this Node as a list containing the only child node.

This method will return the child node as a List of size one containing a `https://developer.android.com/reference/androidx/appsearch/ast/Node` but could be of any type that implements `https://developer.android.com/reference/androidx/appsearch/ast/Node`. The caller should check what type the child node is and cast it to that type accordingly.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/appsearch/ast/Node>` | A list of size one containing a child `https://developer.android.com/reference/androidx/appsearch/ast/Node` representing a query that is being logically negated that could be cast to a type that implements `https://developer.android.com/reference/androidx/appsearch/ast/Node` |

### hashCode

```
public int hashCode()
```

### setChild

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public void setChild(@NonNull Node child)
```

Set the child node that the `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode` holds.

The node will be treated such that search will return everything not matching the term contained in the child.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/ast/Node child` | The child node that `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode` will hold. |

### toString

```
public @NonNull String toString()
```

Get the string representation of `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode`.

The string representation of `https://developer.android.com/reference/androidx/appsearch/ast/NegationNode` is "NOT" prepended to the string representation of the child `https://developer.android.com/reference/androidx/appsearch/ast/Node`.