喜你已久

文章 评论 浏览 31

喜你已久 2025-02-14 08:37:13

您的代码甚至编译吗? stateObject 应具有默认值。这样的事情:

@StateObject var customColors = CustomColorScheme()

能够观察动画,首先需要发生的事情是查看Redraw。更改 darkModeenabled 值可以迫使Redraw。

要查看动画,您将有类似的东西:

.foregroundColor(customColors.darkModeEnabled)
.animation(Animation.easeIn(duration: 2), value: customColors.darkModeEnabled)

Does your code even compile? StateObject should have a default value. Something like this:

@StateObject var customColors = CustomColorScheme()

To be able to observe an animation, the first thing that needs to happen is view redraw. Change in darkModeEnabled value can force the redraw.

To view the animation, you'd have something like:

.foregroundColor(customColors.darkModeEnabled)
.animation(Animation.easeIn(duration: 2), value: customColors.darkModeEnabled)

在Swiftui中更改整个应用程序的颜色的最佳方法

喜你已久 2025-02-14 08:19:41

使用诸如替换之类的字符串方法:

String newString = oldString.replace("}}", "}")

如果是情况或其他情况;您只能在铸造到字符串的情况下才能使用字符串API的任何方法

Use a String method like replace:

String newString = oldString.replace("}}", "}")

if that´s case or another one; you can use anywhere of methods of String API only if casts to String

如何从jmeter中的字符串中删除最后一个字符

喜你已久 2025-02-14 07:52:42
library(tidypaleo)

model <- age_depth_model(
  depth = cars$min,
  age = cars$depth
)



ggplot(cars, aes(x = depth, y = car)) +
  geom_line() +
  scale_x_age_depth(model, depth_name = "min") +
  ggtitle("CARLHB") +
  xlab("Depth (cm)") +
  geom_point() +
  ylab(bquote(Carbon~Accumulation~(g~C/m^2/yr^-1)))


希望有效!

library(tidypaleo)

model <- age_depth_model(
  depth = cars$min,
  age = cars$depth
)



ggplot(cars, aes(x = depth, y = car)) +
  geom_line() +
  scale_x_age_depth(model, depth_name = "min") +
  ggtitle("CARLHB") +
  xlab("Depth (cm)") +
  geom_point() +
  ylab(bquote(Carbon~Accumulation~(g~C/m^2/yr^-1)))

enter image description here
hope that works !

在一个GGPLOT上绘制两个X轴

喜你已久 2025-02-14 07:35:07

如果您只是覆盖 value ,则必须传递所有其他属性,因此您有2个选项来完成此操作。

选项1

您只需将 name 传递给该功能,然后仅更改该值。

import { createSlice } from '@reduxjs/toolkit'

const initialState = {
   name: "name",
   email: "",
   age: "",
   hobby: "",
   grade:""
}

export const userSlice = createSlice({
  name: 'user',
  initialState,
  reducers: {
    login: (state,action) => {
        state.name = action.payload
    }
  },
})

export const { login } = userSlice.actions

export default userSlice.reducer

然后您这样称呼。

if (value.topic=="cred") {

  console.log(value.username)
  dispatch(login(value.username));
  console.log("Value dispatched",user.name)
}

选项2

您可以使用相同的还原器修改不同的字段,即使我建议创建更多的还原器。

import { createSlice } from '@reduxjs/toolkit'

const initialState = {
   value: {
      name: "name",
      email: "",
      age: "",
      hobby: "",
      grade:""
   }
}

export const userSlice = createSlice({
  name: 'user',
  initialState,
  reducers: {
    login: (state,action) => {
        state.value = action.payload
    }
  },
})

export const { login } = userSlice.actions

export default userSlice.reducer

然后您这样称呼。

const user = useSelector((state) => state.user)

if (value.topic=="cred") {

  console.log(value.username)
  dispatch(login({...user, name: value.username})); // You can modify also multiple value at once with {...user, name: value.username, hobby: "Something"}
  console.log("Value dispatched",user.name)
}

If you just overwrite value you have to pass all the other properties as well, so you have 2 options to accomplish this.

