Friday, December 21, 2007

Two most fast ways to set up SubVersion server

Here I would like to introduce two quick instructions to set up Subversion server, this is for people who can't wait to set up and using Subversion. But in order to use Subversion correctly, I still strongly recommend people to study Subversion books in detail.

I. Set up Subversion server running over svn:// protocol

  1. After you install Subversion, open shell, change directory to subversion's /bin folder.
  2. Type svnadmin create <Your Resporitory Path>

    For example: svnadmin create /home/svn-repos
  3. Then Subversion will create necessary files into repository folder.
  4. Change directory to repository, you will find "svnserve.conf" and "passwd" two files under "{repository-root}/conf" folder.
  5. First to open "svnserve.conf" file, you can just clean all of the default content, and just put the following content into that file.

    [general]

    anon-access=none

    password-db=passwd

  6. After that, open "passwd" file. Follow the syntax below to add user name and password.

    [users]

    user1=password1

    user2=password2

  7. Finally, start Subversion server.

    Change directory back to subversion's bin folder, execute svnserve -d -r <Your Repository Path>
  8. Now you can start to commit and update source with your team members.



II. Set up SubVersion server running over http:// protocol
<This part will be added soon....>

Monday, October 29, 2007

A Linked List Sorter


About sorting LinkedList, I just implemented a sotrer class two weeks ago because I was asked how to sort a linked list. I tried to write a Java class to sort LinkedList.
Here is my implementation, just for everyone reference, and please advise if any mistake.

Suppose we have a data structure just as below, upper part display origional position, we have to sort out a sequence as lower part.
(Element has null parent ID means it is the first/top one)


First of all, I define an Interface as below:

public interface SortingElement {

Long getId();
Long getParentId();
void setParentId(Long parentId);

}

A sorting element is composed of two value, one is my id, the other is the id which I am linking to (that means parentId). So we have getId() and a pair of setter and getter for parentId.

Following is the LinkedListSorter class:

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class Sorter {

public static List sort(List elements) {

List rs = new ArrayList();
Map temp = new HashMap();
SortingElement currentElement = null;
for (SortingElement element : elements) {
Long parentId = element.getParentId();
if (parentId != null)
temp.put(element.getParentId(), element);
else
currentElement = element;
}

for (int i=0; i<elements.size(); i++) {
Long childParentId = currentElement.getId();
SortingElement child = temp.get(childParentId);
rs.add(currentElement);
currentElement = child;
}
return rs;
}
}


Before passing List of SortingElement into sorter, we have a pre-condition has to be satisfied, that is only one element can return a null parent id, it means it sits at the top of these elements, others elements must contain its parent id.

Gets into the method, first of all these parent Id value of each elements are extracted out, they are put into a Map which using parent Id as key and element itsself as value.

Then a List is used to sequentially retrieve element from Map according each elements parent Id.

I didn't test its efficiency, but at least it seems works up to now by my test case. Attached is the test Java class, just for you are interested in it.

Tuesday, October 02, 2007

Study note: how the limitless nonvolatile memory will affect the future of world

I am studying the MSc of IT programme in Liverpool University. This week we discussed how the limitless nonvolatile memory will affect the future of world.


Below is the discussion summary of what I wrote to forum wtoday:


Hi All,

Super large but cheap storage device is not a dream in the coming future, but to keep the stored data organized is also the necessary thing we have to bear in mind. I think the problem is not how large of the storage capacity, it is because we misuse the large storage device, and the lack of softwares to help organize the large amount of documents, photos or binary files.

Vee mentioned a key point of these large amount of documents or images - metadata. Everyone knows the concept of web 2.0. It is a popular marketing phrase we can see in the Internet. If we can't organize data well, even 10MB data we could mess it up. Web 2.0 emphasize the interaction among Internet users, people contribute everything into many kinds of web 2.0 model web site, e.g. Del.icio.us, Flicker. Everytime you bookmark or upload something, you have to give metadata to your documents or photos, thus the sofrware, might be a search engine or something like that, behind the user interface can start to analyze the new uploaded document, and associate these data by many kinds of algorism. I would say that the 20th century is the era of data collecting century; and the 21th century is the era of data manipulating. So many ERP systems were built in the last century, these data are collected large enough to start predicting trends, analyzing behavior or something else. Thus who owns the most powerful search engine or analyzing algorism, who will lead the business of 21th century. So a stong back bone hardware to support these large raw data or results is the same important.

A reliable, fast, large, and reasonable price sotrage device is the foundation to support the everything above make make true in the future.

Thursday, May 10, 2007

An easy way to remove blank page generated by JasperReports

If your JasperReports report has one more sub-reports and it was generated as PDF file. In some circumstances, a blank page might be found within PDF file. Here is my solution to easily remove it.

private void removeBlankPage(List<JRPrintPage> pages) {

for (Iterator<JRPrintPage> i=pages.iterator(); i.hasNext();) {
JRPrintPage page = i.next();
if (page.getElements().size() == 0)
i.remove();
}
}

This method should be called before you flush your JasperPrint instance to PDF.

Followed with the sample code, it would be better to know the object hierarchy of JasperPrint.

  1. 1. A JasperPrint has one or more JRPrintPage, you can get it via getPages() method of JasperPrint. It returns a List of JRPrintPage. If you have three elements, then your printer will print 3 pages.
  2. 2. A JRPrintPage has one ore more JRPrintElement, each element might be a string of text, or a picture, or a rectangle, etc. You can change its position or content dynamically, or even add new JRPrintElement into JRPrintPage.