Created
May 17, 2018 15:33
-
-
Save soverby/3b756945369aa4e9781033985efca19d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.Data; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.function.Consumer; | |
import java.util.function.Supplier; | |
public class ConsumerSupplierExample { | |
public static void main(String[] args) { | |
ConsumerSupplierExample cse = new ConsumerSupplierExample(); | |
cse.go(); | |
} | |
public void go() { | |
Map<Supplier<String>, Consumer<String>> mapper = new HashMap<>(); | |
DataObjectOne dt1 = new DataObjectOne(); | |
DataObjectTwo dt2 = new DataObjectTwo(); | |
dt1.setOne("one"); | |
dt1.setTwo("two"); | |
dt1.setThree("three"); | |
mapper.put(dt1::getOne, dt2::setFour); | |
mapper.put(dt1::getTwo, dt2::setFive); | |
mapper.put(dt1::getThree, dt2::setSix); | |
mapper.forEach( ((stringSupplier, stringConsumer) -> stringConsumer.accept(stringSupplier.get()))); | |
System.out.println(dt2.toString()); | |
} | |
@Data | |
public static class DataObjectOne { | |
private String one, two, three; | |
} | |
@Data | |
public static class DataObjectTwo { | |
private String four, five, six; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment