Search Results

Search found 251 results on 11 pages for 'equality'.

Page 7/11 | < Previous Page | 3 4 5 6 7 8 9 10 11  | Next Page >

  • Linq query - multiple where, with extension method

    - by Cj Anderson
    My code works for ORs as I've listed it below but I want to use AND instead of OR and it fails. I'm not quite sure what I'm doing wrong. Basically I have a Linq query that searches on multiple fields in an XML file. The search fields might not all have information. Each element runs the extension method, and tests the equality. Any advice would be appreciated. refinedresult = From x In theresult _ Where x.<thelastname>.Value.TestPhoneElement(LastName) Or _ x.<thefirstname>.Value.TestPhoneElement(FirstName) Or _ x.<id>.Value.TestPhoneElement(Id) Or _ x.<number>.Value.TestPhoneElement(Telephone) Or _ x.<location>.Value.TestPhoneElement(Location) Or _ x.<building>.Value.TestPhoneElement(building) Or _ x.<department>.Value.TestPhoneElement(Department) _ Select x Public Function TestPhoneElement(ByVal parent As String, ByVal value2compare As String) As Boolean 'find out if a value is null, if not then compare the passed value to see if it starts with Dim ret As Boolean = False If String.IsNullOrEmpty(parent) Then Return False End If If String.IsNullOrEmpty(value2compare) Then Return ret Else ret = parent.ToLower.StartsWith(value2compare.ToLower.Trim) End If Return ret End Function

    Read the article

  • Can you define <=> in Ruby and then have ==, >, <, >=, and <= defined automatically?

    - by jeremy Ruten
    Here's part of my Note class: class Note attr_accessor :semitones, :letter, :accidental def initialize(semitones, letter, accidental = :n) @semitones, @letter, @accidental = semitones, letter, accidental end def <=>(other) @semitones <=> other.semitones end def ==(other) @semitones == other.semitones end def >(other) @semitones > other.semitones end def <(other) @semitones < other.semitones end end It seems to me like there should be a module that I could include that could give me my equality and comparison operators based on my <=> method. Is there one? I'm guessing a lot of people run into this kind of problem. How do you usually solve it? (How do you make it DRY?)

    Read the article

  • Nothing = String.Empty (Why are these equal?)

    - by Ek0nomik
    I find it very puzzling that null equals String.Empty in VB.NET. There must be an explanation for it that I'm not understanding. Somehow, when the equality of String.Empty (which has an object type of string) is tested against Nothing (which has no type) the test returns true. It just seems like a turn around in logic to me. In SQL if I were to compare an empty char or varchar against a null value, the test wouldn't return true. A null value is not the same as an empty string in this case. Yet in VB.NET they are equal. I'd love it if someone could provide a good explanation around this.

    Read the article

  • Pure Java open-source libraries for portfolio selection (= constrained, non-linear optimization)?

    - by __roland__
    Does anyone know or has experience with a pure Java library to select portfolios or do some similar kinds of quadratic programming with constraints? There seems to be a lot of tools, as already discussed elsewhere - but what I would like to use is a pure Java implementation. Since I want to call the library from within another open-source software with a BSD-ish license I would prefer LGPL over GPL. Any help is appreciated. If you don't know such libraries, which is the most simple algorithm you would suggest to implement? It has to cope with an inequality constraint (all x_i = 0) and an equality constraint (sum of all x_i = 1).

    Read the article

  • Dynamically set generic type argument

    - by fearofawhackplanet
    Following on from my question here, I'm trying to create a generic value equality comparer. I've never played with reflection before so not sure if I'm on the right track, but anyway I've got this idea so far: bool ContainSameValues<T>(T t1, T t2) { if (t1 is ValueType || t1 is string) { return t1.Equals(t2); } else { IEnumerable<PropertyInfo> properties = t1.GetType().GetProperties().Where(p => p.CanRead); foreach (var property in properties) { var p1 = property.GetValue(t1, null); var p2 = property.GetValue(t2, null); if( !ContainSameValues<p1.GetType()>(p1, p2) ) return false; } } return true; } This doesn't compile because I can't work out how to set the type of T in the recursive call. Is it possible to do this dynamically at all? There are a couple of related questions on here which I have read but I couldn't follow them enough to work out how they might apply in my situation.

    Read the article

  • Adding WCF service reference adds DataContract types too

    - by Avi Shilon
    Hi everybody, I've used Visual Studio's Add Service Reference feature to add a service (actually it is a workflow service, created in WF4 RC1, but I don't think this makes any difference), and it also added the DataContracts that the service uses. At first this seemed fine, because All I've had in the DataContracts was simply properties, with no implementations. But now I've added code in the constructor of one data contracts that initializes creates an instance of one of the properties that exposes a list of other DCs, and when I've updated the service reference via VS (2010 RC1), the implementation was not updated. What should I do? Should I use my DCs instead of the ones created by VS or should I use the ones VS created? I've noticed that the properties in the VS-generated DCs contain some additional logic for checking equality in the setters and they also implement some interfaces too (like IExtensibleDataObject and INotifyPropertyChanged) which might get handy I guess in the future (I'm not knowledgeable at WCF). Thank you for your time folks, Avi

    Read the article

  • Running out of label names in assembly

    - by mamidon
    Heyo, My class at college has us writing programs in assembly. I have never truly appreciated the ease of C until now. Now, when I program in assembly, I often have to make while/for/if loops and conditionals with labels eg: SKIP: ... COMP:ADD R1, R1, #0 ;Check for equality BRZ WHILEEND ... ;code inside the while loop JMP COMP ;Return to while loop WHILEEND: ... So, in this while loop (example) I have used 1 label for the subroutine and 2 more for the loop itself. I've run out of good label names for all the loops and branches I'm doing in assembly, what do you guys do to keep it varied and descriptive?

    Read the article

  • Returning references while using shared_ptrs

    - by Goose Bumper
    Suppose I have a rather large class Matrix, and I've overloaded operator== to check for equality like so: bool operator==(Matrix &a, Matrix &b); Of course I'm passing the Matrix objects by reference because they are so large. Now i have a method Matrix::inverse() that returns a new Matrix object. Now I want to use the inverse directly in a comparison, like so: if (a.inverse()==b) { ... }` The problem is, this means the inverse method needs to return a reference to a Matrix object. Two questions: Since I'm just using that reference in this once comparison, is this a memory leak? What happens if the object-to-be-returned in the inverse() method belongs to a boost::shared_ptr? As soon as the method exits, the shared_ptr is destroyed and the object is no longer valid. Is there a way to return a reference to an object that belongs to a shared_ptr?

    Read the article

  • Comparing two java objects on fly (data type not known)

    - by Narendra
    Hi All, I need to compare different data objects. Can any one tell me how can i do this. I don't know what are the data types i will get priorly. If i need to use any util from apache commons then please give reference to it. At present I am using .equals() for comparing equality of objects .It is working fine when I am comparing quality for two strings. If i am comparing java.sql.date data type then it is showing unequal even though both contains same values. Can any one suggest me on this regard. Thanks, Narendra

    Read the article

  • Are memcached entries saved by the Danga client compatible with the Spy client?

    - by jigjig
    After saving a String value into memcached using the Danga client, I attempted to get the entry using the Spy client. The two String values are not the same. The Danga client retrieves a string with an additional empty char prepended to the string, therefore violating the equality condition. Danga: t,e,s,t,s,t,r,i,n,g Spy: ,t,e,s,t,s,t,r,i,n,g I also attempted to save a serialized Map using the Danga client and get the Map using the Spy client. The Spy client is able to only get a String form of the Map. The string contains binary values, as below: sr

    Read the article

  • Can I create a collection in Scala that uses different equals/hashCode/compare implementations?

    - by Willis Blackburn
    I'm looking for as simple way to create an identity set. I just want to be able to keep track of whether or not I've "seen" a particular object while traversing a graph. I can't use a regular Set because Set uses "==" (the equals method in Scala) to compare elements. What I want is a Set that uses "eq." Is there any way to create a Set in Scala that uses some application-specified method for testing equality rather than calling equals on the set elements? I looked for some kind of "wrapEquals" method that I could override but did not find it. I know that I could use Java's IdentityHashMap, but I'm looking for something more general-purpose. Another idea I had was to just wrap each set element in another object that implements equals in terms of eq, but it's wasteful to generate tons of new objects just to get a new equals implementation. Thanks!

    Read the article

  • Linq with a long where clause

    - by Jeremy Roberts
    Is there a better way to do this? I tried to loop over the partsToChange collection and build up the where clause, but it ANDs them together instead of ORing them. I also don't really want to explicitly do the equality on each item in the partsToChange list. var partsToChange = new Dictionary<string, string> { {"0039", "Vendor A"}, {"0051", "Vendor B"}, {"0061", "Vendor C"}, {"0080", "Vendor D"}, {"0081", "Vendor D"}, {"0086", "Vendor D"}, {"0089", "Vendor E"}, {"0091", "Vendor F"}, {"0163", "Vendor E"}, {"0426", "Vendor B"}, {"1197", "Vendor B"} }; var items = new List<MaterialVendor>(); foreach (var x in partsToChange) { var newItems = ( from m in MaterialVendor where m.Material.PartNumber == x.Key && m.Manufacturer.Name.Contains(x.Value) select m ).ToList(); items.AddRange(newItems); } Additional info: I am working in LINQPad.

    Read the article

  • An operator == whose parameters are non-const references

    - by Eduardo León
    I this post, I've seen this: class MonitorObjectString: public MonitorObject { // some other declarations friend inline bool operator==(/*const*/ MonitorObjectString& lhs, /*const*/ MonitorObjectString& rhs) { return lhs.fVal==rhs.fVal; } } Before we can continue, THIS IS VERY IMPORTANT: I am not questioning anyone's ability to code. I am just wondering why someone would need non-const references in a comparison. The poster of that question did not write that code. This was just in case. This is important too: I added both /*const*/s and reformatted the code. Now, we get back to the topic: I can't think of a sane use of the equality operator that lets you modify its by-ref arguments. Do you?

    Read the article

  • Can I mix compile time string comparison with MPL templates?

    - by Negative Zero
    I got this compile time string comparison from another thread using constexpr and C++11 (http://stackoverflow.com/questions/5721813/compile-time-assert-for-string-equality). It works with constant strings like "OK" constexpr bool isequal(char const *one, char const *two) { return (*one && *two) ? (*one == *two && isequal(one + 1, two + 1)) : (!*one && !*two); } I am trying to use it in the following context: static_assert(isequal(boost::mpl::c_str<boost::mpl::string<'ak'>>::value, "ak"), "should not fail"); But it gives me an compilation error of static_assert expression is not an constant integral expression. Can I do this?

    Read the article

  • Why is window not identical to window.self in Internet Explorer?

    - by Jim Puls
    There's a convoluted backstory involving how I came across this, but why is the self property not exactly equal to the window itself? In Safari and Firefox and friends, the results are as I'd expect: > window == window.self true > window === window.self true The same isn't true in Internet Explorer, though: >> window == window.self true >> window === window.self false Can anybody account for the inconsistency? To exactly what is the self property of the window object pointing? It casts to something with equality, which is even more vexing.

    Read the article

  • How does the " is " operator work internally

    - by JDMX
    I want to compare the type of an object to a type to see if they are the same. I do not have the object, just the type of the object. I can do type1 == type2 and get general equality I can have a recursive loop where I repeat the above step for type1.BaseType until the BaseType is null. I can do type1.GetInterface( type2.FullName ) != null to check if type2 is an interface of type1 If I put it all together, I get if ( type2.IsInterface ) return type1.GetInterface( type2.FullName ) != null; while ( type1 != null ) { if ( type1 == type2 ) return true; type1 = type1.BaseType; } return false; Is that all the is keyword is. I cannot find the right keyword to plug into the Reflector search to find the function and a google search on "is" was not really helpful

    Read the article

  • Linq Distinct() by name for populate a dropdown list with name and value

    - by AndreMiranda
    I'm trying to populate a Drop down list with pharmaceutical companies, like Bayer, Medley etc. And, I'm getting theses names from DB and theses names are repeated in DB, but with different id's. I'm trying to use Linq Distinct(), but I don't want to use the equality comparer. Is there another way? My drop down list must be filled with the id and the name of the company. I'm trying something like: var x = _partnerService .SelectPartners() .Select(c => new {codPartner = c.codPartner, name = c.name}) .Distinct(); This is showing repeated companies in ddl. thanks!

    Read the article

  • Is the .Net HashSet uniqueness calculation completely based on Hash Codes?

    - by RobV
    I was wondering whether the .Net HashSet<T> is based completely on hash codes or whether it uses equality as well? I have a particular class that I may potentially instantiate millions of instances of and there is a reasonable chance that some hash codes will collide at that point. I'm considering using HashSet's to store some instances of this class and am wondering if it's actually worth doing - if the uniqueness of an element is only determined on its hash code then that's of no use to me for real applications MSDN documentation seems to be rather vague on this topic - any enlightenment would be appreciated

    Read the article

  • how to diff / align Python lists using arbitrary matching function?

    - by James Tauber
    I'd like to align two lists in a similar way to what difflib.Differ would do except I want to be able to define a match function for comparing items, not just use string equality, and preferably a match function that can return a number between 0.0 and 1.0, not just a boolean. So, for example, say I had the two lists: L1 = [('A', 1), ('B', 3), ('C', 7)] L2 = ['A', 'b', 'C'] and I want to be able to write a match function like this: def match(item1, item2): if item1[0] == item2: return 1.0 elif item1[0].lower() == item2.lower(): return 0.5 else: return 0 and then do: d = Differ(match_func=match) d.compare(L1, L2) and have it diff using the match function. Like difflib, I'd rather the algorithm gave more intuitive Ratcliff-Obershelp type results rather than a purely minimal Levenshtein distance.

    Read the article

  • sql boolean truth test: zero OR null

    - by AK
    Is there way to test for both 0 and NULL with one equality operator? I realize I could do this: WHERE field = 0 OR field IS NULL But my life would be a hundred times easier if this would work: WHERE field IN (0, NULL) (btw, why doesn't that work?) I've also read about converting NULL to 0 in the SELECT statement (with COALESCE). The framework I'm using would also make this unpleasant. Realize this is oddly specific, but is there any way to test for 0 and NULL with one WHERE predicate?

    Read the article

  • Is there a difference between `==` and `is` in python?

    - by Bernard
    My Google-fu has failed me. In Python, are these: n = 5 # Test one. if n == 5: print 'Yay!' # Test two. if n is 5: print 'Yay!' two tests for equality equivalent (ha!)? Does this hold true for objects where you would be comparing instances (a list say)? Okay, so this kind of answers my question: l = list() l.append(1) if l == [1]: print 'Yay!' # Holds true, but... if l is [1]: print 'Yay!' # Doesn't. So == tests value where is tests to see if they are the same object?

    Read the article

  • Checking for 2 exepcted values in Junit

    - by Swift-Tuttle
    Hi, I have a java program which throws an exception with 2 different messages for 2 different scenarios and I want the Junit test case to check for equality for both of these messages. As an example - public void amethod() { // do some processing if(scenario1 == true) { throw new MySystemException("An error occured due to case 1 being incorrect."); } else if(scenario2 == true) { throw new MySystemException("An error occured as case 2 could not be found"); } } Now the JUnit for this would be something like- public void testAMethod() { // do something assertEquals("Expected", "Actual"); } As I understand, in this above example, if I use the Scenario1 exception message the junit will fail when an exception is thrown for Scenario2 and vice versa. I would like to know if there is any other way provided in Junit by which I can use this one test method and check for both the messages for the test to pass? Something like an OR, if possible to provide the "Expected" value with both these expected message. I hope my query is clear enough. Thanks

    Read the article

  • Delphi developer switching to C#

    - by Dorin Duminica
    Hello, I'm a Delphiholic for quite some time now and lately I was thinking of learning some C# as well, however I'm kinda' "afraid of the unknown", I've done some simple apps as a test drive for C# and I have to admit that I've liked it, HOWEVER I do not really like the IDE... that being said here's the question that I would appreciate if others who went down this path would answer: As a Delphi developer what are the "main basic" changes from the Delphi language(by basic I mean basic -- utility functions, streams, etc.), I'm used to add "System, Classes, Windows" to uses not "use System.XXX.YYY.ZZZ", I'm trying to make a partial equality in my mind from Delphi to C# until I can see where does Delphi go hand-in-hand with C# and so on... I hope the question is pretty clear, if not, do not hesitate to swear me and I'll try to clarify as well as I can :-)

    Read the article

  • Fetching a result twice with deferend name

    - by user1799842
    I have 1 table with tasks named opentask:columns: id,title,description,expires,creator_id,creator_name, executer_id, executer_name, priority_id, status_id1 table with users named user: with columns: user_id, username What I want is to create a query where there will be all columns from opentask table where the executer_id will be equal to the user_id of user table AND the creator_id will be equal to the user_id again. This creates a confusion because the first equality excludes the second.So I need somehow to create a query where I will include the usernames for the executer with something like where "opentask.executer_id=user_user_id" and at the same time I will include the username again (as a differend name?) for the creator with something like "where opentask.executer_id=user_user_id"So I try this, which of course I know that is missing something, can you help? SELECT DISTINCT id, title, description, expires, creator_id, executer_id, oc_opentask.priority_id, oc_opentask.status_id, priority_name, status_name, user_id, username, (SELECT username FROM oc_opentask, oc_user WHERE oc_opentask.creator_id=oc_user.user_id) AS username2 FROM oc_opentask, oc_opentask_priority, oc_user, oc_opentask_status WHERE oc_opentask.priority_id=oc_opentask_priority.priority_id AND oc_opentask.executer_id=oc_user.user_id AND oc_opentask.status_id=oc_opentask_status.status_id ORDER BY oc_opentask.expires DESC

    Read the article

  • PHP file modification time in milliseconds

    - by Steven Rosato
    I there, I am currently writing a unit test which asserts that a file did not get modified. The test code execution takes less than one second and therefore I would like to know if it is possible to retrieve the file modification time in milliseconds. filemtime() function returns the UNIX timestamp in seconds. My current solution is using the sleep(1) function which will assure me that 1 second passed before checking if it was modified or not. I don't like that solution since it slows down the test by a great deal. I cannot assert the content equality via get_file_contents() since the data that can be rewritten would be the same. I am guessing it is impossible, is it?

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11  | Next Page >