All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openlca.git.model.Reference Maven / Gradle / Ivy

There is a newer version: 2.2.1
Show newest version
package org.openlca.git.model;

import java.util.Objects;

import org.eclipse.jgit.lib.ObjectId;
import org.openlca.git.util.GitUtil;
import org.openlca.util.Strings;

public class Reference extends ModelRef {

	public final String commitId;
	public final ObjectId objectId;

	public Reference(String path, String commitId, ObjectId objectId) {
		super(path);
		this.commitId = commitId;
		this.objectId = objectId != null ? objectId : ObjectId.zeroId();
	}

	@Override
	public int hashCode() {
		return (commitId + ":" + path).hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Reference))
			return false;
		var ref = (Reference) obj;
		if (!super.equals(obj))
			return false;
		if (!Strings.nullOrEqual(ref.commitId, commitId))
			return false;
		return Objects.equals(ref.objectId, objectId);
	}

	public String getBinariesPath() {
		return GitUtil.toBinDirPath(type, category, refId);
	}

	@Override
	protected String fieldsToString() {
		var s = super.fieldsToString();
		return s + ", commitId=" + commitId + ", objectId=" + ObjectId.toString(objectId);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy