| #Java - Code Snippets for '#Factory' - 19 code snippet(s) found | 
| 
 | 
| |  Sample 1. Example of Factory Class |  | 
 | 
| public final class EmployeeFactory {
 private Employee svEmp;
 
 public EmployeeFactory(String type){
 if( type.equals("Manager")){
 svEmp = new Manager();
 } else if(type.equals("Developer")){
 svEmp = new Developer();
 } else if(type.equals("QA")){
 svEmp = new QA();
 }
 }
 
 public Employee getFactoryProduct() {
 return svEmp;
 }
 
 }
 | 
| 
 | 
|  Like  Feedback  factory design pattern  factory class  final class  composition | 
| 
 | 
| 
 | 
| |  Sample 2. Cache Hibernate Entities using EHCache |  | 
 | 
| // net.sf.ehcache.Cache.Cache(String name, int maxElementsInMemory, MemoryStoreEvictionPolicy memoryStoreEvictionPolicy, boolean overflowToDisk, String diskStorePath, boolean eternal, long
 timeToLiveSeconds, long timeToIdleSeconds, boolean diskPersistent, long
 diskExpiryThreadIntervalSeconds, RegisteredEventListeners registeredEventListeners)
 
 Ehcache employeeCache = new Cache("Employee", 1000, MemoryStoreEvictionPolicy.FIFO, false, "c:/EmployeeDiskCacheStorage", false, 300,
 300, false, 30, null);
 
 employeeCache = new SelfPopulatingCache(employeeCache, new CacheEntryFactory() {
 @Override
 public Object createEntry(Object day) throws Exception {
 Employee employee = getEmployee(1234);
 return employee;
 }
 });
 
 CacheManager.getInstance().addCache(employeeCache);
 | 
| 
 | 
|  Like  Feedback  EHCache  cache hibernate entities  CacheManager  CacheEntryFactory  SelfPopulatingCache  MemoryStoreEvictionPolicy  net.sf.ehcache.Cache | 
| 
 | 
| 
 | 
| |  Sample 3. Usage of javax.xml.transform.Transformer, TransformerFactory |  | 
 | 
| TransformerFactory tFactory = TransformerFactory.newInstance();
 Transformer transformer = tFactory.newTransformer(
 new StreamSource(styleSheet)
 );
 
 transformer.transform(new StreamSource(xml), new StreamResult(out));
 | 
| 
 | 
|  Like  Feedback  TransformerFactory  Transformer | 
| 
 | 
| 
 | 
| |  Sample 4. Code Sample / Example / Snippet of  org.apache.storm.trident.windowing.WindowsStoreFactory |  | 
 | 
|     public static void main(String[] args) throws Exception {
 Config conf = new Config();
 
 WindowsStoreFactory mapState = new InMemoryWindowsStoreFactory();
 
 
 
 if (args.length == 0) {
 
 List<? extends WindowConfig> list = Arrays.asList(
 
 SlidingCountWindow.of(1000, 100)
 
 ,TumblingCountWindow.of(1000)
 
 ,SlidingDurationWindow.of(new BaseWindowedBolt.Duration(6, TimeUnit.SECONDS), new BaseWindowedBolt.Duration(3, TimeUnit.SECONDS))
 
 ,TumblingDurationWindow.of(new BaseWindowedBolt.Duration(3, TimeUnit.SECONDS))
 
 );
 
 
 
 for (WindowConfig windowConfig : list) {
 
 LocalCluster cluster = new LocalCluster();
 
 cluster.submitTopology("wordCounter", conf, buildTopology(mapState, windowConfig));
 
 Utils.sleep(60 * 1000);
 
 cluster.shutdown();
 
 }
 
 System.exit(0);
 
 } else {
 
 conf.setNumWorkers(3);
 
 StormSubmitter.submitTopologyWithProgressBar(args[0], conf, buildTopology(mapState, SlidingCountWindow.of(1000, 100)));
 
 }
 
 }
 
 
 | 
| 
 | 
|  Like  Feedback  org.apache.storm.trident.windowing.WindowsStoreFactory | 
| 
 | 
| 
 | 
| 
 | 
