Search Results

Search found 1816 results on 73 pages for 'equals'.

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

  • PHP echo if post equals, help

    - by user342391
    I am trying to echo the action for my form if a post equals 'paypal' This is what I have: <?php if $_POST['method'] == 'paypal' echo 'action="paypal/process.php"' else echo 'action="moneybookers/process.php" '?> Do i need to print the variable before I do this? what am I doing wrong? I get this error: Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in /var/www/account/credits/credit_amount.php on line 27

    Read the article

  • Dictionary keys don't contain a key that's already contained in keys

    - by ran
    Why is the following 'exist' boolean variable getting a value of false??? foreach (Cell existCell in this.decoratorByCell.Keys) { //this call yield the same hashcode for both cells. still exist==false bool exist = this.decoratorByCell.ContainsKey(existCell); } I've overridden GetHashCode() & Equals() Methods as follows: public override int GetHashCode() { string nodePath = GetNodePath(); return nodePath.GetHashCode() + m_ownerColumn.GetHashCode(); } public bool Equals(Cell other) { bool nodesEqual = (other.OwnerNode == null && this.OwnerNode == null) || (other.GetNodePath() == this.GetNodePath()); bool columnsEqual = (other.OwnerColumn == null && this.OwnerColumn == null) || (other.OwnerColumn == this.OwnerColumn); bool treesEqual = (this.m_ownerTree == other.m_ownerTree); return (nodesEqual && columnsEqual && treesEqual); }

    Read the article

  • How to compare two maps by their values

    - by lewap
    How to compare two maps by their values? I have two maps containing equal values and want to compare them by their values. Here is an example: Map a = new HashMap(); a.put("f"+"oo", "bar"+"bar"); a.put("fo"+"o", "bar"+"bar"); Map b = new HashMap(); a.put("f"+"oo", "bar"+"bar"); a.put("fo"+"o", "bar"+"bar"); System.out.println("equals: " + a.equals(b)); // obviously false .... what to call to obtain a true? Obviously, to implement a comparison it not difficult, it is enough to compare all keys and their associated values. I don't believe I'm the first one to do this, so there must be already a library functions either in java or in one of the jakarta.commons libraries. Thanks

    Read the article

  • Any way to allow classes implementing IEntity and downcast to have operator == comparisons?

    - by George Mauer
    Basically here's the issue. All entities in my system are identified by their type and their id. new Customer() { Id = 1} == new Customer() {Id = 1}; new Customer() { Id = 1} != new Customer() {Id = 2}; new Customer() { Id = 1} != new Product() {Id = 1}; Pretty standard scenario. Since all Entities have an Id I define an interface for all entities. public interface IEntity { int Id { get; set;} } And to simplify creation of entities I make public abstract class BaseEntity<T> : where T : IEntity { int Id { get; set;} public static bool operator ==(BaseEntity<T> e1, BaseEntity<T> e2) { if (object.ReferenceEquals(null, e1)) return false; return e1.Equals(e2); } public static bool operator !=(BaseEntity<T> e1, BaseEntity<T> e2) { return !(e1 == e2); } } where Customer and Product are something like public class Customer : BaseEntity<Customer>, IEntity {} public class Product : BaseEntity<Product>, IEntity {} I think this is hunky dory. I think all I have to do is override Equals in each entity (if I'm super clever, I can even override it only once in the BaseEntity) and everything with work. So now I'm expanding my test coverage and find that its not quite so simple! First of all , when downcasting to IEntity and using == the BaseEntity< override is not used. So what's the solution? Is there something else I can do? If not, this is seriously annoying. Upadate It would seem that there is something wrong with my tests - or rather with comparing on generics. Check this out [Test] public void when_created_manually_non_generic() { // PASSES! var e1 = new Terminal() {Id = 1}; var e2 = new Terminal() {Id = 1}; Assert.IsTrue(e1 == e2); } [Test] public void when_created_manually_generic() { // FAILS! GenericCompare(new Terminal() { Id = 1 }, new Terminal() { Id = 1 }); } private void GenericCompare<T>(T e1, T e2) where T : class, IEntity { Assert.IsTrue(e1 == e2); } Whats going on here? This is not as big a problem as I was afraid, but is still quite annoying and a completely unintuitive way for the language to behave. Update Update Ah I get it, the generic implicitly downcasts to IEntity for some reason. I stand by this being unintuitive and potentially problematic for my Domain's consumers as they need to remember that anything happening within a generic method or class needs to be compared with Equals()

    Read the article

  • How to hash and check for equality of objects with circular references

    - by mfya
    I have a cyclic graph-like structure that is represented by Node objects. A Node is either a scalar value (leaf) or a list of n=1 Nodes (inner node). Because of the possible circular references, I cannot simply use a recursive HashCode() function, that combines the HashCode() of all child nodes: It would end up in an infinite recursion. While the HashCode() part seems at least to be doable by flagging and ignoring already visited nodes, I'm having some troubles to think of a working and efficient algorithm for Equals(). To my surprise I did not find any useful information about this, but I'm sure many smart people have thought about good ways to solve these problems...right? Example (python): A = [ 1, 2, None ]; A[2] = A B = [ 1, 2, None ]; B[2] = B A is equal to B, because it represents exactly the same graph. BTW. This question is not targeted to any specific language, but implementing hashCode() and equals() for the described Node object in Java would be a good practical example.

    Read the article

  • Why does `Array(0,1,2) == Array(0,1,2)` not return the expected result?

    - by soc
    As far as I understand, Scala's == defines the natural equality of two objects. I expected that Array(0,1,2) == Array(0,1,2) compares the natural equality e. g. checks if all elements of the array return true when compared with the corresponding elements of the other array. People told me that Scala's Array is just a Java [] which only compares identity. But Scala's String is also just a Java String but Scala overrides equals to compare natural equality. I wonder why Array's equals method was not overridden, too. Thank you for your thoughts!

    Read the article

  • Verification GetHashCode and Equals

    - by nettguy
    Does the following code show the correct implementation of overriding GetHashCode ? public class Person { public string fName{get;set;} public string lName { get; set; } public int age { get; set; } public override bool Equals(object obj) { Person p = obj as Person; if (p == null) return false; return ( p.GetType()==this.GetType() && p.fName==this.fName &&p.lName==this.lName && p.age==this.age ); } //I took the below code from Marc Gravell's post,I am not sure whether i have implemented it properly public override int GetHashCode() { unchecked { int hash = 13; hash = (hash * 7) + fName.GetHashCode(); hash = (hash * 7) + lName.GetHashCode(); hash = (hash * 7) + age.GetHashCode(); return hash; } } }

    Read the article

  • Why doesn't list.get(0).equals(null) work?

    - by Jessy
    The first index is set to null (empty), but it doesn't print the right output, why? //set the first index as null and the rest as "High" String a []= {null,"High","High","High","High","High"}; //add array to arraylist ArrayList<Object> choice = new ArrayList<Object>(Arrays.asList(a)); for(int i=0; i<choice.size(); i++){ if(i==0){ if(choice.get(0).equals(null)) System.out.println("I am empty"); //it doesn't print this output } }

    Read the article

  • Java: How to workaround the lack of Equatable interface?

    - by java.is.for.desktop
    Hello, everyone! As far as I know, things such as SortedMap or SortedSet, use compareTo (rather than equals) on Comparable<?> types for checking equality (contains, containsKey). But what if certain types are equatable by concept, but not comparable? I have to declare a Comparator<?> and override the method int compareTo(T o1, To2). OK, I can return 0 for instances which are considered equal. But, for unqeual instances, what do I return when an order is not evident? Is the approach of using SortedMap or SortedSet on equatable but (by concept) not comparable types good anyway? Thank you! EDIT: I don't want to store things sorted, but would I use "usual" Map and Set, I couldn't "override" the equality-behavior. EDIT 2: Why I can't just override equals(...): I need to alter the equality-behavior of a foreign class. Can't edit it. EDIT 3: Just think of .NET: They have IEquatable interface which cat alter the equality-behavior without touching the comparable behavior.

    Read the article

  • Can't seem to get .Union to work (merging 2 array's together, exclude duplicates)

    - by D. Veloper
    I want to combine two array's, excluding duplicates. I am using a custom class: public class ArcContact : IEquatable<ArcContact> { public String Text; public Boolean Equals(ArcContact other) { if (Object.ReferenceEquals(other, null)) return false; if (Object.ReferenceEquals(this, other)) return true; return Text.Equals(other.Text); } public override Int32 GetHashCode() { return Text == null ? 0 : Text.GetHashCode(); } } I implemented and the needed IEquatable interface as mentioned in this msdn section. I only want to check the Text property of the ArcContact class and make sure an Array of ArcContact have an unique Text. Here I pasted the code that I use, as you can see I have method with two parameters, array's to combine and below that the code I got from the previous mentioned msdn section. internal static class ArcBizz { internal static ArcContact[] MergeDuplicateContacts(ArcContact[] contacts1, ArcContact[] contacts2) { return (ArcContact[])contacts1.Union(contacts2); } internal static IEnumerable<T> Union<T>(this IEnumerable<T> a, IEnumerable<T> b); } What am I doing wrong?

    Read the article

  • java: retrieving the "canonical value" from a Set<T> where T has a custom equals()

    - by Jason S
    I have a class Foo which overrides equals() and hashCode() properly. I would like to also would like to use a HashSet<Foo> to keep track of "canonical values" e.g. I have a class that I would like to write like this, so that if I have two separate objects that are equivalent I can coalesce them into references to the same object: class Canonicalizer<T> { final private Set<T> values = new HashSet<T>(); public T findCanonicalValue(T value) { T canonical = this.values.get(value); if (canonical == null) { // not in the set, so put it there for the future this.values.add(value); return value; } else { return canonical; } } } except that Set doesn't have a "get" method that would return the actual value stored in the set, just the "contains" method that returns true or false. (I guess that it assumes that if you have an object that is equal to a separate object in the set, you don't need to retrieve the one in the set) Is there a convenient way to do this? The only other thing I can think of is to use a map and a list: class Canonicalizer<T> { // warning: neglects concurrency issues final private Map<T, Integer> valueIndex = new HashMap<T, Integer>(); final private List<T> values = new ArrayList<T>(); public T findCanonicalValue(T value) { Integer i = this.valueIndex.get(value); if (i == null) { // not in the set, so put it there for the future i = this.values.size(); this.values.add(value); this.valueIndex.put(value, i); return value; } else { // in the set return this.values.get(i); } } }

    Read the article

  • Find numbers that equals a sum in an array

    - by valli-R
    I want to find the first set of integers in an array X that the sum equals a given number N. For example: X = {5, 13, 24, 9, 3, 3} N = 28 Solution = {13, 9, 3, 3} Here what I have so far : WARNING, I know it uses global and it is bad,that's not the point of the question. <?php function s($index = 0, $total = 0, $solution = '') { global $numbers; global $sum; echo $index; if($total == 28) { echo '<br/>'.$solution.' = '.$sum.'<br/>'; } elseif($index < count($numbers) && $total != 28) { s($index + 1, $total, $solution); s($index + 1, $total + $numbers[$index], $solution.' '.$numbers[$index]); } } $numbers = array(5, 13, 24, 9, 3, 3); $sum = 28; s(); ?> I don't get how I can stop the process when it finds the solution.. I know I am not far from good solution.. Thanks in advance

    Read the article

  • If either one of both equals

    - by user1620028
    I have start and end dates which are stored in a database in this format: start date= 20121004 //4th October 2012 end date= 20121004 //16th November 2012 so I can use date format: $date = date("Ymd"); // returns: 20121004 to determine when to display and not display to repopulate my update input boxes I use: $start=(str_split($stdate,4));// START DATE: splits stored date into 2x4 ie: 20121209 = 2012 1209 $syr = $start[0];// re first half ie: 2012 which is the year $start2 = $start[1];//re second half ie: 1209 $start3=(str_split($start2,2));// splits second half date into 2x2 ie: 1209 = 12 09 $smth = $start3[0]; // first half = month ie: 12 $sday = $start3[1]; // second half = day ie: 09 $expiry=(str_split($exdate,4)); ///SAME AGAIN FOR EXPIRY DATE ... $xyr = $expiry[0]; $expiry2 = $expiry[1]; $expiry3=(str_split($expiry2,2)); $xmth = $expiry3[0]; $xday = $expiry3[1]; which works fine but I need to repopulate the input boxes for the month showing the date in the database like this <option value="01">January</option`> using if ($smth==01):$month='January'; endif; if ($xmth==01):$month='January'; endif; // if the start and/or expiry month number = 01 display $month as January if ($smth==02):$smonth='February'; endif; if ($xmth==02):$smonth='February'; endif; if ($smth==03):$month='March'; endif; <select name="stmonth" class="input"> <option value="<?=$smth?>"><?=$month?></option> ... </select> is there an easier way to display IF EITHER ONE EQUALS rather than having to write the same line twice once for each $smth AND $xmth ? re: if ($smth **and or** $xmth ==01):$month='January'; endif;

    Read the article

  • C# what does the == operator do in detail?

    - by clamp
    in c# what does exactly happen in the background when you do a comparison with the "==" operator on two objects? does it just compare the addresses? or does it something like Equals() or CompareTo() ? PS: what about the "==" operator in java? does it behave the same?

    Read the article

  • How to determine if two generic type values are equal?

    - by comecme
    I'm trying to figure out how I can successfully determine if two generic type values are equal to each other. Based on Mark Byers' answer on this question I would think I can just use value.Equals() where value is a generic type. My actual problem is in a LinkedList implementation, but the problem can be shown with this simpler example. class GenericOjbect<T> { public T Value { get; private set; } public GenericOjbect(T value) { Value = value; } public bool Equals(T value) { return (Value.Equals(value)); } } Now I define an instance of GenericObject<StringBuilder> containing new StringBuilder("StackOverflow"). I would expect to get true if I call Equals(new StringBuilder("StackOverflow") on this GenericObject instance, but I get false. A sample program showing this: using System; using System.Text; class Program { static void Main() { var sb1 = new StringBuilder("StackOverflow"); var sb2 = new StringBuilder("StackOverflow"); Console.WriteLine("StringBuilder compare"); Console.WriteLine("1. == " + (sb1 == sb2)); Console.WriteLine("2. Object.Equals " + (Object.Equals(sb1, sb2))); Console.WriteLine("3. this.Equals " + (sb1.Equals(sb2))); var go1 = new GenericOjbect<StringBuilder>(sb1); var go2 = new GenericOjbect<StringBuilder>(sb2); Console.WriteLine("\nGenericObject compare"); Console.WriteLine("1. == " + (go1 == go2)); Console.WriteLine("2. Object.Equals " + (Object.Equals(go1, go2))); Console.WriteLine("3. this.Equals " + (go1.Equals(go2))); Console.WriteLine("4. Value.Equals " + (go1.Value.Equals(go2.Value))); } } For the three methods of comparing two StringBuilder objects, only the StringBuilder.Equals instance method (the third line) returns true. This is what I expected. But when comparing the GenericObject objects, its Equals() method (the third line) returns false. Interestingly enough, the fourth compare method does return true. I'd think the third and fourth comparison are actually doing the same thing. I would have expected true. Because in the Equals() method of the GenericObject class, both value and Value are of type T which in this case is a StringBuilder. Based on Mark Byers' answer in this question, I would've expected the Value.Equals() method to be using the StringBuilder's Equals() method. And as I've shown, the StringBuilder's Equal() method does return true. I've even tried public bool Equals(T value) { return EqualityComparer<T>.Default.Equals(Value, value); } but that also returns false. So, two questions here: Why doesn't the code return true? How could I implement the Equals method so it does return true?

    Read the article

  • What are the best practices for implementing the == operator for a class in C#?

    - by remio
    While implementing an == operator, I have the feeling that I am missing some essential points. Hence, I am searching some best practices around that. Here are some related questions I am thinking about: How to cleanly handle the reference comparison? Should it be implemented through a IEquatable<T>-like interface? Or overriding object.Equals? And what about the != operator? (this list might not be exhaustive).

    Read the article

  • Collection, which method is used to authorize an add of an element ?

    - by Duke Vador
    We find a lot of concrete subclasses under Collection. While trying to add an element in a concrete collection, this collection will use a method to determine if it can accept to store the element (and eventually that this element is not already in the collection). It could use equals(), hashCode() or compareTo() of the element. Is it possible to find a summary about which method is used by each implementation of Collection ? Thanks a lot for your answers.

    Read the article

  • What's the reason both Image and Bitmap classes don't implement a custom equality/hashcode logic?

    - by devoured elysium
    From MSDN documentation, it seems as both GetHashCode() and Equals() haven't been overriden in Bitmap. Neither have them been overriden in Image. So both classes are using the Object's version of them just compares references. I wasn't too convinced so I decided to fire up Reflector to check it out. It seems MSDN is correct in that matter. So, is there any special reason why MS guys wouldn't implement "comparison logic", at least for the Bitmap class? I find it is kinda acceptable for Image, as it is an abstract class, but not so much for the Bitmap class. I can see in a lot of situations calculating the hash code can be an expensive operation, but it'd be alright if it used some kind of lazy evaluation (storing the computed hash code integer in a variable a variable, so it wouldn't have to calculate it later again). When wanting to compare 2 bitmaps, will I have to resort to having to run all over the picture comparing each one of its pixels? Thanks

    Read the article

  • How to check if my string is equal to null?

    - by Roman
    I want to perform some action ONLY IF my string has a meaningful value. So, I tried this. if (!myString.eqauls("")) { doSomething } and this if (!myString.eqauls(null)) { doSomething } and this if ( (!myString.eqauls("")) && (!myString.eqauls(null))) { doSomething } and this if ( (!myString.eqauls("")) && (myString!=null)) { doSomething } and this if ( myString.length()>0) { doSomething } And in all cases my program doSomething in spite on the fact that my string IS EMPTY. It equals to null. So, what is wrong with that?

    Read the article

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