builder

Extending classes using Builder pattern

孤人 提交于 2019-12-03 20:27:44
问题 I am trying to extend a class a, into aX. So, I also extend aBuilder. However, while I am able to create an object of class a using : aBuilder f = new aBuilder(); f.bi = i; f.bs = s; a atry = f.withI(i).withS(s).build(); The same doesn't work for aX. When I try to do this : aXBuilder fb = new aXBuilder(); aX aXtry = fb.withI(i).withS(s).withB(b).build(); I get an error (The method withB(Boolean) is undefined for the type a.aBuilder). Should I instead rewrite all the stuff for aX, instead of

Specific Builder for Parameterized Type

◇◆丶佛笑我妖孽 提交于 2019-12-03 16:26:24
I'm trying to write a class in scala that wraps a (parameterized) collection and overrides it's foreach method. What it does with the foreach method is unimportant for the purpose of this question, so lets say it just prints each element out as it's visited. So ideally, we'd be able to use the wrapper as follows: scala> val a = List(1,2,3,4,5) scala> val b = MyWrapper(a) scala> b.foreach{ x => x } 1 2 3 4 5 The key is that I want this to work with any iterable; not just a list. So my first attempt was something like what follows class MyWrapper[A, S[A] <: Iterable[A]]( val s: S[A] with

HTTP Builder/Groovy - lost 302 (redirect) handling?

纵然是瞬间 提交于 2019-12-03 14:28:06
I am reading here http://groovy.codehaus.org/modules/http-builder/doc/handlers.html "In cases where a response sends a redirect status code, this is handled internally by Apache HttpClient, which by default will simply follow the redirect by re-sending the request to the new URL. You do not need to do anything special in order to follow 302 responses." This seems to work fine when I simply use the get() or post() methods without a closure. However, when I use a closure, I seem to lose 302 handling. Is there some way I can handle this myself? Thank you p.s. Here is my log output showing it is a

Builder pattern with a Java 8 Stream

て烟熏妆下的殇ゞ 提交于 2019-12-03 12:25:11
I am building an object with a simple loop: WebTarget target = getClient().target(u); for (Entry<String, String> queryParam : queryParams.entrySet()) { target = target.queryParam(queryParam.getKey(), queryParam.getValue()); } I want to do the same thing using the Java8 Stream API but I cannot figure out how to do it. What makes me struggle is that target is reassigned every time, so a simple .forEach() will not work. I guess I need to use a .collect() or reduce() since I am looking for a single return value but I am lost at the moment! aioobe There's unfortunately no foldLeft method in the

How to exclude property from Lombok builder?

↘锁芯ラ 提交于 2019-12-03 10:22:16
I have a class called as "XYZClientWrapper" , which have following structure: @Builder XYZClientWrapper{ String name; String domain; XYZClient client; } What I want no build function generated for property XYZClient client Does Lombok supports such use case? Yes, you can place @Builder on a constructor or static (factory) method, containing just the fields you want. Disclosure: I am a Lombok developer. Alternatively, I found out that marking a field as final , static or static final instructs @Builder to ignore this field. @Builder public class MyClass { private String myField; private final

disadvantages of builder design pattern [closed]

懵懂的女人 提交于 2019-12-03 10:20:29
What would be the disadvantages of using the builder design pattern. Are there any?? edit - I want to know whether there is any bad consequence of using builder design pattern? As in the GOF book, they have mentioned the good and bad consequences of design patterns. But they haven't mentioned any bad consequence for builder design pattern. It does create more code (and could introduce more complexity) in the DTO than if you had for example contructor arguments and/or setters/getters. In my opinion this is not a big deal, in most cases there is not a lot of extra code. The builder pattern will

JavaWorld on OO: Getters/Setters vs Builder

て烟熏妆下的殇ゞ 提交于 2019-12-03 10:19:53
问题 Background: I found this article on JavaWorld, where Allen Holub explains an alternative to Getters/Setters that maintains the principle that the implementation of an object should be hidden (his example code can also be found below). It is explained that the classes Name / EmployeeId / Money should have a constructor taking a single string - the reasoning is that if you type it as an int , and later need to change it to a long , you will have to modify all the uses of the class, and with

Alter column length in Schema builder?

≯℡__Kan透↙ 提交于 2019-12-03 08:40:46
问题 I have two fields i need to increment the character limit on. I're read through the documentation and to my surprise i found no option for it. Is it possible to do? If not, how should i go about solving this? I could drop the column and re-create it with the correct properties, but i don't want to loose any data in the database. 回答1: Use Raw Queries: /** * Make changes to the database. * * @return void */ public function up() { DB::query('ALTER TABLE mytable MODIFY mycolumn VARCHAR(new-length

Create new object with Builder pattern with “old” object reference

允我心安 提交于 2019-12-03 08:35:40
I am playing around with the Builder pattern and get stuck how to add a new "property" to a new-created object: public class MsProjectTaskData { private boolean isAlreadyTransfered; private String req; public static class Builder { private boolean isAlreadyTransfered = false; public Builder withTransfered(boolean val) { isAlreadyTransfered = val; return this; } public MsProjectTaskData build() { return new MsProjectTaskData(this); } } private MsProjectTaskData(Builder builder) { isAlreadyTransfered = builder.isAlreadyTransfered; } public MsProjectTaskData(String req) { this.req = req; } } I

Builder pattern with inheritance

陌路散爱 提交于 2019-12-03 05:09:08
问题 I want to represent an web service URL request as an object, and found that there are lots of common parameters that could be "bubbled up" in an inheritance hierarchy. A request could have lots of parameters, some mandatory and other optional, for which I believe Bloch's Builder pattern is a nice option, emulating named arguments with a fluent interface. Specifically, I'm designing for the Google Maps web service API, that has as general web service request http://maps.googleapis.com/maps/api