Option 1

You just pass name to the function and then change only that value.

import { createSlice } from '@reduxjs/toolkit'

const initialState = {
   name: "name",
   email: "",
   age: "",
   hobby: "",
   grade:""
}

export const userSlice = createSlice({
  name: 'user',
  initialState,
  reducers: {
    login: (state,action) => {
        state.name = action.payload
    }
  },
})

export const { login } = userSlice.actions

export default userSlice.reducer

And then you call it like this.

if (value.topic=="cred") {

  console.log(value.username)
  dispatch(login(value.username));
  console.log("Value dispatched",user.name)
}

Option 2

You're able to modify different field with the same reducer, even though I suggest creating more reducers.

import { createSlice } from '@reduxjs/toolkit'

const initialState = {
   value: {
      name: "name",
      email: "",
      age: "",
      hobby: "",
      grade:""
   }
}

export const userSlice = createSlice({
  name: 'user',
  initialState,
  reducers: {
    login: (state,action) => {
        state.value = action.payload
    }
  },
})

export const { login } = userSlice.actions

export default userSlice.reducer

And then you call it like this.

const user = useSelector((state) => state.user)

if (value.topic=="cred") {

  console.log(value.username)
  dispatch(login({...user, name: value.username})); // You can modify also multiple value at once with {...user, name: value.username, hobby: "Something"}
  console.log("Value dispatched",user.name)
}

使用Redux工具套件更新一个参数

喜你已久 2025-02-14 03:55:34

好的,所以我找到了解决我的问题的解决方案。但是我没有回答我的问题。

我仍然想知道是否有更多的Pythonic方法可以做到这一点...因此,欢迎您提出更好答案的任何人!

请注意,我没有试图从数据框架中获取答案,而是我只是提取了每种情况的开始和停止时间,然后获得了每个情况的最分钟,以回答最终问题。

df = pd.DataFrame.from_dict({'datetime': {0: '07/06/2022 12:09', 1: '07/06/2022 12:09', 2: '07/06/2022 12:09', 3: '07/06/2022 12:09', 4: '07/06/2022 12:09', 5: '07/06/2022 12:09', 6: '07/06/2022 12:09', 7: '07/06/2022 12:09', 8: '07/06/2022 12:09', 9: '07/06/2022 12:09', 10: '07/06/2022 12:09', 11: '07/06/2022 12:09', 12: '07/06/2022 12:09', 13: '07/06/2022 12:09'}, 'flag1': {0: False, 1: False, 2: False, 3: True, 4: True, 5: True, 6: True, 7: True, 8: True, 9: True, 10: False, 11: False, 12: False, 13: False}, 'flag2': {0: False, 1: False, 2: True, 3: True, 4: True, 5: True, 6: True, 7: True, 8: False, 9: False, 10: False, 11: False, 12: False, 13: False}, 'flag3': {0: False, 1: False, 2: False, 3: True, 4: True, 5: True, 6: True, 7: False, 8: False, 9: False, 10: False, 11: False, 12: False, 13: False}, 'flag4': {0: False, 1: False, 2: False, 3: True, 4: True, 5: True, 6: True, 7: True, 8: True, 9: True, 10: False, 11: False, 12: False, 13: False}, 'value1': {0: 179.012, 1: 179.012, 2: 179.012, 3: 179.012, 4: 179.012, 5: 179.012, 6: 179.012, 7: 179.012, 8: 179.012, 9: 179.012, 10: 179.012, 11: 179.012, 12: 179.012, 13: 179.012}, 'value2': {0: -101.39, 1: -101.39, 2: -101.41, 3: -101.39, 4: -101.43, 5: -101.43, 6: -101.43, 7: -101.46, 8: -101.4, 9: -101.39, 10: -101.39, 11: -101.43, 12: -101.43, 13: -101.38}, 'state': {0: 'IDLE', 1: 'ON', 2: 'ON', 3: 'ON', 4: 'ACTIVE', 5: 'ACTIVE', 6: 'ACTIVE', 7: 'ACTIVE', 8: 'ACTIVE', 9: 'ACTIVE', 10: 'ACTIVE', 11: 'ACTIVE', 12: 'IDLE', 13: 'IDLE'}})

