Java中具有泛型类型的AbstractFactory:一个设计问题(AbstractFactory with generic types in Java: a design problem)
根据抽象工厂模式,我有以下2个接口:
public interface GenericObjectInterface<T extends Number>{ public T getResult(); } public interface AbstractFactoryInterface{ public <T extends Number> GenericObjectInterface<T> createGenericObject(); }
我有一个实现GenericObject的抽象类,但它仍然不知道具体类型(它只对数字进行通用操作):
public abstract class GenericAbstractClass<T extends Number> implements GenericObjectInterface<T>{ }
然后我有一系列扩展的具体类来执行泛型参数替换:
public class IntegerObject extends GenericAbstractClass<Integer>{ public Integer getResult(){} } ....
现在,从工厂实现的内部构建具体类型,即实现GenericObjectInterface但失去了泛型参数:
public class ConcreteFactory{ public <T extends Number> GenericObjectInterface<T> greateGenericObject(Class<T> c){ if (c.class.isInstance(Integer.class)){ IntegerObject obj = new IntegerObject(); //I would like to return obj GenericObjectInterface<T> a = new IntegerObject(); //errror GenericAbstractClass<T> a = new IntegerObject(); //errror return a; }else if (c.class.isInstance(Double.class)){ } } }
我想返回实现GenericObjectInterface的obj,但我不知道该怎么做。 我该如何解决这个问题?
我习惯于抽象工厂,但我从来没有用过泛型。 我在解释模式时犯了一些错误吗?
I have the following 2 interfaces accordingly to abstract factory pattern:
public interface GenericObjectInterface<T extends Number>{ public T getResult(); } public interface AbstractFactoryInterface{ public <T extends Number> GenericObjectInterface<T> createGenericObject(); }
I have an abstract class implementing GenericObject, but it's still unaware of the concrete type (it does only generic operations on Number):
public abstract class GenericAbstractClass<T extends Number> implements GenericObjectInterface<T>{ }
Then I have a series of concrete class extending that perform generic parameter substitution:
public class IntegerObject extends GenericAbstractClass<Integer>{ public Integer getResult(){} } ....
Now, from inside an implementation of the factory I build the concrete type, that's implementing GenericObjectInterface but has lost it's generic parameter:
public class ConcreteFactory{ public <T extends Number> GenericObjectInterface<T> greateGenericObject(Class<T> c){ if (c.class.isInstance(Integer.class)){ IntegerObject obj = new IntegerObject(); //I would like to return obj GenericObjectInterface<T> a = new IntegerObject(); //errror GenericAbstractClass<T> a = new IntegerObject(); //errror return a; }else if (c.class.isInstance(Double.class)){ } } }
I would like to return obj that implements GenericObjectInterface but I don't know how can I do it. how can I solve this?
I'm used to abstract factory but I've never used it with generics. Am I doing some mistakes in interpreting the pattern?
原文:https://stackoverflow.com/questions/7530717
最满意答案
您可以将每个网站保存到存储桶中的其他位置
s3cmd sync --recursive --preserve /var/www/website1.com/public_html s3://mybucket/website1/ s3cmd sync --recursive --preserve /var/www/website2.com/public_html s3://mybucket/website2/ s3cmd sync --recursive --preserve /var/www/website3.com/public_html s3://mybucket/website3/
you could save each website into a different location within your bucket
s3cmd sync --recursive --preserve /var/www/website1.com/public_html s3://mybucket/website1/ s3cmd sync --recursive --preserve /var/www/website2.com/public_html s3://mybucket/website2/ s3cmd sync --recursive --preserve /var/www/website3.com/public_html s3://mybucket/website3/
相关问答
更多-
您必须使用最新版本1.6.1 只需按照以下方式或您可能想要使用的任何其他方式升级s3cmd。 pip install --upgrade You have to use the latest version 1.6.1 Just upgrade s3cmd the following way or any other way you might want to use. pip install --upgrade
-
如果使用“随机”名称,则表示不同步。 如果您在文件名/映射上的唯一记录是本地记录,则在本地故障时无法恢复备份。 如果您不需要文件的所有版本,我建议在上传之前将所有内容放入(可能是加密的)压缩tarball中。 否则,您将必须编写一个列出所有文件的小脚本,并单独执行指定随机目标的s3cmd put ,其中映射将附加到日志文件中,这应该是您将s3cmd put服务器的第一件事。 我不建议将此作为存储备份的关键。 一个骨架,展示了它如何工作: # Save all files in backupX.sh wher ...
-
您可以将每个网站保存到存储桶中的其他位置 s3cmd sync --recursive --preserve /var/www/website1.com/public_html s3://mybucket/website1/ s3cmd sync --recursive --preserve /var/www/website2.com/public_html s3://mybucket/website2/ s3cmd sync --recursive --preserve /var/www/website3 ...
-
使用s3cmd get过滤结果(filtered results with s3cmd get)[2023-10-16]
s3cmd get --recursive s3://mys3bucket/logfiles/192.168 s3cmd get --recursive s3://mys3bucket/logfiles/192.168 -
经过几次搜索后我找到了解决方案,这是由于RequestTimeTooSkewed。 通过这个命令我能够调试这个s3cmd --configuration --debug Error>
RequestTimeTooSkewed
您可以使用这些命令修复RequestTimeTooSkewed apt-get install ntp 要么 yum install ntp 配置NTP以使用amazon服务器,如:vim /etc/ntp.conf service ntpd ... -
如何使用s3cmd仅移动更改为Amazon S3的文件?(How can I use s3cmd to move only the files that changed to Amazon S3 ?)[2022-07-12]
尝试s3cmd同步选项,如下所示 s3cmd sync /mydir s3://mybucker/ try out the s3cmd sync option something like the following s3cmd sync /mydir s3://mybucker/ -
我同意@MarkAKruger的评论,这里的问题是延迟。 鉴于ColdFusion无法一致地判断文件是否存在,但它始终如一地读取其最新内容(并且在它们不可用时始终无法读取它们),我提出了这个解决方案: string function cacheFileRead( required string cacheFileName ){ var strContent = ''; try{ strContent = FileRead( ARGUMENTS.cachefileNa ...
-
s3cmd:将文件从s3中的加密存储区复制到本地计算机(s3cmd : copy file from encrypted buckets in s3 to local machine)[2022-12-15]
为什么不使用aws命令行? 我想它对加密的s3存储桶有更好的支持。 例如aws s3 cphttps://aws.amazon.com/cli/ So along with this optional parameter --server-side-encryption you have to give the encryption paraphrase while configuring the s3cmd. Unfortunately , I did no ... -
感谢来自github的@fviard来回答我的问题。 这里复制的是我收到的答案: 默认情况下,同步不会删除目标中不在源中的文件。 它可以告诉你在摘要中,但它不会这样做。 检查您是否具有以下配置:delete_after = False delete_after_fetch = False delete_removed = False并且您不在命令行上使用选项,如“--delete-removed”。 顺便说一句,你不需要在分开的命令中做事。 如果没有“skip-existing”,你可以这样做:sync s ...
-
使用s3cmd将静态网站上传到Amazon S3时设置元数据(Set metadata while using s3cmd to upload static website to Amazon S3)[2022-06-22]
您可以使用-m开关在上传到s3时设置文件的mime类型 s3cmd -m text/css ./file.css s3:/path/to/bucket 另外,我所做的是首先用gzip压缩它,然后上传到s3,但你也必须设置内容编码。 请注意,Chrome和Safari有时不喜欢.gz扩展程序,所以我使用.jgz。 gzip file.css -9 -c > file.css.jgz s3cmd -m text/css ./file.css s3:/path/to/bucket s3cmd -m text/c ...