builder

Builder pattern for polymorphic object hierarchy: possible with Java?

放肆的年华 提交于 2019-11-27 10:53:39
问题 I have a hierarchy of interfaces, with Child implementing Parent . I would like to work with immutable objects, so I would like to design Builder classes that construct these objects conveniently. However, I have many Child interfaces, and I don't want to repeat the code for building Parent s in each type of child builder. So, assume the following definitions: public interface Parent { public Long getParentProperty(); } public interface Child1 extends Parent { public Integer getChild1Property

How do I specify a newBuilder for a scala set?

北慕城南 提交于 2019-11-27 07:24:28
问题 I am trying to extend a set of integers in Scala. Based on an earlier answer I have decided to use a SetProxy object. I am now trying to implement the newBuilder mechanism as described in chapter 25 of the second edition of Programming in Scala and am having trouble. Specifically I cannot figure out what parameter to specify to the SetBuilder object. Here is what I have tried. package example import scala.collection.immutable.{HashSet, SetProxy} import scala.collection.mutable case class

The builder pattern and a large number of mandatory parameters

北城以北 提交于 2019-11-27 07:03:09
To date I use the following implementation of the builder pattern (as opposed to the implementation described here ): public class Widget { public static class Builder { public Builder(String name, double price) { ... } public Widget build() { ... } public Builder manufacturer(String value) { ... } public Builder serialNumber(String value) { ... } public Builder model(String value) { ... } } private Widget(Builder builder) { ... } } This works well for most situations I've encountered where I need to build up a complex object with a variety of required/mandatory and optional parameters.

How to populate a TableView that is defined in an fxml file that is designed in JavaFx Scene Builder

◇◆丶佛笑我妖孽 提交于 2019-11-27 04:24:06
问题 I would like to know how do I populate a TableView with data... All the examples I have seen creates a TableView with columns and everything and add it to the scene. All done in the java code itself. What I want to know: if I design my "form" in JavaFx Scene builder. Defining all the tables and columns in there. How do I access it to populate it from java? Or if someone can point me to a proper tutorial on this please. I have defined my form in JavaFx Scene Builder - only a TableView with 3

Rails 3 install error: “invalid value for @cert_chain”

放肆的年华 提交于 2019-11-27 02:32:23
问题 I'm trying to install Rails 3 on a new OS X Snow Leopard machine (with dev tools installed), and when I sudo gem install rails , I get the following error: ERROR: While executing gem ... (Gem::FormatException) builder-2.1.2 has an invalid value for @cert_chain And the update fails. Has anyone seen this before? I grep ed the builder-2.1.2 directory for 'cert_chain,' but couldn't find any clues. Ruby version is 1.8.7 OS X 10.6.6 Thanks! 回答1: This is an issue with Rubygems version 1.7.1.

“borrowed value does not live long enough” when using the builder pattern

妖精的绣舞 提交于 2019-11-27 02:21:59
I have the following code: pub struct Canvas<'a> { width: isize, height: isize, color: Color, surface: Surface, texture: Texture, renderer: &'a Renderer, } impl<'a> Canvas<'a> { pub fn new(width: isize, height: isize, renderer: &'a Renderer) -> Canvas<'a> { let color = Color::RGB(0, 30, 0); let mut surface = core::create_surface(width, height); let texture = Canvas::gen_texture(&mut surface, width, height, color, renderer); Canvas { width: width, height: height, color: color, surface: surface, texture: texture, renderer: renderer, } } pub fn color(&mut self, color: Color) -> &mut Canvas<'a> {

How to access attributes using Nokogiri

最后都变了- 提交于 2019-11-27 01:43:53
问题 I have a simple task of accessing the values of some attributes. This is a simple script that uses Nokogiri::XML::Builder to create a simple XML doc. require 'nokogiri' builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| xml.Placement(:messageId => "392847-039820-938777", :system => "MOD", :version => "2.0") { xml.objects { xml.object(:myattribute => "99", :anotherattrib => "333") xml.nextobject_ '9387toot' xml.Entertainment "Last Man Standing" } } end puts builder.to_xml puts

Spring: Using builder pattern to create a bean

自作多情 提交于 2019-11-27 00:35:15
问题 I use ektorp to connect to CouchDB. The way to build an ektorp HttpClient instance is to use builder pattern: HttpClient httpClient = new StdHttpClient.Builder() .host("mychouchdbhost") .port(4455) .build(); I am relatively new to Spring. Please advice me on how I can configure an HttpClient in my context to create it via the Builder . One way to do this is with @Configuration . Are any other options? 回答1: You may try to implement FactoryBean interface: public class HttpFactoryBean implements

Complex queries with JPA Criteria builder

蓝咒 提交于 2019-11-27 00:12:03
问题 Can someone suggest me how to build up the following query using JPA Criteria builder API? SELECT id,status,created_at from transactions where status='1' and currency='USD' and appId='123' order by id It's better if I can find a solution which creates dynamically based on the parameters given as a Map<String,String> using metamodel classes or any other way. 回答1: It's like this (without metamodel): Map<String, Object> params = ...; CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery

Builder Vs Decorator pattern [closed]

余生长醉 提交于 2019-11-27 00:07:12
问题 From When would you use the Builder Pattern?, It is said that builder pattern is appropriate for Pizza example. Why not Decorator ? by treating Cheese, Pepperoni, Bacon as additional decorations on a base pizza. Is it for the reason that Cheese/Pepperoni have to be built seperately. I don't think, they need to be built seperately as they can be available readymade. Pls clarify. Am also looking for a good real-world example of decorator pattern and reason why it is the apt for that particular