| |  Sample 5. Code Sample / Example / Snippet of  org.apache.storm.trident.state.StateFactory |  | 
 | 
|     protected StormTopology getTopology() throws IOException {
 final TridentTopology tridentTopology = new TridentTopology();
 
 final SolrFieldsSpout spout = new SolrFieldsSpout();
 
 final Stream stream = tridentTopology.newStream("SolrFieldsSpout", spout);
 
 final StateFactory solrStateFactory = new SolrStateFactory(getSolrConfig(), getSolrMapper());
 
 stream.partitionPersist(solrStateFactory, spout.getOutputFields(),  new SolrUpdater(), new Fields());
 
 return tridentTopology.build();
 
 }
 
 
 | 
| 
 | 
|  Like  Feedback  org.apache.storm.trident.state.StateFactory | 
| 
 | 
| 
 | 
| |  Sample 6. Code Sample / Example / Snippet of  org.apache.calcite.rel.type.RelDataTypeFactory |  | 
 | 
|       public Void apply(RelNode node) {
 CassandraSchema.this.addMaterializedViews();
 
 return null;
 
 }
 
 });
 
 }
 
 
 
 RelProtoDataType getRelDataType(String columnFamily, boolean view) {
 
 List<ColumnMetadata> columns;
 
 if (view) {
 
 columns = getKeyspace().getMaterializedView(columnFamily).getColumns();
 
 } else {
 
 columns = getKeyspace().getTable(columnFamily).getColumns();
 
 }
 
 
 
 final RelDataTypeFactory typeFactory =
 
 new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
 
 final RelDataTypeFactory.FieldInfoBuilder fieldInfo = typeFactory.builder();
 
 for (ColumnMetadata column : columns) {
 
 
 | 
| 
 | 
|  Like  Feedback  org.apache.calcite.rel.type.RelDataTypeFactory | 
| 
 | 
| 
 | 
| |  Sample 7. Code Sample / Example / Snippet of  org.apache.calcite.sql.type.SqlTypeFactoryImpl |  | 
 | 
|   public void testLeastRestrictiveWithAny() {
 SqlTypeFactoryImpl typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
 
 final RelDataType sqlBigInt = typeFactory.createSqlType(SqlTypeName.BIGINT);
 
 final RelDataType sqlAny = typeFactory.createSqlType(SqlTypeName.ANY);
 
 
 
 RelDataType leastRestrictive =
 
 typeFactory.leastRestrictive(Lists.newArrayList(sqlBigInt, sqlAny));
 
 assertEquals(leastRestrictive.getSqlTypeName(), SqlTypeName.ANY);
 
 }
 
 
 | 
| 
 | 
|  Like  Feedback  org.apache.calcite.sql.type.SqlTypeFactoryImpl | 
| 
 | 
| 
 | 
| |  Sample 8. Code Sample / Example / Snippet of  javax.net.ssl.KeyManagerFactory |  | 
 | 
|     public SSLContextBuilder loadKeyMaterial(
 final KeyStore keystore,
 
 final char[] keyPassword,
 
 final PrivateKeyStrategy aliasStrategy)
 
 throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
 
 final KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
 
 KeyManagerFactory.getDefaultAlgorithm());
 
 kmfactory.init(keystore, keyPassword);
 
 final KeyManager[] kms =  kmfactory.getKeyManagers();
 
 if (kms != null) {
 
 if (aliasStrategy != null) {
 
 for (int i = 0; i < kms.length; i++) {
 
 final KeyManager km = kms[i];
 
 if (km instanceof X509ExtendedKeyManager) {
 
 kms[i] = new KeyManagerDelegate((X509ExtendedKeyManager) km, aliasStrategy);
 
 }
 
 }
 
 }
 
 for (final KeyManager km : kms) {
 
 keymanagers.add(km);
 
 }
 
 }
 
 return this;
 
 }
 
 
 | 
| 
 | 
|  Like  Feedback  javax.net.ssl.KeyManagerFactory | 
| 
 | 
| 
 | 
| |  Sample 9. Code Sample / Example / Snippet of  javax.net.ssl.TrustManagerFactory |  | 
 | 
