1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  package org.sat4j.pb.tools;
32  
33  import java.math.BigInteger;
34  
35  public final class WeightedObject<T> implements Comparable<WeightedObject<T>> {
36  
37  	public final T thing;
38  	private BigInteger weight;
39  
40  	private WeightedObject(T thing, BigInteger weight) {
41  		this.thing = thing;
42  		this.weight = weight;
43  	}
44  
45  	public BigInteger getWeight() {
46  		return this.weight;
47  	}
48  
49  	public void increaseWeight(BigInteger delta) {
50  		this.weight = this.weight.add(delta);
51  	}
52  
53  	public int compareTo(WeightedObject<T> arg0) {
54  		return this.weight.compareTo(arg0.getWeight());
55  	}
56  
57  	public static <E> WeightedObject<E> newWO(E e, int w) {
58  		return new WeightedObject<E>(e, BigInteger.valueOf(w));
59  	}
60  
61  	public static <E> WeightedObject<E> newWO(E e, long w) {
62  		return new WeightedObject<E>(e, BigInteger.valueOf(w));
63  	}
64  
65  	public static <E> WeightedObject<E> newWO(E e, BigInteger w) {
66  		return new WeightedObject<E>(e, w);
67  	}
68  
69  	@Override
70  	public int hashCode() {
71  		final int prime = 31;
72  		int result = 1;
73  		result = prime * result
74  				+ (this.thing == null ? 0 : this.thing.hashCode());
75  		result = prime * result
76  				+ (this.weight == null ? 0 : this.weight.hashCode());
77  		return result;
78  	}
79  
80  	@Override
81  	public boolean equals(Object obj) {
82  		if (this == obj) {
83  			return true;
84  		}
85  		if (obj == null) {
86  			return false;
87  		}
88  		if (getClass() != obj.getClass()) {
89  			return false;
90  		}
91  		WeightedObject<?> other = (WeightedObject<?>) obj;
92  		if (this.thing == null) {
93  			if (other.thing != null) {
94  				return false;
95  			}
96  		} else if (!this.thing.equals(other.thing)) {
97  			return false;
98  		}
99  		if (this.weight == null) {
100 			if (other.weight != null) {
101 				return false;
102 			}
103 		} else if (!this.weight.equals(other.weight)) {
104 			return false;
105 		}
106 		return true;
107 	}
108 }