(other JSON)
| 721 | } |
| 722 | |
| 723 | func (j jsonArray) Compare(other JSON) (int, error) { |
| 724 | switch { |
| 725 | case isEmptyArray(j) && isEmptyArray(other): |
| 726 | return 0, nil |
| 727 | case isEmptyArray(j): |
| 728 | return -1, nil |
| 729 | case isEmptyArray(other): |
| 730 | return 1, nil |
| 731 | } |
| 732 | cmp := cmpJSONTypes(j.Type(), other.Type()) |
| 733 | if cmp != 0 { |
| 734 | return cmp, nil |
| 735 | } |
| 736 | lenJ := j.Len() |
| 737 | lenO := other.Len() |
| 738 | if lenJ < lenO { |
| 739 | return -1, nil |
| 740 | } |
| 741 | if lenJ > lenO { |
| 742 | return 1, nil |
| 743 | } |
| 744 | // TODO(justin): we should optimize this, we don't have to decode the whole thing. |
| 745 | var err error |
| 746 | if other, err = decodeIfNeeded(other); err != nil { |
| 747 | return 0, err |
| 748 | } |
| 749 | o := other.(jsonArray) |
| 750 | for i := 0; i < lenJ; i++ { |
| 751 | cmp, err := j[i].Compare(o[i]) |
| 752 | if err != nil { |
| 753 | return 0, err |
| 754 | } |
| 755 | if cmp != 0 { |
| 756 | return cmp, nil |
| 757 | } |
| 758 | } |
| 759 | return 0, nil |
| 760 | } |
| 761 | |
| 762 | func (j jsonObject) Compare(other JSON) (int, error) { |
| 763 | // NOTE: There is no need to check if other is an empty array because all |
nothing calls this directly
no test coverage detected