|     public SSLContextBuilder loadTrustMaterial(
 final KeyStore truststore,
 
 final TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException {
 
 final TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
 
 TrustManagerFactory.getDefaultAlgorithm());
 
 tmfactory.init(truststore);
 
 final TrustManager[] tms = tmfactory.getTrustManagers();
 
 if (tms != null) {
 
 if (trustStrategy != null) {
 
 for (int i = 0; i < tms.length; i++) {
 
 final TrustManager tm = tms[i];
 
 if (tm instanceof X509TrustManager) {
 
 tms[i] = new TrustManagerDelegate(
 
 (X509TrustManager) tm, trustStrategy);
 
 }
 
 }
 
 }
 
 for (final TrustManager tm : tms) {
 
 this.trustmanagers.add(tm);
 
 }
 
 }
 
 return this;
 
 }
 
 
 | 
| 
 | 
|  Like  Feedback  javax.net.ssl.TrustManagerFactory | 
| 
 | 
| 
 | 
| 
 | 
| |  Sample 10. Code Sample / Example / Snippet of  javax.net.ssl.TrustManagerFactory |  | 
 | 
|     private TrustManager[] getTrustManagerFactory(String truststoreFile, String storePass) throws IOException, GeneralSecurityException {
 TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
 
 
 
 InputStream is = null;
 
 try {
 
 is = new FileInputStream(truststoreFile);
 
 
 
 KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
 
 ks.load(is, storePass.toCharArray());
 
 
 
 tmf.init(ks);
 
 
 
 return tmf.getTrustManagers();
 
 }
 
 finally {
 
 try {
 
 if (is != null) {
 
 is.close();
 
 }
 
 }
 
 catch (IOException e) {
 
 }
 
 }
 
 }
 
 
 | 
| 
 | 
|  Like  Feedback  javax.net.ssl.TrustManagerFactory | 
| 
 | 
| 
 | 
| |  Sample 11. Code Sample / Example / Snippet of  javax.net.ssl.KeyManagerFactory |  | 
 | 
|     private KeyManager[] getKeyManagerFactory(String keystoreFile, String storePass) throws IOException, GeneralSecurityException {
 KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
 
 
 
 InputStream is = null;
 
 try {
 
 is = new FileInputStream(keystoreFile);
 
 
 
 KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
 
 ks.load(is, storePass.toCharArray());
 
 
 
 kmf.init(ks, storePass.toCharArray());
 
 
 
 return kmf.getKeyManagers();
 
 }
 
 finally {
 
 try {
 
 if (is != null) {
 
 is.close();
 
 }
 
 }
 
 catch (IOException e) {
 
 }
 
 }
 
 }
 
 
 | 
| 
 | 
|  Like  Feedback  javax.net.ssl.KeyManagerFactory | 
| 
 | 
| 
 | 
| |  Sample 12. Code Sample / Example / Snippet of  javax.xml.parsers.SAXParserFactory |  | 
 | 
|     protected void setUp() throws Exception {
 SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
 
 m_parser = saxParserFactory.newSAXParser();
 
 
 
 String xml = generateValidTestXml();
 
 m_inputStream = new ByteArrayInputStream(xml.getBytes());
 
 }
 
 
 | 
| 
 | 
|  Like  Feedback  javax.xml.parsers.SAXParserFactory | 
| 
 | 
| 
 | 
| |  Sample 13. Code Sample / Example / Snippet of  javax.xml.parsers.DocumentBuilderFactory |  | 
 | 
|     private Document getDocument(InputStream input) throws IOException {
 try {
 
 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 
 DocumentBuilder builder;
 
 builder = factory.newDocumentBuilder();
 
 return builder.parse(input);
 
 }
 
 catch (ParserConfigurationException e) {
 
 throw new IOException("Error instantiation XML parser:" + e.getMessage());
 
 }
 
 catch (SAXException e) {
 
 throw new IOException("Error parsing user data:" + e.getMessage());
 
 }
 
 }
 
 
 | 
| 
 | 
|  Like  Feedback  javax.xml.parsers.DocumentBuilderFactory | 
| 
 | 
| 
 | 
| |  Sample 14. Code Sample / Example / Snippet of  org.apache.ace.connectionfactory.impl.UrlCredentials.AuthType |  | 
 | 
