public virtual void Compute() { this.Schedule = new List <PointInTimeAmount>(); var hasPayments = Payments.Count() > 0; var currentMonth = new DateTime(Mortgage.StartDate.Year, Mortgage.StartDate.Month, 1); var finalMonth = currentMonth.AddMonths(Mortgage.TermInMonths); var balanceLeft = Mortgage.Principal; while (balanceLeft > 0 && currentMonth < finalMonth) { var monthlyInterest = balanceLeft * Mortgage.MonthlyRate; var monthlyPrincipal = Mortgage.MonthlyAmount - monthlyInterest; var supplement = 0.0; if (hasPayments) { supplement = Payments.Where(p => Rules.All(r => r.CanApply())) .Select(p => p.Amount) .Sum(); } var adjustedBalance = balanceLeft - (monthlyPrincipal + supplement); balanceLeft = Math.Max(0, adjustedBalance); this.Schedule.Add(new PointInTimeAmount { ScheduledFor = currentMonth, Amount = balanceLeft }); currentMonth = currentMonth.AddMonths(1); } }
/// <summary> /// 添加规则 /// </summary> public virtual void AddRule(IReqRule rule) { if (Rules.All(m => !m.Equals(rule))) { Rules.Add(rule); } }
public bool IsValidFor(IEnumerable <FieldWithValue> allCollectedFieldValues, IPublishedContent content) { // swap the rule fields for the actual fields collected by the form model foreach (var rule in Rules) { if (rule.Field == null) { // should not happen! continue; } var collectedField = allCollectedFieldValues.FirstOrDefault(f => f.Name == rule.Field.Name); if (collectedField != null) { rule.Field = collectedField; } } Invalid = Rules.Any(r => r.IsApplicable == false) // it's impossible to validate the rule if we have frontend only conditions in play ? false // the validation fails if all rules are fulfilled : Rules.All(r => r.IsFulfilledBy(allCollectedFieldValues, content)); return(Invalid == false); }
/// <summary> /// 添加规则 /// </summary> public void AddRule(FilterRule rule) { if (Rules.All(m => !m.Equals(rule))) { Rules.Add(rule); } }
public bool RulesMatch(Error instance) { if (Rules != null && Rules.All(r => r.IsMatch(instance))) { return(true); } return(false); }
/// <summary> /// 添加规则 /// </summary> public FilterGroup AddRule(FilterRule rule) { if (Rules.All(m => !m.Equals(rule))) { Rules.Add(rule); } return(this); }
public bool Handle(Move move, Board board) { if (move.PieceType == Type) { return(Rules.All(rule => rule.IsMoveValid(move, board))); } if (Next != null) { return(Next.Handle(move, board)); } throw new Exception("NOBODY TREATS THIS PIECE !!! " + move.PieceType); }
protected override object SolvePartTwo() { int count = 0; foreach (var passport in _passports) { if (Rules.All(rule => passport.ContainsKey(rule.Key) && rule.Validate(passport[rule.Key]))) { count++; } } return(count.ToString()); }
public void AddRule(string propertyName, RuleType ruleType) { var propertiesWithDuplicatesAllowed = new HashSet <ItemProperty> { ItemProperty.ElementalDamage, ItemProperty.SkillDamage }; Func <ItemProperty, bool> allowedToAdd = p => Rules.All(r => r.ItemProperty != p) || propertiesWithDuplicatesAllowed.Contains(p); ItemProperty property; Core.Logger.Log("Attempting to Add {0} Type={1}", propertyName, ruleType); if (!Enum.TryParse(propertyName, out property)) { return; } var allowed = allowedToAdd(property); if (property != ItemProperty.Unknown && allowed) { var id = (int)property; var statRange = GetItemStatRange(property); if (statRange != null) { Core.Logger.Verbose($"Stats Min = {statRange.AbsMin} Max = {statRange.AbsMax} Step = {statRange.AbsStep}"); } Rules.Add(new LRule { Id = id, ItemStatRange = statRange, ItemReference = ItemReference, TrinityItemType = TrinityItemType, RuleType = ruleType, Value = LRule.GetDefaultValue(property) }); OnPropertyChanged(nameof(Rules)); OnPropertyChanged(ruleType + "Rules"); } else { if (!allowed) { Core.Logger.Log("{0} has already been added and duplicates are not allowed", propertyName); } } }
public bool IsMatch(IResourceInfo resource) { if ((Rules?.Length ?? 0) <= 0) { return(false); } var target = Source == FilterSource.Name ? resource.Title : resource.Hash; if (IsRegex) { return(CompiledRegex?.All(s => s.IsMatch(target)) == true); } return(Rules.All(s => target.IndexOf(s, StringComparison.OrdinalIgnoreCase) != -1)); }
/// <summary> /// Tries to match all rules against a collection of argument values /// </summary> /// <param name="argsCollection">collection of argument values</param> /// <returns></returns> public bool Match(IEnumerable <CommandArgValue> argsCollection) { if (argsCollection == null) { return(false); } //must match first if (!Command.Match(argsCollection.FirstOrDefault())) { return(false); } //match other arguments in any position foreach (var arg in argsCollection.Skip(1)) { //try to match any no-matched rule with any argument in any position after first command if (!Rules.Where(rule => !rule.Matched).Any(rule => rule.Match(arg))) { return(false); } } //here we must have all rules matched return(Rules.All(rule => rule.Matched)); }
public void AddRule(string propertyName, RuleType ruleType) { var propertiesWithDuplicatesAllowed = new HashSet <ItemProperty> { ItemProperty.ElementalDamage, ItemProperty.SkillDamage }; Func <ItemProperty, bool> allowedToAdd = p => Rules.All(r => r.ItemProperty != p) || propertiesWithDuplicatesAllowed.Contains(p); ItemProperty property; Logger.Log("Attempting to Add {0} Type={1}", propertyName, ruleType); if (Enum.TryParse(propertyName, out property) && property != ItemProperty.Unknown && allowedToAdd(property)) { var statRange = GetItemStatRange(property); if (statRange != null) { Logger.LogVerbose(string.Format("Stats Min = {0} Max = {1} Step = {2}", statRange.AbsMin.ToString(), statRange.AbsMax.ToString(), statRange.AbsStep.ToString())); } Rules.Add(new LRule { Id = (int)property, ItemStatRange = statRange, TrinityItemType = TrinityItemType, RuleType = ruleType, Value = LRule.GetDefaultValue(property) }); OnPropertyChanged("Rules"); OnPropertyChanged(ruleType + "Rules"); } }
internal bool IsValid() { return(!string.IsNullOrWhiteSpace(Title) && !string.IsNullOrWhiteSpace(TitleTranslated) && EnumerableValidator.IsNotEmpty(Rules) && Rules.All(e => e.IsValid())); }
public override bool IsMatch(DateTime day) { return(Rules.All(r => r.IsMatch(day))); }
public bool IsValid(int input) { return(Rules.All(i => !i.IsValid(input))); }
public override bool ShouldImport(LogEntry logEntry) => Rules.All(rule => rule.ShouldImport(logEntry));
public override bool IsValid() { return(Rules.All(rule => rule.Passed(this))); }
public bool IsSatisfiedBy(ClaimsPrincipal principal) { return(Operator == RuleSetOperator.Or ? Rules.Any(r => r.IsSatisfiedBy(principal)) : Rules.All(r => r.IsSatisfiedBy(principal))); }
protected override bool InternalMatch(ParserState p) { return(Rules.All(r => r.Match(p))); }
public void Solve1() { var sum = NearbyTickets.SelectMany(t => t.Numbers.Where(n => Rules.All(r => !r.IsValid(n)))).Sum(); Console.WriteLine(sum); }
public bool Eval(T t) { return(IsTrue = Rules.All(x => x.Eval(t))); }
private bool CheckDirectRules(string stringToCheck) { return(Rules.All(x => x.ConformsToRule(stringToCheck))); }
private bool IsMatchRules(BaseItem item, User user) { return(Rules.All(x => x.IsMatch(new UserItem(user, item)))); }