flag1 = 'flag1'
flag2 = 'flag2'
flag3 = 'flag3'
flag4 = 'flag4'

# test cases
# df.drop('flag1', axis = 1,inplace=True)
# df.drop('flag2', axis = 1,inplace=True)
# df.drop('flag3', axis = 1,inplace=True)
# df.drop('flag4', axis = 1,inplace=True)

#the valid indexes
valstart = []
valend = []

flaglist = [flag1, flag2, flag3, flag4]
curflag = flag1
for curflag in flaglist:
      if curflag in df.columns and (df[curflag] == True).any():
            #find the start and end of the case
            valstart.append(df[(df[curflag] == True)].index[0])
            valend.append(df[(df[curflag] == True)].index[-1])

anystart = min(valstart)
allstart = max(valstart)
anyend = max(valend)
allend = min(valend)

whenAllAreTrueAtTheSameTime = df[allstart:allend+1]
whenAnyareTrueAtTheSameTime  = df[anystart:anyend+1]

OK, So I found A solution to my problem. However I did not answer my question.

I am still wondering if there is a more PYTHONIC way to do this... so anyone who comes up with a better answer is welcome to try!

Note that instead of trying to brute force get the answer from the dataframe I just extracted the start and stop times of each case and then got the mins and maxes of each one in order to answer the final question.

df = pd.DataFrame.from_dict({'datetime': {0: '07/06/2022 12:09', 1: '07/06/2022 12:09', 2: '07/06/2022 12:09', 3: '07/06/2022 12:09', 4: '07/06/2022 12:09', 5: '07/06/2022 12:09', 6: '07/06/2022 12:09', 7: '07/06/2022 12:09', 8: '07/06/2022 12:09', 9: '07/06/2022 12:09', 10: '07/06/2022 12:09', 11: '07/06/2022 12:09', 12: '07/06/2022 12:09', 13: '07/06/2022 12:09'}, 'flag1': {0: False, 1: False, 2: False, 3: True, 4: True, 5: True, 6: True, 7: True, 8: True, 9: True, 10: False, 11: False, 12: False, 13: False}, 'flag2': {0: False, 1: False, 2: True, 3: True, 4: True, 5: True, 6: True, 7: True, 8: False, 9: False, 10: False, 11: False, 12: False, 13: False}, 'flag3': {0: False, 1: False, 2: False, 3: True, 4: True, 5: True, 6: True, 7: False, 8: False, 9: False, 10: False, 11: False, 12: False, 13: False}, 'flag4': {0: False, 1: False, 2: False, 3: True, 4: True, 5: True, 6: True, 7: True, 8: True, 9: True, 10: False, 11: False, 12: False, 13: False}, 'value1': {0: 179.012, 1: 179.012, 2: 179.012, 3: 179.012, 4: 179.012, 5: 179.012, 6: 179.012, 7: 179.012, 8: 179.012, 9: 179.012, 10: 179.012, 11: 179.012, 12: 179.012, 13: 179.012}, 'value2': {0: -101.39, 1: -101.39, 2: -101.41, 3: -101.39, 4: -101.43, 5: -101.43, 6: -101.43, 7: -101.46, 8: -101.4, 9: -101.39, 10: -101.39, 11: -101.43, 12: -101.43, 13: -101.38}, 'state': {0: 'IDLE', 1: 'ON', 2: 'ON', 3: 'ON', 4: 'ACTIVE', 5: 'ACTIVE', 6: 'ACTIVE', 7: 'ACTIVE', 8: 'ACTIVE', 9: 'ACTIVE', 10: 'ACTIVE', 11: 'ACTIVE', 12: 'IDLE', 13: 'IDLE'}})

flag1 = 'flag1'
flag2 = 'flag2'
flag3 = 'flag3'
flag4 = 'flag4'

# test cases
# df.drop('flag1', axis = 1,inplace=True)
# df.drop('flag2', axis = 1,inplace=True)
# df.drop('flag3', axis = 1,inplace=True)
# df.drop('flag4', axis = 1,inplace=True)

