/// <summary> /// Finds the maximum number '<c>k</c>' within a given integer interval such that a predicate /// holds for this number '<c>k</c>'. /// </summary> /// <typeparam name="T">The type of numbers contained inside the interval.</typeparam> /// <typeparam name="C">A calculator for the <typeparamref name="T"/> type.</typeparam> /// <param name="interval"> /// An integer interval, containing at least one number for which the <paramref name="predicate"/> /// holds. /// </param> /// <param name="predicate"> /// A predicate that should hold for the desired number and not for every number that is bigger and located /// inside the interval. /// </param> /// <remarks> /// This method takes <c>O(n)</c> time for intervals of length '<c>n</c>'. Thus, it usually works significantly /// slower than <see cref="Max_BinarySearch<T,C>"/>, but does not put any restrictions /// on the <paramref name="interval"/> object passed. /// </remarks> /// <returns> /// A <c>PotentialResult<Numeric<T, C>></c> object which will store /// the maximum number within a given interval for which the <paramref name="predicate"/> holds, if the algorithm /// finds one. /// </returns> public static PotentialResult <Numeric <T, C> > Max_LinearSearch <T, C>(this BoundedInterval <T, C> interval, Predicate <T> predicate) where C : ICalc <T>, new() { Contract.Requires <ArgumentException>(Numeric <T, C> .Calculator.isIntegerCalculator, "This method works only for integer numbers."); Contract.Requires <ArgumentNullException>(predicate != null, "predicate"); Contract.Requires <ArgumentException>(!interval.IsEmptyInteger, "The interval should contain at least one integer point."); BoundedInterval <T, C> inclusive = interval.ToInclusiveIntegerInterval(); bool found = false; Numeric <T, C> max = Numeric <T, C> .Zero; for (Numeric <T, C> current = inclusive.LeftBound; current <= inclusive.RightBound; ++current) { if (predicate(current)) { found = true; max = current; } } if (!found) { return(PotentialResult <Numeric <T, C> > .CreateFailure()); } else { return(PotentialResult <Numeric <T, C> > .CreateSuccess(max)); } }
public async Task <bool> Delete(PotentialResult PotentialResult) { if (await ValidateId(PotentialResult)) { } return(PotentialResult.IsValidated); }
public Opportunity_PotentialResultDTO(PotentialResult PotentialResult) { this.Id = PotentialResult.Id; this.Code = PotentialResult.Code; this.Name = PotentialResult.Name; this.Errors = PotentialResult.Errors; }
public Contract_PotentialResultDTO(PotentialResult PotentialResult) { this.Id = PotentialResult.Id; this.Code = PotentialResult.Code; this.Name = PotentialResult.Name; this.Errors = PotentialResult.Errors; }
public async Task <PotentialResult> Get(long Id) { PotentialResult PotentialResult = await UOW.PotentialResultRepository.Get(Id); if (PotentialResult == null) { return(null); } return(PotentialResult); }
public async Task <PotentialResult> Get(long Id) { PotentialResult PotentialResult = await DataContext.PotentialResult.AsNoTracking() .Where(x => x.Id == Id) .Select(x => new PotentialResult() { Id = x.Id, Code = x.Code, Name = x.Name, }).FirstOrDefaultAsync(); if (PotentialResult == null) { return(null); } return(PotentialResult); }
public async Task <bool> ValidateId(PotentialResult PotentialResult) { PotentialResultFilter PotentialResultFilter = new PotentialResultFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = PotentialResult.Id }, Selects = PotentialResultSelect.Id }; int count = await UOW.PotentialResultRepository.Count(PotentialResultFilter); if (count == 0) { PotentialResult.AddError(nameof(PotentialResultValidator), nameof(PotentialResult.Id), ErrorCode.IdNotExisted); } return(count == 1); }
public async Task <bool> Create(PotentialResult PotentialResult) { return(PotentialResult.IsValidated); }