constraint.dart 1.06 KB
Newer Older
Chinmay Garde's avatar
Chinmay Garde committed
1 2 3 4
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
import 'priority.dart';
import 'expression.dart';
Chinmay Garde's avatar
Chinmay Garde committed
7

8 9 10 11 12
enum Relation {
  equalTo,
  lessThanOrEqualTo,
  greaterThanOrEqualTo,
}
Chinmay Garde's avatar
Chinmay Garde committed
13 14

class Constraint {
15 16
  Constraint(this.expression, this.relation);

Chinmay Garde's avatar
Chinmay Garde committed
17
  final Relation relation;
18

Chinmay Garde's avatar
Chinmay Garde committed
19 20
  final Expression expression;

21
  double priority = Priority.required;
22 23

  Constraint operator |(double p) => this..priority = p;
24

pq's avatar
pq committed
25
  @override
26 27 28 29 30 31
  String toString() {
    StringBuffer buffer = new StringBuffer();
    buffer.write(expression.toString());

    switch (relation) {
      case Relation.equalTo:
Hixie's avatar
Hixie committed
32
        buffer.write(' == 0 ');
33 34
        break;
      case Relation.greaterThanOrEqualTo:
Hixie's avatar
Hixie committed
35
        buffer.write(' >= 0 ');
36 37
        break;
      case Relation.lessThanOrEqualTo:
Hixie's avatar
Hixie committed
38
        buffer.write(' <= 0 ');
39 40 41
        break;
    }

Hixie's avatar
Hixie committed
42
    buffer.write(' | priority = $priority');
43

44
    if (priority == Priority.required)
Hixie's avatar
Hixie committed
45
      buffer.write(' (required)');
46 47 48

    return buffer.toString();
  }
Chinmay Garde's avatar
Chinmay Garde committed
49
}