Tag Archives: list

[Solved] stream Convert list to map Error: java.lang.IllegalStateException: Duplicate key

I background

In many scenarios, the data of List needs to be transformed into the key-value pairs of Map scenarios to facilitate quick query data. For example: the need to query the corresponding person name details scenario according to the work number. There are two kinds of scenarios, the first one is to query the database once by each work number, which is obviously not reasonable because it is not good for DB pressure and connection. The second will be a collection of work number (need to consider the volume of data scenarios, Oracle supports a maximum of one thousand, mysql, although no online, but consider the performance and memory consumption need to consider the upper limit recommended 1000 below), the next is the second way to expand.

Translated with www.DeepL.com/Translator (free version)

II Development practice

List<User> userList = new ArrayList<>();

userList.add(User.builder().id(123).name("TEST123").build());

userList.add(User.builder().id(1231).name("TEST1231").build());

userList.add(User.builder().id(1232).name("TEST1232").build());

userList.add(User.builder().id(1233).name("TEST1233").build());

userList.add(User.builder().id(1234).name("TEST1234").build());

1.The stream implementation was not available before Java 1.8

Map<String, Long> idNameMap = new HashMap<String, Long>();

for(User user : userList ){

     idNameMap.put(user.getName(),  user.getId());

}

return idNameMap ;

2.Java 1.8 onwards supports stream implementation

