我有以下数组.
<cfset ItemHasUsers = arrayNew(1)>
<cfloop query="qReadData">
<cfset ItemHasUsers[qReadData.currentrow]["ID"] = qReadData.ID >
<cfset ItemHasUsers[qReadData.currentrow]["Asset"] = qReadData.COUNTOFITEMS >
</cfloop>
Run Code Online (Sandbox Code Playgroud)
我从我的数据库中获取了一些记录,这些记录放入表中并通过表单进行操作.
<form action="same-site.cfm method="post">
<table>
<tr>
<th>ID</th>
<th>Asset</th>
<th>Delete</th>
<tr>
<cfset ItemHasUsers = Item.getItemHasUsers() >
<cfoutput>
<cfloop index="i" from="1" to="#arrayLen(ItemHasUsers)#">
<td>#ItemHasUsers[i]["ID"]#</td>
<td><input type="text" name="upd_#ItemHasUsers[i]["ID"]#" maxlength="6" size="6" value="#ItemHasUsers[i]["Asset"]#"></td>
<td><input type="checkbox" name="del_#ItemHasUsers[i]["ID"]#"></td>
</tr>
</cfloop>
</cfouput>
</table>
<input type="submit" value="OK">
</form>
Run Code Online (Sandbox Code Playgroud)
依赖我的输入我想更新我的数据库.目前我循环通过表单结构来清除我想要删除的用户.看起来很丑,但我不知道更好的方法 - >看初学者标签;)
<cfset ItemHasUsers = Item.getItemHasUsers() >
<cfloop collection="#form#" item="key">
<cfif left(key,len("DEL_")) eq ("DEL_")>
<cfset Id = listLast(key,"_") >
<cfloop index="i" from="1" to="#arrayLen(ItemHasUsers)#"> …Run Code Online (Sandbox Code Playgroud) 我正在自学java,我在Thinking in Java中进行练习.
在第116页,练习11,您应该右移一个整数到其所有二进制位置,并使用Integer.toBinaryString显示每个位置.
public static void main(String[] args) {
int i = 8;
System.out.println(Integer.toBinaryString(i));
int maxIterations = Integer.toBinaryString(i).length();
int j;
for (j = 1; j < maxIterations; j++) {
i >>= 1;
System.out.println(Integer.toBinaryString(i));
}
Run Code Online (Sandbox Code Playgroud)
在解决方案指南中,输出如下所示:
1000
1100
1110
1111
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,我得到这个:
1000
100
10
1
Run Code Online (Sandbox Code Playgroud)
这里发生了什么.数字是否被截断?
我使用的是jdk1.6.0_20 64bit.这本书使用jdk1.5 32bit.
我需要在oracle中加入子查询.这不起作用我得到连接操作的语法错误
select s1.key, s1.value, s2.value
from ((select key, value
from tbl
where id = 1) as s1
join
(select key, value
from tbl
where id = 2) as s2
on s1.contract = s2.contract);
Run Code Online (Sandbox Code Playgroud) 我有这个方法:
public static long sumDigits(final List<Long> list) {
return list
.stream()
.map(l -> toDigits(l))
.flatMapToLong(x -> x.stream())
.sum()
}
Run Code Online (Sandbox Code Playgroud)
toDigits有这个签名:
List<Long> toDigits(long l)
Run Code Online (Sandbox Code Playgroud)
在flatMapToLong行上,它给出了这个错误
类型不匹配:无法从Stream <Long>转换为LongStream
当我改为
flatMapToLong(x -> x)
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
类型不匹配:无法从List <Long>转换为LongStream
唯一有效的是这个
public static long sumDigits(final List<Long> list) {
return list
.stream()
.map(l -> toDigits(l))
.flatMap(x -> x.stream())
.reduce(0L, (accumulator, add) -> Math.addExact(accumulator, add));
}
Run Code Online (Sandbox Code Playgroud) 这是我的班级:
public class Test {
Test(){
new Webshop
(new Warenkorb[]{"Max", new Artikel[]{new Artikel("AAA",3.0)},
"Joe", new Artikel[]{new Artikel("BBB",3.0),
new Artikel("CCC",3.0)}
},
new Warenkorb[]{"Sam", new Artikel[]{new Artikel("BBB",3.0),
new Artikel("CCC",3.0)}
},
);
}
}
Run Code Online (Sandbox Code Playgroud)
这些是我的构造者:
Artikel(String name, double preis){
this.name = name;
verkaufspreis = preis;
Art = Warengruppe.S;
Warenkorb(String kunde, Artikel[] artikel){
this.kunde = kunde;
artikelliste = artikel;
sessionid = s.nextInt();
summe = 0;
for(Artikel preis : artikel){
summe += preis.verkaufspreis;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到了类型不匹配错误
测试类(String []无法解析为Warenkorb [] | Artikel []无法解析为Warenkorb).
我该如何解决这些错误?
我在我的cfm中有这个代码,它有效
<cfif not StructIsEmpty(form)>
<cfset larray = user.getArray() />
<cfloop collection="#form#" item="key">
<cfif left(key,4) eq "UPD_">
<cfset x = listLast(key,"_") />
<cfset y = evaluate(0,key) />
<cfloop index="j" from="1" to="#arrayLen(larray)#">
<cfif (larray[j][1] eq x) and (larray[j][3] neq y)>
<cfset larray[j][3] = y />
<cfif not LSIsNumeric(larray[j][3])>
<cfset larray[j][3] = "0" />
</cfif>
<cfset larray[j][4] = "update" />
</cfif>
</cfloop>
</cfif>
</cfloop>
<cfloop collection="#form#" item="key">
<cfif left(key,4) eq "DEL_">
<cfset x = listLast(key,"_") />
<cfloop index="k" from="1" to="#arrayLen(larray)#">
<cfif larray[k][1] eq …Run Code Online (Sandbox Code Playgroud) 我正在使用Visual Studio 2010和git(git svn).我的同事使用纯svn和Ankhsvn插件.
当我尝试在启用Git源代码控制提供程序的情况下打开文件时,Visual Studion会抱怨:
源控制插件
活动解决方案或项目由与您选择的插件相关的源控制插件控制.如果更改源控件插件,将关闭活动解决方案或项目.
你想继续吗?
当我单击是时,将打开一个空的解决方案.当我单击否时,解决方案项旁边的所有git特定图标都会丢失(我仍然会在解决方案资源管理器中看到分支名称),每次打开解决方案时都会收到有关源控件插件的提示.
当我克隆我的同事创建的svn存储库时,解决方案sln文件包含以下内容
GlobalSection(SubversionScc)= preSolution
Svn-Managed = True
Manager = AnkhSVN - 对Visual Studio
EndGlobalSection的 Subversion支持
我已经删除了这一部分,现在解决方案在Git源代码控制提供程序被激活时没有问题,但是当您选择Ankhsvn提供程序时会抱怨 - 情况正好相反.
我想告诉git在pull(git svn fetch)期间删除.sln文件的这一部分,并在我提交时添加它(git svn dcommit).这可能通过gitattributes以及如何做到这一点?
编辑:
我现在补充说
solutionname.sln filter = ankhsvn
到$ GIT_DIR/info/attributes
和
[filter "ankhsvn"]
clean=sed '/^Global$/ r ../ankhsvnsection '
smudge=sed '/GlobalSection(SubversionScc)/,/EndGlobalSection/d '
Run Code Online (Sandbox Code Playgroud)
到我的.git/config文件.
ankhsvnsection包含由涂抹操作删除的部分.我似乎什么也没做?!
我是第一次嘲笑和尝试moq的新手.我想知道我是否只能使用模拟编写测试?
public class FileCopierTests
{
private string path = AppDomain.CurrentDomain.BaseDirectory;
[Fact]
public void Copy_starts_copying_when_event_is_fired_returns_true()
{
var fullyQualifiedFileName = string.Format(@"{0}\..\..\Integration\TestData.xls", this.path);
var destFileName = Path.GetTempPath() + "66768c06-d1c4-4416-be81-767f36abeeb1.xls";
var copierMock = new Mock<IFileCopier>();
var watcherMock = new Mock<IFileWatcher>();
copierMock.Setup(cp => cp.Copy(fullyQualifiedFileName, destFileName)).Raises(
ev => ev.CopyingFinished += null, destFileName);
watcherMock.Object.Changed += arg => copierMock.Object.Copy(arg, destFileName);
watcherMock.Raise(e => e.Changed += null, fullyQualifiedFileName);
copierMock.VerifyAll();
}
}
Run Code Online (Sandbox Code Playgroud)
这些是我想要测试的类和接口,
public interface IFileCopier
{
event Action<string> CopyingFinished;
void Copy(string fqFileName, string destFileName);
}
public class FileCopier : IFileCopier …Run Code Online (Sandbox Code Playgroud) 我有这个测试
[Fact]
public void Get_if_item_is_not_in_cache_return_null_returns_true()
{
var repo = new Repository<IProduct>(
this.factoryMock.Object,
this.cacheMock.Object,
this.readerMock.Object,
this.storageMock.Object);
var key = 1;
const string Name = "Product1";
var date = new DateTime(0, DateTimeKind.Utc);
var product1 = this.Product; /* returns new Product(
* "Product1",
* new DateTime(0, DateTimeKind.Utc),
* new Dictionary<string, decimal>
* { { "@1lom", 0m }, { "@2lom", 0m } }) */
this.cacheMock.Setup(
m => m.Add(key, product1)).Returns(product1);
this.cacheMock.Setup(
m => m.Get<IList<IDictionary<string, object>>>(0)).Returns(null as IList<IDictionary<string, object>>);
this.cacheMock.Setup(
m => m.Get<IProduct>(key)).Returns(null as IProduct);
this.factoryMock.Setup( …Run Code Online (Sandbox Code Playgroud) 我想获得两个日期之间的所有夏令时(DST)小时.
这是我的示例代码:
public static void main(String[] args) {
Date startDate = new Date();
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(startDate);
startCalendar.set(2014, 2, 1, 0, 0, 0);
startCalendar.set(Calendar.MILLISECOND, 0);
Date endDate = new Date();
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(endDate);
endCalendar.set(2014, 2, 31, 0, 0, 0);
endCalendar.set(Calendar.MILLISECOND, 0);
DateTime startDateTime = new DateTime(startCalendar);
DateTime endDateTime = new DateTime(endCalendar).plusDays(1);
Hours hours = Hours.hoursBetween(startDateTime, endDateTime);
// actual is 744
System.out.println("Expected: 743, actual: " + hours.getHours());
}
Run Code Online (Sandbox Code Playgroud)
好吧,我显然错过了一些东西,但我无法发现我的错误.
任何人都可以解释为什么我必须转换为T,为什么Add2不接受Bar作为参数?
class Foo<T> where T : class, IBar
{
void Add1(IDo<T> @do) { @do.Stuff(new Bar() as T); }
// Add2 does not compile:
// Argument type Bar is not assignable to parameter Type T
void Add2(IDo<T> @do) { @do.Stuff(new Bar()); }
}
interface IBar {}
class Bar : IBar {}
interface IDo<in T> {
void Stuff(T bar);
}
Run Code Online (Sandbox Code Playgroud)