Replace OptionalPath.valid flag by checking the path itself.
Test: m nothing
Change-Id: Iaf7655e4676d2beeb7c7ac3bcba11a7dad4a01a3
diff --git a/android/paths.go b/android/paths.go
index 763cd7c..5eeb6e5 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -263,27 +263,23 @@
// OptionalPath is a container that may or may not contain a valid Path.
type OptionalPath struct {
- valid bool
- path Path
+ path Path // nil if invalid.
}
// OptionalPathForPath returns an OptionalPath containing the path.
func OptionalPathForPath(path Path) OptionalPath {
- if path == nil {
- return OptionalPath{}
- }
- return OptionalPath{valid: true, path: path}
+ return OptionalPath{path: path}
}
// Valid returns whether there is a valid path
func (p OptionalPath) Valid() bool {
- return p.valid
+ return p.path != nil
}
// Path returns the Path embedded in this OptionalPath. You must be sure that
// there is a valid path, since this method will panic if there is not.
func (p OptionalPath) Path() Path {
- if !p.valid {
+ if p.path == nil {
panic("Requesting an invalid path")
}
return p.path
@@ -294,7 +290,7 @@
// It returns nil if this is not valid, or a single length slice containing the Path embedded in
// this OptionalPath.
func (p OptionalPath) AsPaths() Paths {
- if !p.valid {
+ if p.path == nil {
return nil
}
return Paths{p.path}
@@ -303,7 +299,7 @@
// RelativeToTop returns an OptionalPath with the path that was embedded having been replaced by the
// result of calling Path.RelativeToTop on it.
func (p OptionalPath) RelativeToTop() OptionalPath {
- if !p.valid {
+ if p.path == nil {
return p
}
p.path = p.path.RelativeToTop()
@@ -312,7 +308,7 @@
// String returns the string version of the Path, or "" if it isn't valid.
func (p OptionalPath) String() string {
- if p.valid {
+ if p.path != nil {
return p.path.String()
} else {
return ""