#the valid indexes
valstart = []
valend = []

flaglist = [flag1, flag2, flag3, flag4]
curflag = flag1
for curflag in flaglist:
      if curflag in df.columns and (df[curflag] == True).any():
            #find the start and end of the case
            valstart.append(df[(df[curflag] == True)].index[0])
            valend.append(df[(df[curflag] == True)].index[-1])

anystart = min(valstart)
allstart = max(valstart)
anyend = max(valend)
allend = min(valend)

whenAllAreTrueAtTheSameTime = df[allstart:allend+1]
whenAnyareTrueAtTheSameTime  = df[anystart:anyend+1]

如何获得和&amp;熊猫索引清单

喜你已久 2025-02-13 22:56:42

假设源和结果列分别为 col values ,则可以实现如下:

data = [
    ([{"X": "A11"}, {"X": "A12"}, {"X": "A13"}],)
]
df = spark.createDataFrame(data, ['col'])
df = df.withColumn('values', F.array_join(F.flatten(F.transform('col', lambda x: F.map_values(x))), ','))
df.show(truncate=False)

Assuming that the source and result columns are col and values respectively, it can be implemented as follows:

data = [
    ([{"X": "A11"}, {"X": "A12"}, {"X": "A13"}],)
]
df = spark.createDataFrame(data, ['col'])
df = df.withColumn('values', F.array_join(F.flatten(F.transform('col', lambda x: F.map_values(x))), ','))
df.show(truncate=False)

Spark SQL中一系列地图的所有元素的串联值

喜你已久 2025-02-13 22:22:12

是的,这是可能的。编写创建CSV的流时,首先要做的就是:

myStream.Write(Encoding.UTF8.GetPreamble(), 0, Encoding.UTF8.GetPreamble().Length)

Yes it is possible. When writing the stream creating the csv, the first thing to do is this:

myStream.Write(Encoding.UTF8.GetPreamble(), 0, Encoding.UTF8.GetPreamble().Length)

是否可以自动强迫Excel识别UTF-8 CSV文件?

喜你已久 2025-02-13 07:22:46

您可以使用 re 模块:

import re

s = "GAMES HELLO VAUXHALL RUNS=15 TESTED=3"


m = re.search(r"RUNS=(\d+)", s)
if m:
    print("RUN=... found! The value is", m.group(1))

打印:

RUN=... found! The value is 15

You can use re module:

import re

s = "GAMES HELLO VAUXHALL RUNS=15 TESTED=3"


m = re.search(r"RUNS=(\d+)", s)
if m:
    print("RUN=... found! The value is", m.group(1))

Prints:

RUN=... found! The value is 15

python从字符串中提取值

喜你已久 2025-02-13 02:47:36

您可以创建两个组,其中一个具有额外的特权来删除,然后将按钮与删除特权组相关联,因此,如果用户拥有此组,则他将看到按钮,例如:在安全文件中创建两个组:

<record id="group_read_write_create" model="res.groups">
    <field name="name">Reading, writing, and creation permisions</field>
    <field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>

<record id="group_read_write_create_unlink" model="res.groups">
    <field name="name">Reading, writing, creation, and unlinking permisions</field>
    <field name="implied_ids" eval="[(4, ref('group_read_write_create'))]"/>
</record>

然后在.csv文件中定义了两个访问权限:

access_hr_model_name_read_write_create,hr.model.name.read.write.create,model_hr_model_name,group_read_write_create,1,1,1,0
access_hr_model_name_read_write_create_unlink,hr.model.name.read.write.create.unlink,model_hr_model_name,group_read_write_create_unlink,1,1,1,1

在视图中,该按钮将按钮与删除特权组相关联:

<xpath expr="//notebook/page[@name='page']/div[1]" position="before">
  <group string="Some Info">
    <field name="some_ids" readonly="True" nolabel="1">
      <tree default_order="create_date desc">
        <button name="unlink" type="object" string="Delete" class="oe_stat_button" icon="fa-times" groups="module_name.group_read_write_create_unlink"/>
      </tree>
    </field>
  </group>
