# PropertyPath

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

*** ** * ** ***


```
public class PropertyPath implements Iterable<PropertyPath.PathSegment>
```

<br />

*** ** * ** ***

Represents a property path returned from searching the AppSearch Database.

One of the use cases for this class is when searching the AppSearch Database for the snippet matching use case. In this case you will get back `https://developer.android.com/reference/androidx/appsearch/app/SearchResult.MatchInfo` objects that contain a property path signifying the location of a match within the database. This is a string that may look something like "foo.bar\[0\]". `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath` parses this string and breaks it up into a List of `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath.PathSegment`s. These may represent either a property or a property and a 0-based index into the property. For instance, "foo.bar\[1\]" would be parsed into a `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath.PathSegment` with a property name of foo and a `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath.PathSegment` with a property name of bar and an index of 1. This allows for easier manipulation of the property path.

This class won't perform any retrievals, it will only parse the path string. As such, it may not necessarily refer to a valid path in the database.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/app/SearchResult.MatchInfo` |   |

## Summary

| ### Nested types |
|---|
| `public class https://developer.android.com/reference/androidx/appsearch/app/PropertyPath.PathSegment` A segment of a PropertyPath, which includes the name of the property and a 0-based index into this property. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath#PropertyPath(java.util.List<androidx.appsearch.app.PropertyPath.PathSegment>)(@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/app/PropertyPath.PathSegment> pathList)` Constructor directly accepting a path list |
| `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath#PropertyPath(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html path)` Constructor that parses a string representing the path to populate a List of PathSegments |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath#equals(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html 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/app/PropertyPath.PathSegment` | `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath#get(int)(int index)` Returns the `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath.PathSegment` at a specified index of the PropertyPath. |
| `int` | `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath#hashCode()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Iterator.html<https://developer.android.com/reference/androidx/appsearch/app/PropertyPath.PathSegment>` | `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath#iterator()()` Returns an iterator over the PathSegments within the PropertyPath |
| `int` | `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath#size()()` Returns the number of `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath.PathSegment`s in the PropertyPath. |
| `@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/app/PropertyPath#toString()()` Returns a valid path string representing this PropertyPath |

### Inherited methods

From [java.lang.Iterable](https://developer.android.com/reference/java/lang/Iterable.html) `void` `https://developer.android.com/reference/java/lang/Iterable.html#forEach(java.util.function.Consumer&lt;? super T&gt;)(https://developer.android.com/reference/java/util/function/Consumer.html<T> action)` `https://developer.android.com/reference/java/util/Spliterator.html<T>` `https://developer.android.com/reference/java/lang/Iterable.html#spliterator()()`

## Public constructors

### PropertyPath

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

```
public PropertyPath(@NonNull List<PropertyPath.PathSegment> pathList)
```

Constructor directly accepting a path list

| Parameters |
|---|---|
| `@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/app/PropertyPath.PathSegment> pathList` | a list of PathSegments |

### PropertyPath

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

```
public PropertyPath(@NonNull String path)
```

Constructor that parses a string representing the path to populate a List of PathSegments

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html path` | the string to be validated and parsed into PathSegments |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | when the path is invalid or malformed |

## Public methods

### equals

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

### get

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

```
public @NonNull PropertyPath.PathSegment get(int index)
```

Returns the `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath.PathSegment` at a specified index of the PropertyPath.

Calling `get(1)` on a `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath` representing "foo.bar\[1\]" will return a `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath.PathSegment` representing "bar\[1\]". `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath.PathSegment`s both with and without a property index of `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath.PathSegment#NON_REPEATED_CARDINALITY()` are retrieved the same.

| Parameters |
|---|---|
| `int index` | the position into the PropertyPath |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/ArrayIndexOutOfBoundsException.html` | if index is not a valid index in the path list |

### hashCode

```
public int hashCode()
```

### iterator

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

```
public @NonNull Iterator<PropertyPath.PathSegment> iterator()
```

Returns an iterator over the PathSegments within the PropertyPath

### size

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

```
public int size()
```

Returns the number of `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath.PathSegment`s in the PropertyPath.

Paths representing "foo.bar" and "foo\[1\].bar\[1\]" will have the same size, as a property and an index into that property are stored in one `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath.PathSegment`.

### toString

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

Returns a valid path string representing this PropertyPath