必须与Liz的自定义OP(在下面的评论中)一起去。
sub prefix:<²^>(uint $a) { (+^ $a) + 1 }
say ²^ 18446744073709551592; # 24
野生猜测”² @zentrunix可以接受,也是Liz's Op的基础:
say (+^ my uint $ = 18446744073709551592) + 1; # 24
/它起作用!
\ o
我原来的“半教育的 +^表格,将其子数字作为“两个补充”,然后避免看起来像^2
。
²一条思维是关于特定整数的。我看到 184444444073709551592
接近 2 ** 64
。另一个是,除非您采取其他行动使它们做某事,否则整数在Perl中的精度有限,而在Raku中,除非您做某事以使它们有其他方式,否则它们是任意的精度。第三条思维来自阅读 prefix +^
说“使用所需的任意多字符将数字转换为二进制”这意味着表示形式很重要。唔。如果我尝试 int
变量怎么办?溢出。 (当然。) uint
?宾果游戏。
³我不知道此解决方案是否是正确的,原因是出于错误的原因。甚至更糟。关于Raku中的 uint
的一件事定义为对应于用于编译Raku代码的RAKU编译器支持的最大的本机无符号整数大小。 (iirc。)实际上,这意味着Rakudo和任何基础平台的目标,我认为几乎在几乎所有情况下,这几乎可以肯定意味着C的 uint64_t
。我想 perl
具有一些相似的平台依赖性定义。因此,如果我的解决方案(如果是合理的解决方案),则可能仅适用于Raku编译器(实际上在今天意味着Rakudo)与 perl
二进制(实际上在今天,今天意味着P5P的 perl )在某个平台上运行时。另请参阅下面的 @P6Steve的评论。
好吧,根据评论&amp;问题似乎您需要在下面做:
public static void main(String[] args) {
try {
File file = new File("/Downloads/student.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Company.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Student com= (Student) jaxbUnmarshaller.unmarshal(file);
List<Student> list = com.getStudent();
list.stream().forEach(stu->{
if(stu.getGender().equalsIgnoreCase("M")){
//write to file where Male gender details can be stored.
}
else {
//write to file where Male gender details can be stored.
}
});
}
}}
在这里,您可以获取流&amp;比较每个元素&amp;按元素写入各自的文件元素。
请注意,您可以在 main
开始时声明文件。
编辑:当您正在寻找多级分组时,我的建议是:
Map<String, Map<String, List<Student>>> map = list.stream()
.collect(Collectors.groupingBy(x -> x.getGender(), Collectors.groupingBy(y -> y.getAddress().getZipCode())));
此地图具有基于性别和ZIP的数据汇总。迭代这张地图&amp;将详细信息放入不同的文件中。
在您的书籍课
public function author(){
return $this->belongsTo(Author::class);
}
和控制器上执行此操作:
public function index(){
$books=Book::with('author')->get();
return response()->json([
"books" => $books
], 200);
}
使用插入...选择
和交叉加入
表:
INSERT INTO IDMAPPING (metricid, storeid)
SELECT m.metrictid, s.storeid
FROM METRIC m
CROSS JOIN store s
WHERE m.metrictid = 50441
AND s.storeid = 18198;
或只使用PL/SQL并捕获错误:
DECLARE
parent_key_not_found EXCEPTION;
PRAGMA EXCEPTION_INIT(parent_key_not_found, -2291);
BEGIN
INSERT INTO idmapping (metricid, storeid) VALUES (50441, 18198);
EXCEPTION
WHEN parent_key_not_found THEN
-- Ignore the exception
NULL;
END;
/
db&lt;&gt; fiddle 在这里
您可以使用按钮配置iOS 15:
private func makeButton(withTitle title: String) -> UIButton {
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
var configuration = UIButton.Configuration.filled()
configuration.title = title
configuration.baseBackgroundColor = .blue
configuration.contentInsets = NSDirectionalEdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16)
button.configuration = configuration
return button
}
您可以在创建按钮时简单地调用此方法,如下所示:
let button = makeButton(withTitle: "Get Started")
我认为您应该使用 debugger.isattached
与语句结合使用:
public void Recursion(int depth) {
if (Debugger.IsAttached) {
//do something with depth
}else {
//do something without depth
}
}
您可以使用 grid 。更改按钮的尺寸时,这将更加健壮。
.act_button {
width: 200px;
height: 100px;
background-color: #ADD8E6;
border: none;
display: grid;
grid-template-columns: auto auto;
place-content: space-between;
}
.act_button>span {
padding: 5px;
}
<body>
<button class="act_button" type="button">
<span>Top left</span>
<span>Top right</span>
<span>Bottom left</span>
<span>Bottom right</span>
</button>
</body>
要处理道具的类型,您可以做:
type Props = ({ multiple: true; value: Item[] } | { multiple: false; value: Item }) & { label: string, ... }
然后,如果您检查props.multiple,它将成为一个物品数组。但是,诸如状态之类的事情仍然可能最终以项目| item []
作为输入字样无法有效地跟踪(即使您的组件也可能会从多个= true - &gt; false更改,并且状态仍然是一个数组!)。为此,通常在组件中处理两种情况并在需要时断言类型可能是最简单的。
我看过的另一个常见选择是:
type Props<IsMultiple extends boolean> = {
isMultiple: IsMultiple;
value: IsMultiple extends true ? Item[] : Item;
}
这种方法的问题是,虽然 props&lt; true&gt;
and props&lt; false&gt;
既正确键入(因此通常会输入typescript) {ismultiple:false,value:[]}不允许,因为它假定 props&lt; false&gt;
), props&lt; boolean&gt;
技术上允许iSmultiple和值不匹配。因此,检查props.ismultiple是否也不会打字值。
如果有人需要“财务圆形”(总是0.5回合):
from decimal import ROUND_HALF_UP, Decimal, localcontext
def myround(x, base: int = 5):
# starting with Python 3.11:
# with localcontext(rounding=decimal.ROUND_HALF_UP):
with localcontext() as ctx:
ctx.rounding = ROUND_HALF_UP
return base * int(decimal.Decimal(x / base).quantize(Decimal('0')))
按文档圆形选项为:
-
round_ceiling
(to infinity ) -
round_down
(to Zero) -
round> round_floor
(to -Infinity ) -
round_half_down
(到最接近零的关系) -
round_half_even
(到最接近的纽带,均为最接近整数) -
round_half_up
(到距离零的领带最接近) -
round_up
(远离零) -
round_05up
是0或5;
默认情况下,python
我现在看到它写下来后,这个答案在某种程度上是 Matthew Watson 和维克多,但无论如何我都会提供。
首先,我同意维克多的观点,即摆脱所有筑巢是一个重要的进步。我也同意他们的观点,将您的代码分为方法在这方面可能非常有帮助。
其次,我同意Matthew的观点,如果 DO的结果
可以直接用于定义条件3
的结果,也可以直接使用它,而不是将其调用在评估条件3
之前。
如果可以将条件3
提取到将 do a
作为输入参数结果的方法中提取,则可以通过在每个嵌套级别创建一个方法来完全避免嵌套。例如:
public static void Main()
{
DoYourThing();
do E;
}
DoYourThing()
{
if (<condition1>)
{
DoYourNextThing();
}
else
{
do D;
}
}
DoYourNextThing()
{
if (<condition2> && Condition3(A()))
{
do B;
}
else
{
do C;
}
}
private bool Condition3(object a)
{
//...
}
如果条件3
不能将其提取到将 do do a
作为输入参数的结果的方法中, doyournextthing( )
可能需要以不同的方式实现。一种可能性是:
DoYourNextThing()
{
if (ShouldDoB())
{
do B;
}
else
{
do C;
}
}
ShouldDoB()
{
if (!condition2)
{
return false;
}
var a = do A;
return condition3; // based on a
}
作为旁注,我要说的是,使用描述性变量名称和方法名称通常比重构嵌套循环更为重要。而做 (以增强理解和可读性的方式)是黄金。
话虽这么说,我相信OP只是使用通用名称,只是为他们试图实现的逻辑提供了一个清晰,简单的例子。
注意:下面给出的代码是解决问题的一种方法,可能不是最好的方法。代码中的一切都可以改变。如果您在环境变量中没有mySQL,请在mysqldump和mysql之前添加路径(例如xampp,c:\ xampp \ mysql \ mysql \ bin \ mysqldump)
(希望,这会解决您的问题。完全找出所有内容并正确地实现)
备份方法:
public static void Backupdbtosql() {
try {
/*NOTE: Getting path to the Jar file being executed*/
/*NOTE: YourImplementingClass-> replace with the class executing the code*/
CodeSource codeSource = YourImplementingClass.class.getProtectionDomain().getCodeSource();
File jarFile = new File(codeSource.getLocation().toURI().getPath());
String jarDir = jarFile.getParentFile().getPath();
/*NOTE: Creating Database Constraints*/
String dbName = "YourDBName";
String dbUser = "YourUserName";
String dbPass = "YourUserPassword";
/*NOTE: Creating Path Constraints for folder saving*/
/*NOTE: Here the backup folder is created for saving inside it*/
String folderPath = jarDir + "\\backup";
/*NOTE: Creating Folder if it does not exist*/
File f1 = new File(folderPath);
f1.mkdir();
/*NOTE: Creating Path Constraints for backup saving*/
/*NOTE: Here the backup is saved in a folder called backup with the name backup.sql*/
String savePath = "\"" + jarDir + "\\backup\\" + "backup.sql\"";
/*NOTE: Used to create a cmd command*/
String executeCmd = "mysqldump -u" + dbUser + " -p" + dbPass + " --database " + dbName + " -r " + savePath;
/*NOTE: Executing the command here*/
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
/*NOTE: processComplete=0 if correctly executed, will contain other values if not*/
if (processComplete == 0) {
System.out.println("Backup Complete");
} else {
System.out.println("Backup Failure");
}
} catch (URISyntaxException | IOException | InterruptedException ex) {
JOptionPane.showMessageDialog(null, "Error at Backuprestore" + ex.getMessage());
}
}
还原方法:
public static void Restoredbfromsql(String s) {
try {
/*NOTE: String s is the mysql file name including the .sql in its name*/
/*NOTE: Getting path to the Jar file being executed*/
/*NOTE: YourImplementingClass-> replace with the class executing the code*/
CodeSource codeSource = YourImplementingClass.class.getProtectionDomain().getCodeSource();
File jarFile = new File(codeSource.getLocation().toURI().getPath());
String jarDir = jarFile.getParentFile().getPath();
/*NOTE: Creating Database Constraints*/
String dbName = "YourDBName";
String dbUser = "YourUserName";
String dbPass = "YourUserPassword";
/*NOTE: Creating Path Constraints for restoring*/
String restorePath = jarDir + "\\backup" + "\\" + s;
/*NOTE: Used to create a cmd command*/
/*NOTE: Do not create a single large string, this will cause buffer locking, use string array*/
String[] executeCmd = new String[]{"mysql", dbName, "-u" + dbUser, "-p" + dbPass, "-e", " source " + restorePath};
/*NOTE: processComplete=0 if correctly executed, will contain other values if not*/
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
/*NOTE: processComplete=0 if correctly executed, will contain other values if not*/
if (processComplete == 0) {
JOptionPane.showMessageDialog(null, "Successfully restored from SQL : " + s);
} else {
JOptionPane.showMessageDialog(null, "Error at restoring");
}
} catch (URISyntaxException | IOException | InterruptedException | HeadlessException ex) {
JOptionPane.showMessageDialog(null, "Error at Restoredbfromsql" + ex.getMessage());
}
}
您可以创建一个具有服务方法定义的 a ,并使两个服务都实现了该摘要类(在打字稿中,您可以像一个摘要类一样界面)
在您的组件 c
注入构造函数中的抽象类(与接口不同,抽象类可用作注入令牌),
constructor(private service: A)
在 c ,提供相关服务
// replace useExisting with useClass if
// the service isn't already available
@Component({
selector: 'parent-one',
/* . . . */
providers: [{
provide: A, useExisting: S
}]
})
@Component({
selector: 'parent-two',
/* . . . */
providers: [{
provide: A, useExisting: S2
}]
})
不可避免地会创建新的索引。当您从一个数组移动到另一个数组时,它需要一个索引才能知道该项目的位置。
实际上,即使您在同一列表中更改项目的位置(同一数组),即使在此项目索引更改,也会因更改而影响的所有其他项目,并且由于单个项目的更改,因此更改了其他项目的索引(+1 / -1)。
todo = ['Get to work', 'Pick up groceries', 'Go home', 'Fall asleep'];
done = ['Get up', 'Brush teeth', 'Take a shower', 'Check e-mail', 'Walk dog'];
drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex); // when change happens in same array (same list)
this.eventIndex = [event.previousIndex,event.currentIndex];
} else {
transferArrayItem(
event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex,
);
this.eventIndex = [event.previousIndex,event.currentIndex]; // when changes arrays (lists)
}
}
/** Index of the item when it was picked up. */
previousIndex: number;
/** Current index of the item. */
currentIndex: number;
/** Item that is being dropped. */
item: CdkDrag<I>;
/** Container in which the item was dropped. */
container: CdkDropList<T>;
/** Container from which the item was picked up. Can be the same as the `container`. */
使用BindingSource查找方法时,如何允许null TextBox?