</xpath>

You can create two groups one of which has extra privilege to delete and then associate the button with the group of deletion privilege so if the user has this group then he will see the button, for example: in the security file create two groups:

<record id="group_read_write_create" model="res.groups">
    <field name="name">Reading, writing, and creation permisions</field>
    <field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>

<record id="group_read_write_create_unlink" model="res.groups">
    <field name="name">Reading, writing, creation, and unlinking permisions</field>
    <field name="implied_ids" eval="[(4, ref('group_read_write_create'))]"/>
</record>

Then in the .csv file define two access rights:

access_hr_model_name_read_write_create,hr.model.name.read.write.create,model_hr_model_name,group_read_write_create,1,1,1,0
access_hr_model_name_read_write_create_unlink,hr.model.name.read.write.create.unlink,model_hr_model_name,group_read_write_create_unlink,1,1,1,1

And in the view associate the button with the group of deletion privilege:

<xpath expr="//notebook/page[@name='page']/div[1]" position="before">
  <group string="Some Info">
    <field name="some_ids" readonly="True" nolabel="1">
      <tree default_order="create_date desc">
        <button name="unlink" type="object" string="Delete" class="oe_stat_button" icon="fa-times" groups="module_name.group_read_write_create_unlink"/>
      </tree>
    </field>
  </group>
</xpath>

ODOO 13:检查用户是否具有“删除访问”

喜你已久 2025-02-13 02:35:30

您可以使用语句过滤掉自我服务记录,最好只在使用CTE:

WITH pure_employee AS (
SELECT * FROM Employee WHERE Team <> 'Self Service'
)

SELECT 
    i.CreatedBy, 
    COALESCE (e.Team, e1.Team) as CreatedByTeam, 
    i.CreatedDateTime, 
    i.Owner, 
    i.OwnerTeam, 
    i.LastModDateTime, 
    i.ResolvedBy,
    COALESCE (e2.Team, e3.Team) as ResolvedByTeam
FROM 
    Incident i
    LEFT JOIN pure_employee e ON i.CreatedBy=e.DisplayName
    LEFT JOIN pure_employee e1 ON i.CreatedBy=e1.PrimaryEmail
    LEFT JOIN pure_employee e2 ON i.ResolvedBy=e2.DisplayName
    LEFT JOIN pure_employee e3 ON i.ResolvedBy=e3.PrimaryEmail
WHERE 
    i.CreatedDateTime BETWEEN '2021-06-09' AND '2022-06-09' OR i.LastModDateTime BETWEEN '2021-06-09' AND '2022-06-09'

You can filter out the Self Service records using a WHERE statement, preferrably only doing it once using a cte:

WITH pure_employee AS (
SELECT * FROM Employee WHERE Team <> 'Self Service'
)

SELECT 
    i.CreatedBy, 
    COALESCE (e.Team, e1.Team) as CreatedByTeam, 
    i.CreatedDateTime, 
    i.Owner, 
    i.OwnerTeam, 
    i.LastModDateTime, 
    i.ResolvedBy,
    COALESCE (e2.Team, e3.Team) as ResolvedByTeam
FROM 
    Incident i
    LEFT JOIN pure_employee e ON i.CreatedBy=e.DisplayName
    LEFT JOIN pure_employee e1 ON i.CreatedBy=e1.PrimaryEmail
    LEFT JOIN pure_employee e2 ON i.ResolvedBy=e2.DisplayName
    LEFT JOIN pure_employee e3 ON i.ResolvedBy=e3.PrimaryEmail
WHERE 
    i.CreatedDateTime BETWEEN '2021-06-09' AND '2022-06-09' OR i.LastModDateTime BETWEEN '2021-06-09' AND '2022-06-09'

在SQL中排除特定匹配

喜你已久 2025-02-12 22:19:51

序言 preamble

通常会在不熟悉对象中的参考文献的情况下输出不良计算。默认情况下, asizeof 仅遍历计算的属性。但是,有例外 - 库中存在的参考方法,例如 numpy 是硬编码。

我怀疑 dekisionTreeReReReRegressor 有其自己的内部参考方法,用于构建一个未通过 asizeof

