One trick of JAVA’s TreeSet


 I used to meet a bug while using a TreeSet to save & order some objects. I found some objects are lost although they are totally different with other objects.

What happened

According to the official document of JAVA, TreeSet exactly uses TreeMap to save elements. Not like HashMap and HashSet, TreeMap uses Comparator other than Objects’ hashCode and equals() to remove duplicates. If Comparator return 0, TreeSet or TreeMap don’t add the element into itself.

In this case, my Comparator compares one integer variable called size, which only depends on the size of an input object. So that all objects with the same size value have been defined as the same, only the first one can be kept.


  1. Update Comparator
  2. Change to other Sorted Set

Overall structure of RabbitMQ

RabbitMQ is an open source message broker middleware created in 2007 and that is now managed by GoPivotal.

Most of the operations are performed in memory. RabbitMQ is not “disk-oriented”:
messages are received by brokers via an exchange (i.e. a logical entry point that will decide based on some criteria in which queue(s) the broker should place a message) and then pushed to the registered consumers. The broker pushes randomly queued messages toward the consumers. They thus receive unordered messages, and do not need to remember anything about the queue state (as messages are unordered and pushed by the brokers. They do not and cannot fetch specific messages on their own). Messages are paged out to disc only if there is no more memory available, or if they are explicitly told to be stored.

Continue reading “Overall structure of RabbitMQ”

Hadoop error: log4j:WARN No appenders could be found for logger

log4j need a configure file to tell it how to work.

Continue reading “Hadoop error: log4j:WARN No appenders could be found for logger”

Leetcode 210. Course Schedule II

210. Course Schedule II


There are a total of n courses you have to take, labeled from 0 to n - 1.

Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1]

Continue reading “Leetcode 210. Course Schedule II”

Reproduce:WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for ‘jquery’. Please add a ScriptResourceMapping named jquery(case-sensitive)

This problem occurs while using control RangeValidation. And the answer I can use is following.

In webconfig and search for:

Delete <add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms" />

Continue reading “Reproduce:WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for ‘jquery’. Please add a ScriptResourceMapping named jquery(case-sensitive)”

solving unittest bug of csrf_token in Django

in the Chapter 5 of Book “Test-Driven Web Development with Python” written by Harry J.W. Percival, there is a bug in the part of unit test.

while high version of Django(>1.7) rendering template, it will replace the template tag with a <input type="hidden">, the value is csrf_token.
Continue reading “solving unittest bug of csrf_token in Django”