comparison

java comparison of two enums

梦想的初衷 提交于 2019-12-24 23:07:59
问题 Given the test code: @Test public void testEnumAreEqual() { for (var someEnum : SomeEnum.values()) { Assertions.assertTrue(EnumUtils.isValidEnum(OtherEnum.class, someEnum.name())); } for (var otherEnum : OtherEnum.values()) { Assertions.assertTrue(EnumUtils.isValidEnum(SomeEnum.class, otherEnum.name())); } } I want to check if two given enums are containing the same values. Is there maybe a more elegant way to do this? 回答1: Build a set of the names: Set<String> someEnumNames = Arrays.stream

Similar language features to compare with Perl and Ruby __END__

风流意气都作罢 提交于 2019-12-24 19:27:08
问题 Background Perl and Ruby have the __END__ and __DATA__ tokens that allow embedding of arbitrary data directly inside a source code file. Although this practice may not be well-advised for general-purpose programming use, it is pretty useful for "one-off" quick scripts for routine tasks. Question: What other programming languages support this same or similar feature, and how do they do it? 回答1: Perl supports the __DATA__ marker, which you can access the contents of as though it were a regular

VB.NET: Check if List items are equal and have same count

懵懂的女人 提交于 2019-12-24 14:19:25
问题 How can I detect whether the items of two given lists are equal? Dim list1 As New List(Of Integer) list1.AddRange({1, 2, 3}) Dim list2 As New List(Of Integer) list2.AddRange({3, 2, 1}) If I compare them using SequenceEqual I get False because the order of the items is not the same. How can I compare them without sorting them first, though? EDIT: Please take into account that this should respect duplicates, for example {1, 2, 3, 1} is not the same as {1, 2, 3} (item 1 occurs two times in the

value of CustomEquality and CustomComparison

旧巷老猫 提交于 2019-12-24 13:32:03
问题 I understand the value of asserting [<StructuralEquality;StructuralComparison>] This statically forces equality and comparison constraints to be derived structurally, and have a nice side effect to warn if it can not Similarly [<ReferenceEquality>] forces the equality constraint to be satisfied using reference. Last NoComparison, NoEquality statically unsatisfy those constraints, with the benefit of catching errors as well. However I am unsure what the added value of CustomEquality,

C# Compare Lists with custom object but ignore order

旧街凉风 提交于 2019-12-24 12:14:23
问题 I'm trying to compare 2 Lists (wrapped in an object) containing custom objects. I don't care about the order, but if list 1 contains "1,2,3,4" then list 2 must and only contain those elements. E.g.: "4,2,3,1" Based on Compare two List<T> objects for equality, ignoring order ignoring-order I've used the Except and Any but it doesn't give me the desired results. If I use Assert.Equals it fails, but Assert.IsTry(list1.equals(list2)) succeeds. Further more if I remove the Equals and GetHashCode

Programming In C and Win32 API: Comparing Strings

六眼飞鱼酱① 提交于 2019-12-24 12:08:21
问题 I am writing a program in C and Windows API. I am using Visual Studio 2010 Express and Character Set is set to "Not Set". I have made an edit control to accept username. Here's declaration: hwnduser = CreateWindow (TEXT("EDIT"), NULL, WS_VISIBLE | WS_CHILD | WS_BORDER, 220, 70, 80, 20, hwnd, (HMENU) 3, NULL, NULL); I am fetching its value into a string named username. len = GetWindowTextLength(hwnduser) + 1; GetWindowText(hwnduser, username, len); Now, the valid username is in a string called

OrderedDict KeyError

好久不见. 提交于 2019-12-24 10:57:06
问题 import collections d = collections.defaultdict(dict) d["i"]["a"] = "111" d["i"]["b"] = "222" print d od = collections.OrderedDict() od["i"]["a"] = "111" od["i"]["b"] = "222" print od Output: defaultdict(<type 'dict'>, {'i': {'a': '111', 'b': '222'}}) Traceback (most recent call last): File "app_main.py", line 51, in run_toplevel File "/Users/adam/Desktop/collections.py", line 12, in <module> od["i"]["a"] = "111" KeyError: 'i' Why the key error with OrderedDict and what I can do about it?

In practice, why compare integer is better than compare string?

倖福魔咒の 提交于 2019-12-24 08:01:49
问题 I did this test import time def test1(): a=100 b=200 start=time.time() if (a>b): c=a else: c=b end=time.time() print(end-start) def test2(): a="amisetertzatzaz1111reaet" b="avieatzfzatzr333333ts" start=time.time() if (a>b): c=a else: c=b end=time.time() print(end-start) def test3(): a="100" b="200" start=time.time() if (a>b): c=a else: c=b end=time.time() print(end-start) And obtain as result 1.9073486328125e-06 #test1() 9.5367431640625e-07 #test2() 1.9073486328125e-06 #test3() Execution

List of Dicts comparision to match between lists and detect value changes in Python

别等时光非礼了梦想. 提交于 2019-12-24 07:46:11
问题 I have a list of dictionaries that I get back from a web service call, listA = [{'name':'foo', 'val':'x'}, {'name':'bar', 'val':'1'}, {'name':'alice','val':'2'}] I need to compare the results from the previous call to the service and pull out changes. So on the next call I may get: listB = [{'name':'foo', 'val':'y'}, {'name':'bar', 'val':'1'}, {'name':'eve','val':'z'}] The ordering is not guaranteed and nor is the length of list. The names won't change. The actual data has several more keys,

Weird comparison performance on Javascript object key lookup

倾然丶 夕夏残阳落幕 提交于 2019-12-24 07:35:38
问题 Presentation : I am working on a piece of code that can compare two javascript Object by looping into the first one (called A) to perform a key lookup in the second one called B (I put value as key and occurence as value). But when I am measuring the performance of the subkey key lookup of Object A (10 times per amount of data, with data as changing parameters for each 10 times the program runs (100 per row, 200...) I get high timing for the smallest amount of data (so potentially less key in