Platypus - Java Mixins

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

License

License

GroupId

GroupId

com.github.ruifigueira
ArtifactId

ArtifactId

platypus
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Platypus - Java Mixins
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project Organization

Project Organization

VILT Group
Source Code Management

Source Code Management

https://github.com/ruifigueira/platypus

Download platypus

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.ruifigueira/platypus/ -->
<dependency>
    <groupId>com.github.ruifigueira</groupId>
    <artifactId>platypus</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.ruifigueira/platypus/
implementation 'com.github.ruifigueira:platypus:0.1.0'
// https://jarcasting.com/artifacts/com.github.ruifigueira/platypus/
implementation ("com.github.ruifigueira:platypus:0.1.0")
'com.github.ruifigueira:platypus:jar:0.1.0'
<dependency org="com.github.ruifigueira" name="platypus" rev="0.1.0">
  <artifact name="platypus" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.ruifigueira', module='platypus', version='0.1.0')
)
libraryDependencies += "com.github.ruifigueira" % "platypus" % "0.1.0"
[com.github.ruifigueira/platypus "0.1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.google.guava : guava jar 18.0
org.slf4j : slf4j-api jar 1.7.10

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
org.mockito : mockito-core jar 1.10.19

Project Modules

There are no modules declared in this project.

Platypus Build Status

Platypus is a Java Mixins library. It is being heavily used in Minium.

A quick example:

public interface Car {
    String drive();
}

public interface Aircraft {
    String fly();
}

public interface Delorean extends Car, Aircraft { }

public class CarImpl implements Car {
    @Override public String drive() {
        return "It can drive";
    }
}

public class AircraftImpl implements Aircraft {
    @Override public String fly() {
        return "It can fly";
    }
}

@Test public void testDelorean() {
	MixinClass<Delorean> deloreanMixinClass = MixinClasses.create(Delorean.class);
	
	Delorean delorean = deloreanMixinClass.newInstance(new AbstractMixinInitializer() {
	    @Override
	    protected void initialize() {
	        implement(Car.class).with(new CarImpl());
	        implement(Aircraft.class).with(new AircraftImpl());
	    }
	});
	
	assertThat(delorean.drive(), equalTo("It can drive"));
	assertThat(delorean.fly(), equalTo("It can fly"));
}

Besides, Mixin interface and its default implementation, Mixin.Impl will allow maximum fun with complex mixins, where you can chain different interface calls using the .as(Class<?>) method.

For instance, check the delorean.as(Aircraft.class).fly() in the adaptation of the previous example:

public interface Car extends Mixin {
    String drive();
}

public interface Aircraft extends Mixin {
    String fly();
}

public class CarImpl extends Mixin implements Car {
    @Override public String drive() {
        return "It can drive";
    }
}

public class AircraftImpl extends Mixin implements Aircraft {
    @Override public String fly() {
        return "It can fly";
    }
}

@Test public void testDeloreanCarWithAircrafCapabilities() {
	MixinClass<Car> deloreanMixinClass = MixinClasses.create(Car.class, Aircraft.class);
	
	Car delorean = deloreanMixinClass.newInstance(new AbstractMixinInitializer() {
	    @Override
	    protected void initialize() {
	        implement(Car.class).with(new CarImpl());
	        implement(Aircraft.class).with(new AircraftImpl());
	    }
	});
	
	assertThat(delorean.drive(), equalTo("It can drive"));
	assertThat(delorean.as(Aircraft.class).fly(), equalTo("It can fly"));
}

Versions

Version
0.1.0