return userList.stream().collect(Collectors.toMap(User::getName, User::getId);

III Existing problems

If you use the 2.1 way, the possible problems, if there are two data with the same name in the data, it will report an error java.lang.IllegalStateException: Duplicate key.

When using stream stream, it will not overwrite the data directly like the above way, but will report an error. So it needs to be optimized as

return userList.stream().collect(Collectors.toMap(User::getName, User::getId , (entity1, entity2) -> entity1);

It can solve the problem of error reporting.

[Solved] redis Error: AttributeError: ‘list‘ object has no attribute ‘decode‘

An error occurred while [redis data management tool] was running!

AttributeError: ‘list’ object has no attribute ‘decode’

Solution:

1. redisutil_main.py under /www/server/panel/plugin/redisutil
2. Line 97 db=db, followed by decode_responses=True
3. Look for .decode(‘utf-8’) and delete, four out of four
4. Done!

[Solved] Error: error getting chaincode bytes: ‘go list‘ failed with: cannot find module providing package


Execute the packing command.
peer lifecycle chaincode package sacc.tar.gz
–path github.com/hyperledger/fabric-cluster/chaincode/go/
–label sacc_1

Error Messages:

Error: error getting chaincode bytes: ‘go list’ failed with: cannot find module providing package github.com/hyperledger/fabric-cluster/chaincode/go: working directory is not part of a module: exit status 1

Solution:

The command go env -w GO111MODULE=auto solves this problem

[Solved] error LNK2005: ___pInvalidArgHandler Already defined in libcmtd.lib(invarg.obj)

Started generation...
1>------ has been started: Project: Bosch_EDC7, Configuration: Debug Win32 ------
1>edc7.lib(Bosch_EDC7.obj) : MSIL .netmodule or module compiled with /GL found; link is being restarted with /LTCG; adding /LTCG to link command line to improve linker performance
1>LINK : warning LNK4075: ignore "/INCREMENTAL" (due to "/LTCG" specification)
1>Bosch_EDC7.obj : warning LNK4075: ignore "/EDITANDCONTINUE" (due to "/OPT:ICF" specification)
1>LIBCMT.lib(invarg.obj) : error LNK2005: ___pInvalidArgHandler has been defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __initp_misc_invarg has been defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __call_reportfault has been defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __set_invalid_parameter_handler has been defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __get_invalid_parameter_handler has been defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson has been defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: "void __cdecl _invoke_watson(unsigned short const *,unsigned short const *,unsigned short const *, unsigned int,unsigned int)" (? _invoke_watson@@YAXPBG00II@Z) is already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invalid_parameter has been defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: "void __cdecl _invalid_parameter(unsigned short const *,unsigned short const *,unsigned short const *, unsigned int,unsigned int)" (? _invalid_parameter@@YAXPBG00II@Z) is already defined in libcmtd.lib(invarg.obj)
1>nafxcw.lib(objcore.obj) : error LNK2005: "public: static struct CRuntimeClass const CObject::classCObject" (?classCObject@CObject@@ 2UCRuntimeClass@@B) is already defined in nafxcwd.lib(objcore.obj)
1>nafxcw.lib(objcore.obj) : error LNK2005: "public: virtual struct CRuntimeClass * __thiscall CObject::GetRuntimeClass(void)const " (? GetRuntimeClass@CObject@@UBEPAUCRuntimeClass@@XZ) already defined in nafxcwd.lib(objcore.obj)
1>nafxcw.lib(objcore.obj) : error LNK2005: "public: class CObject * __thiscall CRuntimeClass::CreateObject(void)" (?CreateObject@ CRuntimeClass@@QAEPAVCObject@@XZ) already defined in nafxcwd.lib(objcore.obj)
1>nafxcw.lib(objcore.obj) : error LNK2005: "public: int __thiscall CObject::IsSerializable(void)const " (?IsSerializable@CObject@@QBEHXZ) already defined in nafxcwd.lib(objcore.obj)
1>nafxcw.lib(objcore.obj) : error LNK2005: "public: int __thiscall CRuntimeClass::IsDerivedFrom(struct CRuntimeClass const *)const " (? IsDerivedFrom@CRuntimeClass@@QBEHPBU1@@Z) already defined in nafxcwd.lib(objcore.obj)
1>nafxcw.lib(objcore.obj) : error LNK2005: "public: int __thiscall CObject::IsKindOf(struct CRuntimeClass const *)const " (?IsKindOf@CObject@@@ QBEHPBUCRuntimeClass@@@Z) is already defined in nafxcwd.lib(objcore.obj)
1>nafxcw.lib(objcore.obj) : error LNK2005: "class CObject * __cdecl AfxDynamicDownCast(struct CRuntimeClass *,class CObject *)" (? AfxDynamicDownCast@@YAPAVCObject@@PAUCRuntimeClass@@PAV1@@Z) already defined in nafxcwd.lib(objcore.obj)
1>nafxcw.lib(objcore.obj) : error LNK2005: "void __stdcall AfxClassInit(struct CRuntimeClass *)" (?AfxClassInit@@@YGXPAUCRuntimeClass@@@Z) already defined in nafxcwd.lib(objcore.obj)
1>nafxcw.lib(winmain.obj) : error LNK2005: "class CWinApp * __stdcall AfxGetApp(void)" (?AfxGetApp@@YGPAVCWinApp@@XZ) is already defined in nafxcwd.lib(afxinl2 .obj) is defined in
1>LINK : warning LNK4098: Default library "LIBCMT" conflicts with other libraries; please use /NODEFAULTLIB:library
1>LINK : warning LNK4098: The default library "nafxcw.lib" conflicts with other libraries; please use /NODEFAULTLIB:library
1>D:\A-Working\VS10_Projects\Bosch_EDC7\Bosch_EDC7\Debug\Bosch_EDC7.exe : fatal error LNK1169: One or more multi-defined symbols found
1> The operation to generate the project "Bosch_EDC7.vcxproj" has been completed - failed.
========== Generated: 0 successful, 1 failed, 2 latest, 0 skipped ==========

Solution:
The reason is that in Debug mode, some libraries are used in conflict, we just ignore the conflicting libraries.
Project Project Properties —> Linker —> Input —> Ignore specific default libraries —>

nafxcw.lib;libcmt.lib

[Solved] Zabbix Error: Cannot parse list of active checks

Question:

There is no data reported by the virtual machine, and an error is reported:

Cannot parse list of active checks

Solution:

1. Search the forum. The comment shows that there is a problem with the 10051 interface to the server. Check the firewall and no problem is found

2. The architecture adopts the mode of agent channel machine IP1 serverip2,

On the agent machine:

 tcping IP1 10051端口

The display is turned on. Continue troubleshooting

3. On the server machine, check the port status

tcping IP2 10051端口

It is found that the 10051 port is not open. Locate the problem, that is, the server problem. Restart the httpd service and solve it

systemctl restart httpd

After upgrading windows 11, Wireshark can’t get list of interfaces: packetgetadapternames reports an error

Question

After win10 is upgraded to win11, Wireshark displays Wireshark can’t get list of interfaces: packetgetadapternames: the system cannot find the specified path
packetgetadapternames is an API of WinPcap. Wireshark captures packets based on WinPcap or npcap. When installing Wireshark, an npcap or usbpcap will be automatically installed. I guess npcap or usbpcap may disappear after upgrading the system, so uninstall Wireshark and reinstall it. Just install npcap or usbpcap

solve

Remember to check all these options when uninstalling

[Solved] Vue Error: Duplicate keys detected: ‘74004’. This may cause an update error

Problems and Solutions

This may cause an update error

This error indicates that in your V-for loop, key   The value may be duplicate.

Duplicate key will cause rendering errors.

The reason for the error is that I didn’t add the key attribute at the beginning. The error code fragment is as follows:

<template>
    <vue-aplayer
            :audio="audio"
            :lrc-type="3"
            :fixed='fixed'
            :autoplay='autoplay'
            :order='order'
            :volume='volume'
            :theme='theme'
            :listFolded='listFolded '
    />
</template>


No more errors will be reported after adding key

<template>
    <vue-aplayer
            :audio="audio"
            :lrc-type="3"
            :fixed='fixed'
            :autoplay='autoplay'
            :order='order'
            :volume='volume'
            :theme='theme'
            :listFolded='listFolded '
            :key="audio.name"
    />
</template>


Note: audio attribute is the list I want to traverse, and name is the primary key in my list, so here I take audio. Name as the value of key ,   key must be unique.

Official description

key

Expectation: the special attributes of number | string key are mainly used in Vue’s virtual DOM algorithm to identify vnodes when comparing old and new nodes. If you do not use keys, Vue will use an algorithm that minimizes dynamic elements and tries to modify/reuse elements of the same type in place as much as possible. When using a key, it rearranges the order of elements based on the change of the key, and removes elements that do not exist in the key. Child elements with the same parent element must have a unique key. Duplicate keys can cause rendering errors. The most common use case is the combination of V-for :

<ul>
  <li v-for="item in items" :key="item.id">...</li>
</ul>


It can also be used to force replacement of elements/components rather than reuse it. It may be useful when you encounter the following scenarios:

Completely trigger the life cycle hook of the component to trigger the transition, for example:

<transition>
  <span :key="text">{{ text }}</span>
</transition>


When text changes, <span> is always replaced rather than modified, so a transition is triggered.

Type error: sequence item 0: expected STR instance, int found

TypeError: sequence item 0: expected STR instance, int found TypeError: sequence item 0: expected STR instance, int found
List1 =[1,’two’,’three’,4]
print(‘ ‘.join(list1))
I thought it would print 1, two, three, four
The result was an error
Traceback (most recent call last):
File “< pyshell#27>” , line 1, in < module>
print(” “.join(list1))
peerror: sequence item 0: expected STR instance, int found
p> (“.join(list1))
TypeError: sequence item 0: expected STR instance, int found
A list of numbers cannot be converted directly to a string.
Print (” “.join(‘%s’ %id for id in list1))
That is, iterating through the elements of the list, converting them to strings. So I can print 1, 2, 3, 4.

Some problems in using arrays

/*
* array note some issues
*/
#include < iostream>
using namespace std;
Int main()
{
const int ArraySize = 5;
// initializes the elements in the array, and the uninitialized elements are by default filled with the value 0, representing the NULL character (NULL or \0)
int arr[ArraySize] = {10,3,5};

// array name, which represents the starting address of the first element (direct array name is recommended)
cout < < “arr = ” < < arr < < endl;
// array is a collection, take the address of the array name, get is the first address of the collection represented by the array (generally not recommended to use the address of the array name)
cout < < “& arr = ” < < & arr < < endl;

{
/* array name itself is not a variable, so it does not occupy storage space, nor can it be used to store data; ,
, which simply represents a data, as a value, it represents the address of the first data element in the array. */
// for example, the following is wrong!!
/* compile times wrong: assigning to an array from the an, initializer list */
// arr = {10,16,8};
// therefore, arrays cannot be assigned, only array elements can be initialized or assigned.
}
// if an array is defined and not initialized, its output will be garbage instead of having no value
/*cout < < “No array initialization, garbage data output!” < < endl;
for(int I = 0; i ! = ArraySize; I++)
cout & lt; < arr[i] < < “‘;
cout & lt; < endl;

// input data, assign values to data elements in arr array
/* even if the number of input data elements is greater than the length of the array, cin will only extract required data from the input buffer according to the length of the array
, while the remaining data will be left in the input buffer for use next time */
//cout < < “The input data are:”;
//for(int I = 0; i ! = ArraySize; I++)
// cin & gt; > arr[i];

// below are three different ways to output the address of each array element in memory
/*cout < < “Method 1:” < < endl;
for(int I = 0; i ! = ArraySize; I++)
cout & lt; < “& arr[” << i << “] = ” < < & arr[i] < < endl;
cout & lt; < “Method two:” < < endl;
for(int I = 0; i ! = ArraySize; I++)
cout & lt; < “[arr+” << i << “] = ” < < arr+i < < endl;
cout & lt; < “Method 3:” < < endl;
for(int I = 0,*p = arr; p ! = (arr+ArraySize) & & i ! = ArraySize; I++ p++)
cout & lt; < “p -[” << i << “]= ” < < p < < endl; */

/* the following four methods of outputting elements in an array have no errors;
the compiler changes the brackets in the array at compile time :(both sides are equivalent to each other)
arr[I] < => * (arr + I)
* (arr + I) & lt; => * (I + arr)
* (I + arr) & lt; => I (arr)
arr [I] < => I [arr]
I is the offset, indicating the number of elements of the offset first element */
/*for(int I = 0; i ! = ArraySize; I++)
cout & lt; < arr[i] < < “‘;
cout & lt; < endl;
For (int I = 0; i ! = ArraySize; I++)
cout & lt; < *(arr+i) < < “‘;
cout & lt; < endl;
For (int I = 0; i ! = ArraySize; I++)
cout & lt; < i[arr] < < “‘;
cout & lt; < endl;

for(int* p = arr; p ! = (arr+ArraySize); P++)
cout & lt; < *p < < “‘;
cout & lt; < endl; * /

cout <
cout < < “The consequences of a cross-border visit!” < < endl;
int iNum = 123,iLen = 90;
int array[7] = {10,3,6,8,5,9,7};
for(int I = -2);
for(int I = -2);
for(int I = -2); i ! = 9; I++)
cout & lt; < array[i] < < “‘;
cout & lt; < endl;

cout & lt; < iNum < < “—” < < iLen < < endl;
// Out-of-bounds storage of data can result in the value of other variables, and may even cause the program to crash (which didn’t happen, which is weird!!).
for(int I = -2; i ! = 7. I++)
cin & gt; > array[i];
for(int I = 0; i ! = 7. I++)
cout & lt; < array[i] < < “‘;
cout & lt; < endl;
cout & lt; < iNum < < “—” < < iLen < < endl;
return 0;
}