我目前正在重构一些旧代码.我正在寻找有关最佳设计模式的说明.我在考虑工厂模式,但我不确定这是不是最好的方式.
所以这里是伪代码的简要概述.Foo类具有核心业务逻辑.
Class Foo{
private List<Things> stuff;
private static Integer count;
//getter setter for stuff
public Foo(List<Things> stuff){
this.stuff = stuff;
this.count=1;
}
//the following 3 methods are 90% similar
public List<Newthings> doSomeThingFirst(){
//uses the list stuff and also increments the static member count for each entry in List<NewThings> based on certain conditions
}
public List<Newthings> doSomethingSecond(){
//uses the list stuff and also increments the static member count for each entry in List<NewThings> based on certain conditions
}
public List<Newthings> …Run Code Online (Sandbox Code Playgroud) 我右键单击>重构>从项目菜单移动,"将所有内容从.../.. /移动到另一个目录">确定选择了另一个文件夹,并且wham,我的所有数据都消失了.我在项目树中做了一个grep -r来找到它,然后找一个.-iname" mydataas "仍然没有出现.没了.
为什么Intellij会这样做?
系统:Windows Vista 32位,Java 6.0.2
关于将字符转换为整数,我有几个问题.我运行下面的代码,将myInt保留为值4:
char myChar = '4';
int myInt = myChar - '0';
Run Code Online (Sandbox Code Playgroud)
现在,这种转换是Java自动完成的吗?将ascii值'0'从ascii'4'减去,然后在幕后投射到一个int?这对我来说很困惑,因为当我尝试反向操作时,我必须实际将结果转换为char:
int anotherInt = 5;
char newChar = anotherInt + '0'; //gives error
char newChar = (char)(anotherInt + '0'); //works fine
Run Code Online (Sandbox Code Playgroud)
这是否发生是因为Java会自动将(anotherInt +'0')转换为int,如第一个示例中所示?谢谢.
我正在尝试创建SQL Select,它根据字段返回某个字段的计数.所以,这就是我想要做的.
Select count(distinct id) as TotalCount, -- this will be the total of id
count(distinct id where type='A') as TotalA, -- this will be total when type='A'
count(distinct id where type='B') as TotalB -- This will be total when type = 'B'
from MyTable
Run Code Online (Sandbox Code Playgroud)
基本上,TotalCount = TotalA + TotalB.
如何在SQL Select语句中实现此目的?谢谢.
我正在尝试学习Java中的继承和接口.我有三个不同的类:Customer,SilverCustomer和GoldCustomer.SilverCustomer和GoldCustomer都扩展了客户.
在申请中,客户获得旅行积分.普通客户获得他们前往积分的里程数.SilverCustomer获得里程*1.5,GoldCustomer获得里程*2分.
当我创建一个普通的客户John时,如何使用方法降级()和升级()在普通客户,silvercustomer和goldcustomer之间切换?
class Testfile {
public static void main(String[] args) {
Airline aProgram = new Airline();
Customer john = new Customer("john", 10001); // 10001 is the id number and the status of a customer is normal
aProgram.addMembers(john);
john.update_mileage(12000);
john.upgrade(); //upgrade John to SilverCustomer
john.update_mileage(2000);
aProgram.printAllCustomerMilege();
}
}
Run Code Online (Sandbox Code Playgroud) 我有下表:
CREATE TABLE [dbo].[MyTable](
[timestamp] [timestamp] NOT NULL,
[Col1] [varchar](20) NOT NULL,
[Col2] [varchar](20) NOT NULL,
[col3] [datetime] NOT NULL,
[col4] [varchar](10) NOT NULL,
[Col5] [varchar](10) NOT NULL,
[Col6] [varchar](10) NOT NULL,
[Col7] [decimal](38, 20) NOT NULL,
[Col8] [decimal](38, 20) NOT NULL,
[Col9] [datetime] NOT NULL,
CONSTRAINT [MyTable$0] PRIMARY KEY CLUSTERED
(
[Col1] ASC,
[Col2] ASC,
[Col3] ASC,
[Col4] ASC,
[Col5] ASC,
[Col6] ASC,
[Col7] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, …Run Code Online (Sandbox Code Playgroud) 我的班级有一个Enum作为属性.它使用String来设置此attr.有许多枚举类.我怎么能重构它?
public void setType(String s) {
for (MyEnum1 e : MyEnum1.values()) {
if (e.name().equalsIgnoreCase(s))
this.type = e;
}
for (MyEnum2 e : MyEnum2.values()) {
if (e.name().equalsIgnoreCase(s))
this.type = e;
}
for ...
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我对这两个查询的结果感到惊讶.我期待两者都一样.我有两个共享一个共同字段的表,但没有设置关系.table(A)有一个字段EventID varchar(10),table(B)有一个字段XXNumber varchar(15).
表B列XXNumber中引用了表A列中的值EventID.即使XXNumber可以容纳15个字符,179K行数据也不会超过10个字符.
所以要求是:
"为了避免重复表B和表A条目,如果XXNumber包含在表A>"事件ID"中,则不应计算它."
要查看我有多少常见记录,我首先运行此查询 - 称之为查询alpha"
SELECT dbo.TableB.XXNumber FROM dbo.TableB WHERE dbo.TableB.XXNumber in
( select distinct dbo.TableA.EventId FROM dbo.TableA )
Run Code Online (Sandbox Code Playgroud)
结果是5322行.
以下查询 - 将其称为查询delta,如下所示:
SELECT DISTINCT dbo.TableB.XXNumber, dbo.TableB.EventId
FROM dbo.TableB INNER JOIN dbo.TableA ON dbo.TableB.XXNumber= dbo.TableB.EventId
Run Code Online (Sandbox Code Playgroud)
哈斯返回4308行.
结果行数不应该相同吗?
有没有办法将一些功能移动到谷歌应用程序脚本中的单独文件?目前我的Code.gs如下所示:
function onSubmit(e) {}
function readSpreadsheet(sheet) {}
function writeSpreadsheet(sheet, data) {}
function sendEmail() {}
function helperLogic1() {}
function helperLogic2() {}
function helperLogic3() {}
function helperLogic4() {}
Run Code Online (Sandbox Code Playgroud)
因此,为了使我的代码看起来更好; p ..我想将与电子表格相关的函数移动到spreadsheet.gs电子邮件到email.gs等.所以在移动它们之后,如何从中加载它code.gs?
谢谢
我正在编写一个反应组件,当单击前进handleClickLeft或后退 handleClickRight按钮时,它会向前或向后循环遍历数组。我通过使用模逻辑来做到这一点。我能够让前进按钮handleClickLeft正常工作,但我不知道如何反向操作handleClickRight。这是我的示例代码:
export default class Rooms extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {indexPos: [0, 1, 2]};
this.state.itemArry = [{room1: 'this is room1'}, {room2: 'this is room2'}, {room3: 'this is room3'}, {room4: 'this is room4'}];
this.handleClickLeft = this.handleClickLeft.bind(this);
this.handleClickRight = this.handleClickRight.bind(this);
}
render() { //Using index to show each item in the itemArry
let firstItem = this.state.indexPos[0]
let secondItem = this.state.indexPos[1]
let thirdItem = this.state.indexPos[2]
<div>
<ul>
<li>this.state.itemArry[firstItem]</li>
<li>this.state.itemArry[secondItem]</li>
<li>this.state.itemArry[thirdItem]</li> …Run Code Online (Sandbox Code Playgroud) java ×5
refactoring ×5
javascript ×2
sql ×2
.net ×1
arrays ×1
casting ×1
char ×1
enums ×1
inheritance ×1
int ×1
interface ×1
modulus ×1
reactjs ×1
sql-server ×1