-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clear up Name and Id parameters (#3810)
- Loading branch information
Showing
25 changed files
with
213 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace Elasticsearch.Net | ||
{ | ||
public interface IUrlParameter | ||
|
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
src/Nest/CommonAbstractions/Infer/CategoryId/CategoryId.cs
This file was deleted.
Oops, something went wrong.
61 changes: 0 additions & 61 deletions
61
src/Nest/CommonAbstractions/Infer/ForecastIds/ForecastIds.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using Elasticsearch.Net; | ||
|
||
namespace Nest | ||
{ | ||
[DebuggerDisplay("{DebugDisplay,nq}")] | ||
public class Ids : IUrlParameter, IEquatable<Ids> | ||
{ | ||
private readonly List<string> _ids; | ||
|
||
public Ids(IEnumerable<string> value) => _ids = value?.ToList(); | ||
|
||
public Ids(string value) | ||
{ | ||
if (!value.IsNullOrEmptyCommaSeparatedList(out var arr)) | ||
_ids = arr.ToList(); | ||
} | ||
|
||
private string DebugDisplay => ((IUrlParameter)this).GetString(null); | ||
|
||
public bool Equals(Ids other) | ||
{ | ||
if (other == null) return false; | ||
if (_ids == null && other._ids == null) return true; | ||
if (_ids == null || other._ids == null) return false; | ||
|
||
return _ids.Count == other._ids.Count && | ||
_ids.OrderBy(id => id).SequenceEqual(other._ids.OrderBy(id => id)); | ||
} | ||
|
||
string IUrlParameter.GetString(IConnectionConfigurationValues settings) => | ||
string.Join(",", _ids ?? Enumerable.Empty<string>()); | ||
|
||
public static implicit operator Ids(string value) => | ||
value.IsNullOrEmptyCommaSeparatedList(out var arr) ? null : new Ids(arr); | ||
|
||
public static implicit operator Ids(string[] value) => | ||
value.IsEmpty() ? null : new Ids(value); | ||
|
||
public override bool Equals(object obj) => obj is Ids other && Equals(other); | ||
|
||
public override int GetHashCode() | ||
{ | ||
if (_ids == null) return 0; | ||
unchecked | ||
{ | ||
var hc = 0; | ||
foreach (var id in _ids.OrderBy(id => id)) | ||
hc = hc * 17 + id.GetHashCode(); | ||
return hc; | ||
} | ||
} | ||
|
||
public static bool operator ==(Ids left, Ids right) => Equals(left, right); | ||
|
||
public static bool operator !=(Ids left, Ids right) => !Equals(left, right); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Globalization; | ||
using Elasticsearch.Net; | ||
|
||
namespace Nest | ||
{ | ||
public class LongId : IUrlParameter, IEquatable<LongId> | ||
{ | ||
internal readonly long Value; | ||
|
||
public LongId(long value) => Value = value; | ||
|
||
public bool Equals(LongId other) => Value == other.Value; | ||
|
||
// ReSharper disable once ImpureMethodCallOnReadonlyValueField | ||
public string GetString(IConnectionConfigurationValues settings) => Value.ToString(CultureInfo.InvariantCulture); | ||
|
||
public static implicit operator LongId(long value) => new LongId(value); | ||
|
||
public static implicit operator long(LongId value) => value.Value; | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
switch (obj) | ||
{ | ||
case int l: return Value == l; | ||
case long l: return Value == l; | ||
case LongId i: return Value == i.Value; | ||
default: return false; | ||
} | ||
} | ||
|
||
public override int GetHashCode() => Value.GetHashCode(); | ||
|
||
public static bool operator ==(LongId left, LongId right) => Equals(left, right); | ||
|
||
public static bool operator !=(LongId left, LongId right) => !Equals(left, right); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.