降低输出尺寸的

树/图,这取决于您的要求(Python版本,兼容性,时间,时间,时间) )您可以通过更改默认的协议 pickle 的参数来优化输出大小,以提高空间效率。

还有一个内置模块,称为 Pickletools ,可用于减少腌制文件使用的空间(腌制工具。 Pickletools 也可以用于拆卸字节代码。

此外,您可以使用内置的归档模块来压缩腌制输出。

参考

https://docs.python.orgg/ 3/library/pickle.html

​https://docs.python.org/3/library/archiving.html

Preamble

asizeof usually outputs bad calculations when it is unfamiliar with how to resolve references in objects. By default, asizeof only traverses attributes for calculations,. There are exceptions, however— reference methods present in libraries such as numpy are hardcoded.

I suspect DecisionTreeRegressor has its own internal reference methods used to build a tree/graph that is not recognized by asizeof

Reducing output size

Depending on your requirements (python version, compatibility, time) you may be able to optimize for output size by changing the default protocol parameter for pickle to a protocol more space efficient.

There is also a built in module called pickletools that can be used to reduce space used by your pickled file (pickle tools.optimize). pickletools may also be used to disassemble the byte code.

Furthermore, you may compress the pickled output using built-in archiving modules.

References

https://github.com/pympler/pympler/blob/master/pympler/asizeof.py

https://docs.python.org/3/library/pickle.html

https://docs.python.org/3/library/pickletools.html#module-pickletools

https://docs.python.org/3/library/archiving.html

为什么这么大的Sklearn决策树(大30k倍)的泡菜?

喜你已久 2025-02-12 20:25:15

我的一个想法是每个资源每个资源创建许多链,并用一条链包裹每个请求,以圆形旋转方式选择它们。这可能起作用,

它不会阻止资源饥饿。如果您将其作为每个命名的资源,那么您可能不会有效地限制并发的工作,除非唯一命名资源的数量足够低以满足您所需的限制。

,但不太优雅。有更好的选择吗?

我会说你需要一个适当的队列。 io_service 内部确实使用了工作队列,但它不打算用于优先排队或基于资源的调度。为什么使用 io_service ?您是否正在尝试避免自己实施队列的工作?

My one idea is to create a number of strands per each resource, and wrap each request with a strand, choosing them in round-robin manner. This could work,

It will not prevent resource starvation. If you make it a strand-per-named-resource then you might not limit concurrent work effecively unless the number of unique named resources is low enough to satisfy your required limit.

but is not too elegant. Are there any better options?

I'd say you need a proper queue. io_service internally does use a work queue, but it's not intended for priority queuing or resource-based scheduling. Why are you using io_service? Are you trying to avoid the work of implementing the queue(s) yourself?

提升asio io_service请求限制

喜你已久 2025-02-12 19:52:37
  1. 这是手动您应该检查

  2. 这是

    a href =“ https://stackoverflow.com/questions/2911754/how-to-to-upload-binary-file-with-ftplib-in-python”>相同的问题您应该检查第二个

  3. 这是正确代码的示例:

     来自ftplib import ftp
    
    使用ftp(
      conc_settings.ftp_domain,
      conc_settings.ftp_user,
      conc_settings.ftp_password
    )作为ftp:
      使用打开(OS.Path.join(文件夹,文件名),'rb')作为文件:
        ftp.storbinary(f'stor {filename}',file)
     
  1. Here is a manual that you should check first

  2. Here is a same question that you should check second

  3. Here is an example of correct code:

    from ftplib import FTP
    
    with FTP(
      conf_settings.FTP_DOMAIN,
      conf_settings.FTP_USER,
      conf_settings.FTP_PASSWORD
    ) as ftp:
      with open(os.path.join(folder, filename), 'rb') as file:
        ftp.storbinary(f'STOR {filename}', file)
    

Django和FTPLIB连接是否可以选择?

喜你已久 2025-02-12 18:51:05

根据 cppreference.com 无效。”在删除当前元素之前,您应该将迭代器转到下一个元素。

在同一页面中,cppReference给出了一个示例:

// Erase all even numbers (C++11 and later)
    for (std::list<int>::iterator it = c.begin(); it != c.end(); ) {
        if (*it % 2 == 0) {
            it = c.erase(it);
        } else {
            ++it;
        }
    }

擦除将迭代器返回下一个元素(如果删除元素是最后一个元素,则end(end()),因此“ IT = c.erase(it);”使“ IT”指向下一个元素,并且不需要增加迭代器(使用++)。

因此,您可以拥有类似的东西:

void advance(OrderInfo ordInfo, std::list <OrderInfo> ::iterator& orderIter) {
    if (ordInfo.statusCode == SCT_OSC_FILLED) {
        orderIter = MasterOrders.erase(orderIter);
    } else {
        orderIter++;
    }
}

According to cppreference.com, "References and iterators to the erased elements are invalidated." You should get an iterator to the next element, before deleting the current element.

In the same page, cppreference gives an example:

// Erase all even numbers (C++11 and later)
    for (std::list<int>::iterator it = c.begin(); it != c.end(); ) {
        if (*it % 2 == 0) {
            it = c.erase(it);
        } else {
            ++it;
        }
    }

erase returns an iterator to the next element (end() if the removed element was the last), so "it = c.erase(it);" makes "it" to point to the next element, and there is no need for incrementing the iterator (with ++).

So you could have something like:

void advance(OrderInfo ordInfo, std::list <OrderInfo> ::iterator& orderIter) {
    if (ordInfo.statusCode == SCT_OSC_FILLED) {
        orderIter = MasterOrders.erase(orderIter);
    } else {
        orderIter++;
    }
}

在列表中循环时删除数据

喜你已久 2025-02-12 12:10:07

没有执行任务的单线仪,但是如果您需要收拾此操作,则可以声明方法/函数/一体术并重复使用。 (假设您的所有数字都适合长时间)

public static void main(String[] args) {
    NumberFormat nf = new DecimalFormat("###,###");
    UnaryOperator<String> function = s -> {
        Pattern p = Pattern.compile("\\d{4,}");
        Matcher m = p.matcher(s);
        StringBuffer sb = new StringBuffer();
        while (m.find()) {
            m.appendReplacement(sb, nf.format(Long.parseLong(m.group())));
        }
        m.appendTail(sb);
        return sb.toString();
    };

    String s1 = "1128 ... 9812"; //What I have        "1,128 ... 9,812" //Expected result
    String s2 = "823446 ... 26 ... 239173"; //What I have        "823,446 ... 26 ... 239,173" //Expected result
    String s3 = "8012332 ... 7283912011"; //What I have        "8,012,332 ... 7,283,912,011" //Expected result

    s1 = function.apply(s1);
    s2 = function.apply(s2);
    s3 = function.apply(s3);

    System.out.println(s1);
    System.out.println(s2);
    System.out.println(s3);
}

There is no one-liner which does the task, but if you need to do this reapetedly you could declare a method/function/UnaryOperator and reuse it. (Assuming all your numbers fit in a long)

public static void main(String[] args) {
    NumberFormat nf = new DecimalFormat("###,###");
    UnaryOperator<String> function = s -> {
        Pattern p = Pattern.compile("\\d{4,}");
        Matcher m = p.matcher(s);
        StringBuffer sb = new StringBuffer();
        while (m.find()) {
            m.appendReplacement(sb, nf.format(Long.parseLong(m.group())));
        }
        m.appendTail(sb);
        return sb.toString();
    };

    String s1 = "1128 ... 9812"; //What I have        "1,128 ... 9,812" //Expected result
    String s2 = "823446 ... 26 ... 239173"; //What I have        "823,446 ... 26 ... 239,173" //Expected result
    String s3 = "8012332 ... 7283912011"; //What I have        "8,012,332 ... 7,283,912,011" //Expected result

    s1 = function.apply(s1);
    s2 = function.apply(s2);
    s3 = function.apply(s3);

    System.out.println(s1);
    System.out.println(s2);
    System.out.println(s3);
}

文本之间存在的格式数字的最简单方法是什么?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文