|     private void supplyCredentials(URLConnection conn, UrlCredentials urlCreds) throws IOException {
 final AuthType type = urlCreds.getType();
 
 final Object[] creds = urlCreds.getCredentials();
 
 
 
 if (AuthType.BASIC.equals(type)) {
 
 applyBasicAuthentication(conn, creds);
 
 }
 
 else if (AuthType.CLIENT_CERT.equals(type)) {
 
 applyClientCertificate(conn, creds);
 
 }
 
 else if (!AuthType.NONE.equals(type)) {
 
 throw new IllegalArgumentException("Unknown authentication type: " + type);
 
 }
 
 }
 
 
 | 
| 
 | 
|  Like  Feedback  org.apache.ace.connectionfactory.impl.UrlCredentials.AuthType | 
| 
 | 
| 
 | 
| 
 | 
| |  Sample 15. Code Sample / Example / Snippet of  org.apache.activemq.ActiveMQConnectionFactory |  | 
 | 
|     public void run() throws JMSException {
 ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
 
 connection = factory.createConnection();
 
 session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
 
 topic = session.createTopic("topictest.messages");
 
 control = session.createTopic("topictest.control");
 
 
 
 MessageConsumer consumer = session.createConsumer(topic);
 
 consumer.setMessageListener(this);
 
 
 
 connection.start();
 
 
 
 producer = session.createProducer(control);
 
 System.out.println("Waiting for messages...");
 
 }
 
 
 | 
| 
 | 
|  Like  Feedback  org.apache.activemq.ActiveMQConnectionFactory | 
| 
 | 
| 
 | 
| |  Sample 16. Code Sample / Example / Snippet of  org.apache.commons.compress.archivers.ArchiveStreamFactory |  | 
 | 
|     public void testEncodingCtor() {
 ArchiveStreamFactory fac = new ArchiveStreamFactory();
 
 assertNull(fac.getEntryEncoding());
 
 fac = new ArchiveStreamFactory(null);
 
 assertNull(fac.getEntryEncoding());
 
 fac = new ArchiveStreamFactory("UTF-8");
 
 assertEquals("UTF-8", fac.getEntryEncoding());
 
 }
 
 
 | 
| 
 | 
|  Like  Feedback  org.apache.commons.compress.archivers.ArchiveStreamFactory | 
| 
 | 
| 
 | 
| |  Sample 17. Code Sample / Example / Snippet of  org.apache.commons.compress.compressors.CompressorStreamFactory |  | 
 | 
|     public void testOverride() {
 CompressorStreamFactory fac = new CompressorStreamFactory();
 
 assertFalse(fac.getDecompressConcatenated());
 
 fac.setDecompressConcatenated(true);
 
 assertTrue(fac.getDecompressConcatenated());
 
 
 
 fac = new CompressorStreamFactory(false);
 
 assertFalse(fac.getDecompressConcatenated());
 
 try {
 
 fac.setDecompressConcatenated(true);
 
 fail("Expected IllegalStateException");
 
 } catch (final IllegalStateException ise) {
 
 }
 
 
 
 fac = new CompressorStreamFactory(true);
 
 assertTrue(fac.getDecompressConcatenated());
 
 try {
 
 fac.setDecompressConcatenated(true);
 
 fail("Expected IllegalStateException");
 
 } catch (final IllegalStateException ise) {
 
 }
 
 }
 
 
 | 
| 
 | 
|  Like  Feedback  org.apache.commons.compress.compressors.CompressorStreamFactory | 
| 
 | 
| 
 | 
| |  Sample 18. Initializing a list using factory method in java 9 
 Usage of List.of()
 |  | 
 | 
| List<String> countryList = List.of("France","Belgium","Germany");
 | 
| 
 | 
|  Like  Feedback  java 9 | 
| 
 | 
| 
 | 
| |  Sample 19. Initializing a map using factory method in java 9 
 Usage of Map.of()
 |  | 
 | 
| Map<String,String> countryCodeMap = Map.of("France","FR","United States","US","Canada","CA");
 | 
| 
 | 
|  Like  Feedback  java 9 | 
| 
 | 
| 
 |