// LoneAnonymousOperationRule Lone anonymous operation
//
// A GraphQL document is only valid if when it contains an anonymous operation
// (the query short-hand) that it contains only that one operation definition.
329341
func LoneAnonymousOperationRule(context *ValidationContext) *ValidationRuleInstance {
	var operationCount = 0
	visitorOpts := &visitor.VisitorOptions{
		KindFuncMap: map[string]visitor.NamedVisitFuncs{
			kinds.Document: {
				Kind: func(p visitor.VisitFuncParams) (string, interface{}) {
					if node, ok := p.Node.(*ast.Document); ok {
						operationCount = 0
						for _, definition := range node.Definitions {
							if definition.GetKind() == kinds.OperationDefinition {
								operationCount++
							}
						}
					}
					return visitor.ActionNoChange, nil
				},
			},
			kinds.OperationDefinition: {
				Kind: func(p visitor.VisitFuncParams) (string, interface{}) {
					if node, ok := p.Node.(*ast.OperationDefinition); ok {
						if node.Name == nil && operationCount > 1 {
							reportError(
								context,
								`This anonymous operation must be the only defined operation.`,
								[]ast.Node{node},
							)
						}
					}
					return visitor.ActionNoChange, nil
				},
			},
		},
	}
	return &ValidationRuleInstance{
		VisitorOpts: visitorOpts,
	}
}
652271
func (e InvalidNonPrivateTLFOperation) Error() string {
	return fmt.Sprintf(
		"Tried to do invalid operation %s on non-private TLF %v (ver=%v)",
		e.opName, e.id, e.ver)
}
368844
func (lo *lo) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
	return locales.PluralRuleOther
}
367213
func (p *Policy) AllowNoAttrs() *attrPolicyBuilder {

	p.init()

	abp := attrPolicyBuilder{
		p:          p,
		allowEmpty: true,
	}
	return &abp
}
1093723
func (op *DestroyRelationOperation) internalDestroy() (ops []txn.Op, err error) {
	if len(op.r.doc.Endpoints) == 1 && op.r.doc.Endpoints[0].Role == charm.RolePeer {
		return nil, errors.Errorf("is a peer relation")
	}
	defer func() {
		if err == nil {
			// This is a white lie; the document might actually be removed.
			op.r.doc.Life = Dying
		}
	}()
	rel := &Relation{op.r.st, op.r.doc}

	remoteApp, isCrossModel, err := op.r.RemoteApplication()
	if err != nil {
		if !op.Force {
			return nil, errors.Trace(err)
		}
		op.AddError(err)
	} else {
		// If the status of the consumed app is terminated, we will never
		// get an orderly exit of units from scope so force the issue.
		if isCrossModel {
			statusInfo, err := remoteApp.Status()
			if err != nil && !errors.IsNotFound(err) {
				if !op.Force {
					return nil, errors.Trace(err)
				}
				op.AddError(err)
			}
			if err == nil && statusInfo.Status == status.Terminated {
				logger.Debugf("forcing cleanup of units for %v", remoteApp.Name())
				remoteUnits, err := rel.AllRemoteUnits(remoteApp.Name())
				if err != nil {
					if !op.Force {
						return nil, errors.Trace(err)
					}
					op.AddError(err)
				}
				logger.Debugf("got %v relation units to clean", len(remoteUnits))
				failRemoteUnits := false
				for _, ru := range remoteUnits {
					leaveScopeOps, err := ru.leaveScopeForcedOps(&op.ForcedOperation)
					if err != nil && err != jujutxn.ErrNoOperations {
						op.AddError(err)
						failRemoteUnits = true
					}
					ops = append(ops, leaveScopeOps...)
				}
				if !op.Force && failRemoteUnits {
					return nil, errors.Trace(op.LastError())
				}
			}
		}
	}

	// In this context, aborted transactions indicate that the number of units
	// in scope have changed between 0 and not-0. The chances of 5 successive
	// attempts each hitting this change -- which is itself an unlikely one --
	// are considered to be extremely small.
	// When 'force' is set, this call will return  needed operations
	// and accumulate all operational errors encountered in the operation.
	// If the 'force' is not set, any error will be fatal and no operations will be returned.
	destroyOps, _, err := rel.destroyOps("", &op.ForcedOperation)
	if err == errAlreadyDying {
		return nil, jujutxn.ErrNoOperations
	} else if err != nil {
		if !op.Force {
			return nil, err
		}
		op.AddError(err)
	}
	return append(ops, destroyOps...), nil
}
798148
func (yav *yav) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
	return locales.PluralRuleUnknown
}
1247762
func (zh *zh_Hans_MO) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
	return locales.PluralRuleOther
}
32151
func (dua *dua_CM) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
	return locales.PluralRuleUnknown
}
1023369
func (a *ACL) AllowOperatorWrite() bool {
	switch {
	case a.management:
		return true
	case a.operator == PolicyWrite:
		return true
	default:
		return false
	}
}
583866
func (guz *guz) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
	return locales.PluralRuleUnknown
}
122430
func (th *th) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
	return locales.PluralRuleOther
}
695828
func (s *Scheduler) noSuitableNode(ctx context.Context, taskGroup map[string]*api.Task, schedulingDecisions map[string]schedulingDecision) {
	explanation := s.pipeline.Explain()
	for _, t := range taskGroup {
		var service *api.Service
		s.store.View(func(tx store.ReadTx) {
			service = store.GetService(tx, t.ServiceID)
		})
		if service == nil {
			log.G(ctx).WithField("task.id", t.ID).Debug("removing task from the scheduler")
			continue
		}

		log.G(ctx).WithField("task.id", t.ID).Debug("no suitable node available for task")

		newT := *t
		newT.Status.Timestamp = ptypes.MustTimestampProto(time.Now())
		if explanation != "" {
			newT.Status.Err = "no suitable node (" + explanation + ")"
		} else {
			newT.Status.Err = "no suitable node"
		}
		s.allTasks[t.ID] = &newT
		schedulingDecisions[t.ID] = schedulingDecision{old: t, new: &newT}

		s.enqueue(&newT)
	}
}
388710
func (lrc *lrc) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
	return locales.PluralRuleUnknown
}
534057
func (fw *firewallRulesState) AllRules() ([]*FirewallRule, error) {
	coll, closer := fw.st.db().GetCollection(firewallRulesC)
	defer closer()

	var docs []firewallRulesDoc
	err := coll.Find(nil).All(&docs)
	if err != nil {
		return nil, errors.Trace(err)
	}
	result := make([]*FirewallRule, len(docs))
	for i, doc := range docs {
		result[i] = doc.toRule()
	}
	return result, nil
}
959546
func (da *da) CardinalPluralRule(num float64, v uint64) locales.PluralRule {

	n := math.Abs(num)
	i := int64(n)
	t := locales.T(n, v)

	if (n == 1) || (t != 0 && (i == 0 || i == 1)) {
		return locales.PluralRuleOne
	}

	return locales.PluralRuleOther
}
1109447
func (ewo *ewo_CM) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
	return locales.PluralRuleUnknown
}
1069190
func localIdInCollectionOp(st modelBackend, localIds ...string) bson.D {
	ids := make([]string, len(localIds))
	for i, id := range localIds {
		ids[i] = st.docID(id)
	}
	return inCollectionOp("_id", ids...)
}