@Override
	public int compareTo(Object o) {
		if (this == o) return 0;
		if (!(o instanceof Rule)) return getClass().getName().compareTo(o.getClass().getName());

		Rule r = (Rule) o;
		int c = mode.compareTo(r.mode);
		if (c != 0) return c;
		c = body.size() - r.body.size();
		if (c != 0) return c;
		Iterator<Literal> it = body.iterator();
		Iterator<Literal> itr = r.body.iterator();
		Literal l, lr;
		while (it.hasNext()) {
			l = it.next();
			lr = itr.next();
			c = l.compareTo(lr);
			if (c != 0) return c;
		}
		c = head.size() - r.head.size();
		if (c != 0) return c;
		for (int i = 0; i < head.size(); i++) {
			c = head.get(i).compareTo(r.head.get(i));
			if (c != 0) return c;
		}
		return 0;
	}