I'm playing around with HashMaps in Java and I've stumbled upon something that I can't make sense of. I can't seem to find a duplicate of my issue on here either.  I'm trying to create a Map that has a VertexPair key and an Integer value. The VertexPair is simply a container for 2 Vertex objects. When I create 2 VertexPairs that have the same hash code and are equal (verified by .equals()), they do not return the same value from my map.   Here is my code:  HashMap&lt;VertexPair, Integer&gt; edges = new HashMap&lt;VertexPair, Integer&gt;();  Vertex a = new Vertex("A"); Vertex b = new Vertex("B");  VertexPair p = new VertexPair(a, b); VertexPair m = new VertexPair(a, b); VertexPair n = new VertexPair(b, a); VertexPair check = new VertexPair(a, new Vertex("C"));  System.out.println(p.equals(m)); System.out.println(p.equals(n)); System.out.println(m.equals(n)); //just to be sure equals is working System.out.println(p.equals(check));  System.out.println(m.hashCode()); System.out.println(n.hashCode()); System.out.println(p.hashCode()); //just to be sure hashCode is working System.out.println(check.hashCode());  edges.put(p, 10);  System.out.println(edges.get(p)); System.out.println(edges.get(m)); System.out.println(edges.get(n));   And it's output:  true true true false 1757285723 1757285723 1757285723 -425440240 10 null null   Here is the VertexPair class as requested:  public final class VertexPair {      private HashSet&lt;Vertex&gt; set;      public VertexPair(Vertex a, Vertex b) {         if(a==null || b==null)             throw new NullPointerException("Vertexes must not be null");         set = new HashSet&lt;Vertex&gt;();         set.add(a);         set.add(b);     }      public HashSet&lt;Vertex&gt; getVertexes() {         return set;     }             @Override     public int hashCode() {         return set.hashCode();     }      public boolean equals(VertexPair p) {         if(!(p instanceof VertexPair))             return false;         if(p==this)             return true;         return set.equals(p.getVertexes());      }   }   Can someone please explain to me what's going on? I must be misunderstanding something crucial about HashMaps. Thanks in advance :)
I ran into an interesting behavior recently.  It seems that if I override .equals() to take a parameter other than Object, it doesn't get called.  Can anyone explain to me why this is happening?  It seems to violate my understanding of polymorphism in OOP, but maybe I'm missing something.  Here's much simpler code that shows what I'm seeing:  public class MyClass {   private int x;   public MyClass(int n) { x = n; }   public boolean equals(Object o) { return false; }   public boolean equals(MyClass mc) { return x == mc.x; }   public static void main(String[] args) {     List&lt;MyClass&gt; list = new ArrayList&lt;MyClass&gt;();     list.add(new MyClass(3));     System.out.println("Contains 3? " + list.contains(new MyClass(3)));   } }   When this is run, it prints "Contains 3? false".  It looks like the equals(Object) function is called, even though there is another that would work.  By contrast, if I write equals like this the code works as expected:  public boolean equals(Object o) {   if(!(o instanceof MyClass))     return false;   MyClass mc = (MyClass)o;   return x == mc.x; }   Why isn't it figuring out which version of the function to call based on the type of the parameter?
Microphone doesn't work in Hangouts I have a DELL inspiron 5537 i5 laptop with Ubuntu 14.04. When I use Google Hangouts on Google Chrome, my mic just doesn't work. When I open the secure info setting it shows that the mic is allowed.  Works in Windows.  I have tried to add the Hangouts plugin and it also doesn't work.  Is there any to solve the problem? I was reading . They are performing a logistic regression (with R). At some point they calculate the probability of getting a residual deviance higher than the one they got on a $\chi^2$ distribution with degrees of freedom equal to the degrees of freedom of the model. Copying-pasting from their website...   &gt; glm( cbind(using,notUsing) ~ age + hiEduc + noMore, family=binomial)  Call:  glm(formula = cbind(using, notUsing) ~ age + hiEduc + noMore,            family = binomial)   Coefficients: (Intercept)     age25-29     age30-39     age40-49       hiEduc       noMore       -1.9662       0.3894       0.9086       1.1892       0.3250       0.8330    Degrees of Freedom: 15 Total (i.e. Null);  10 Residual Null Deviance:      165.8  Residual Deviance: 29.92        AIC: 113.4        The residual deviance of 29.92 on 10 d.f. is highly significant:  &gt; 1-pchisq(29.92,10) [1] 0.0008828339       so we need a better model     Why does it make sense to compute 1-pchisq(29.92,10) and why does a low probability indicate that something is going wrong with their model? So from what I understand transistors are one of the most important electronic elements for computers because of TTL (Transistors-Transistors Logic).  Is this true? If so, how exactly does this work? I have heard the terms "logic gate" and "logic block" tossed around. Every partial order can be extended to a linear ordering NSString instance reports its class as NSCFString My objective here is really simple -- I'm trying to set an NSString to some test data, then return the class, which should be NSString. Here's my code:  NSString* stringer = [NSString stringWithFormat: @"Test"]; NSLog(@"%@", [stringer class]);   The log says that the class is NSCFString, not NSString. What's going on here? How to remove local (untracked) files from the current Git working tree Is there a cryptographic algorithm which is immune to side channel attacks? Is there any cryptographic algorithm immune to side channel attacks based on scan chain? In VLSI point of view. I am trying to learn how to find the product of non-disjoint cycles, as you may have guessed from the title. I have the basic idea, but I do not understand it entirely.  I am trying to find $(1352)(256)$ and $(1634)(1352)$, multiplying from right to left.  Please give me some hints/suggestions.  Thank you. This problem comes from , who do not rigorously demonstrate (in their solution key) that the statistic is not sufficient.  Let $X_1,\dots,X_n$ be a random sample from a population with PDF $f(x|\theta)=\theta x^{\theta-1} \cdot 1_{\{x\in(0,1)\}}$ for $\theta&gt;0$. Show that $\sum_i X_i$ is not sufficient for $\theta$.  If you write out the PDF $p(\vec{x}|\theta)$ of the random sample, it is clear by the factorization theorem that $\prod_i X_i$ or $\sum_i \log(X_i)$ are sufficient for $\theta$; the PDF $p$ also suggests $\sum_i X_i$ is not sufficient for $\theta$. However, to rigorously demonstrate this, we need to analyze $p(\vec{x},\theta)/q(T(\vec{x},\theta)$, where $p$ is the distribution of sample $\vec{x}$, $q$ is the distribution of the statistic $T(\vec{X})=\sum_i X_i$. But finding the distribution of $T(X)=\sum_i X_i$ seems impractical. I have observed that $f$ is the PDF of a Beta($\theta$,1) distribution, but checking online, the distribution of the sum of Beta random variables doesn't appear to have a closed form. Are there any alternative routes (e.g., showing there is no factorization involving $T(\vec{X})$)? Did C&amp;B leave out a full explanation that $\sum_i X_i$ is not sufficient because none actually exist? Are user accounts on data.stackexchange.com and Stack Exchange two different entities? I tried to search for similar questions, as I always do, but was not able to find one. I just created a new  on Data.Stack Exchange with my existing Google OpenID and it seems to be not associated with my regular Stack Exchange account. Is this by design? and if so, why? Prove if $n \in \mathbb N$, then $\frac{1}{2!}+\frac{2}{3!}+\frac{3}{4!}+\cdots+\frac{n}{\left(n+1\right)!} = 1-\frac{1}{\left(n+1\right)!}$   So I proved the base case where $n=1$ and got $\frac{1}{2}$  Then since $n=k$ implies $n=k+1$ I setup the problem like so:  $\frac{k}{(k+1)!}+\frac{(k+1)}{(k+2)!}=1-\frac{1}{(k+2)!}$  After trying to simplify it I got the following:  $\frac{k(k+2)!+(k+1)(k+1)!}{(k+1)!(k+2)!}=1-\frac{1}{(k+2)!}$  However, I'm having trouble simplifying it to match the RHS.  Hints? $n!+1$ being a perfect square One observes that  \begin{equation*} 4!+1 =25=5^{2},~5!+1=121=11^{2}  \end{equation*} is a perfect square. Similarly for $n=7$ also we see that $n!+1$ is a perfect square. So one can ask the truth of this question:   Is $n!+1$ a perfect square for infinitely many $n$? If yes, then how to prove. Sum of digits of repunits Thousands of 404 errors in Google Webmaster Tools Because of a former error in our ASP.Net application, created by my predecessor and undiscovered for a long time, thousands of wrong URLs where created dynamically. The normal user did not notice it, but Google followed these links and crawled itself through these incorrect URLs, creating more and more wrong links.  To make it clearer, consider the url     example.com/folder   should create the link     example.com/folder/subfolder   but was creating     example.com/subfolder   instead. Because of bad url rewriting, this was accepted and by default showed the index page for any unknown url, creating more and more links like this.     example.com/subfolder/subfolder/....   The problem is resolved by now, but now I have thousands of 404 errors listed in the Google Webmaster Tools, which got discovered 1 or 2 years ago, and more keep coming up.  Unfortunately the links do not follow a common pattern that I could deny for crawling in the robots.txt.  Is there anything I can do to stop google from trying out those very old links and remove the already listed 404s from Webmaster Tools? interpreting scatter plots I have plotted my predictors versus my response variable in order to be able to fit a good Poisson model to my data. However i am getting  those scatter plots for nearly all predictors which make me rather worried since including these predictors is making my residual deviance a value of 575 on 571 df(high enough) Thanks Kinematics with non constant acceleration A particle experiences an acceleration described by  $$ a=kx^{-2} $$ where x is the displacement from the origin and k is an arbitrary constant.  To what value does the velocity v of the particle converge to as x approaches infinity if the particle starts at some point x0?  If I approach this problem with energy, then $$ W = \int F \mathrm{d}x $$ $$  = \int_{x_0}^\infty mkx^{-2} \mathrm{d}x $$ $$  = mk(-\infty^{-1}+{x_0}^{-1}) $$ $$ W = K = mk{x_0}^{-1} $$ $$ \frac{1}{2}mv^2 = mk{x_0}^{-1} $$ $$ v = \sqrt{2k{x_0}^{-1}} $$  How would I solve this problem with pure kinematics? (there appears to be some sort of cyclical dependency where acceleration affects velocity, velocity affects displacement, and displacement affects acceleration)  Likewise, two particles experience accelerations described by $$ a_1=k_1x^{-2} $$ $$and $$ $$ a_2=-k_2x^{-2} $$ where x is the distance between the two particles  What two velocities do the particles reach as x approaches infinity if the two particles are initially separated by some x0? Force Messages to use SMS for specific contact rather than iMessage? Essentially, I would like to set my phone so that all my outgoing messages to a specific friend, with whom I currently text back and forth over iMessage, are sent out over SMS, never iMessage. Additionally, I would like to block any incoming iMessage texts of his and (hopefully) they'll fail and be resent via SMS.  Let me restate that: I would like to force SMS for both parties, going both ways, for a specific individual contact.   Is this possible? Blocking any usage of iMessage between myself and this other individual, so they must either send and receive any texts to or from me via SMS (or the texts fail/never arrive). What is the number of invertible $n\times n$ matrices in $\operatorname{GL}_n(F)$? $F$ is a finite field of order $q$. What is the size of $\operatorname{GL}_n(F)$ ?  I am reading Dummit and Foote "Abstract Algebra".  The following formula is given:  $(q^n - 1)(q^n - q)\cdots(q^n - q^{n-1})$.  The case for $n = 1$ is trivial.  I understand that for $n = 2$  the first row of the matrix can be any ordered pair of field elements except for $0,0$. and the second row can be any ordered pair of field elements that is not a multiple of the first row.  So for $n = 2$  there are $(q^n - 1)(q^n - q)$ invertible matrices.  For $n\geq 3$, I cannot seem to understand why  the formula works.  I have looked at Sloane's OEIS A002884.  I have also constructed and stared at a list of all $168$ $3\times 3$ invertible matrices over $GF(2)$.  I would most appreciate a concrete and detailed explanation of how say $(2^3 - 1)(2^3 - 2)(2^3 - 2^2)$ counts these $168$ matrices. I'm unable to update nodejs, and I can't see why.  If I were to make a guess, I'd say that I have two repositories listed in apt-get, that both contain a nodejs package.  Here's what I've done:  Remove old version:  sudo apt-get remove --purge nodejs npm   Then, going by , I've run:  curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -   And then:  sudo apt-get install -y nodejs   I then run:  nodejs -v   Which returns:  v0.10.25   Can anyone explain what's going wrong? And how I can remedy this situation?  Many thanks. I have a JavaScript object. Is there a built-in or accepted best practice way to get the length of this object? const myObject = new Object(); myObject[&quot;firstname&quot;] = &quot;Gareth&quot;; myObject[&quot;lastname&quot;] = &quot;Simpson&quot;; myObject[&quot;age&quot;] = 21;