Git Product home page Git Product logo

guavanator's Introduction

Guavanator

Eclipse plugin to generate Guava versions of equals, hashcode, toString, getters/setters and a Builder.

Install

Help -> Install New Software https://raw.github.com/joetoth/guavanator/master/site/site.xml

Usage

Right-Click -> Source -> Generate Guava Bean

public class Person implements Serializable {
	private String firstName;
	private final String lastName;
	private int age;
	private List<String> siblingNames = Lists.newArrayList();
	private final ImmutableSet<String> parentNames;
}

Will Generate

public class Person implements Serializable {
	private String firstName;
	private final String lastName;
	private int age;
	private List<String> siblingNames = Lists.newArrayList();
	private final ImmutableSet<String> parentNames;

	// Everything below is auto-generated by the Guavanator

	public String getFirstName() {
		return firstName;
	}

	public Person setFirstName(String firstName) {
		this.firstName = firstName;
		return this;
	}

	public String getLastName() {
		return lastName;
	}

	public Person setLastName(String lastName) {
		this.lastName = lastName;
		return this;
	}

	public int getAge() {
		return age;
	}

	public Person setAge(int age) {
		this.age = age;
		return this;
	}

	public List<String> getSiblingNames() {
		return siblingNames;
	}

	public Person setSiblingNames(List<String> siblingNames) {
		this.siblingNames = siblingNames;
		return this;
	}

	public ImmutableSet<String> getParentNames() {
		return parentNames;
	}

	public Person setParentNames(ImmutableSet<String> parentNames) {
		this.parentNames = parentNames;
		return this;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof Person)) {
			return false;
		}

		Person that = (Person) obj;

		return Objects.equal(this.firstName, that.firstName)
				&& Objects.equal(this.lastName, that.lastName)
				&& Objects.equal(this.age, that.age)
				&& Objects.equal(this.siblingNames, that.siblingNames)
				&& Objects.equal(this.parentNames, that.parentNames);
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(
				firstName,
				lastName,
				age,
				siblingNames,
				parentNames);
	}

	@Override
	public String toString() {
		return Objects.toStringHelper(this)
				.add("firstName", firstName)
				.add("lastName", lastName)
				.add("age", age)
				.add("siblingNames", siblingNames)
				.add("parentNames", parentNames)
				.toString();
	}

	public static class Builder {
		private String firstName;
		private String lastName;
		private int age;
		private List<String> siblingNames;
		private ImmutableSet<String> parentNames;

		public Builder setFirstName(String firstName) {
			this.firstName = firstName;
			return this;
		}

		public Builder setLastName(String lastName) {
			this.lastName = lastName;
			return this;
		}

		public Builder setAge(int age) {
			this.age = age;
			return this;
		}

		public Builder setSiblingNames(List<String> siblingNames) {
			this.siblingNames = siblingNames;
			return this;
		}

		public Builder setParentNames(ImmutableSet<String> parentNames) {
			this.parentNames = parentNames;
			return this;
		}

		public Person build() {
			return new Person(this);
		}
	}

	private Person(Builder builder) {
		this.firstName = builder.firstName;
		this.lastName = builder.lastName;
		this.age = builder.age;
		this.siblingNames = builder.siblingNames;
		this.parentNames = builder.parentNames;
	}

	public static Builder newBuilder() {
		return new Builder();
	}
}

guavanator's People

Contributors

joetoth avatar

Watchers

 avatar James Cloos avatar Grzegorz Sancewicz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.