001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.apache.servicemix.vfs.comparator;
017    
018    import java.util.Comparator;
019    
020    import org.apache.commons.vfs.FileObject;
021    
022    /**
023     * <p>
024     * Simple file object comparator working on file size.
025     * </p>
026     * 
027     * @author jbonofre
028     */
029    public class SizeComparator implements Comparator<FileObject> {
030    
031        /*
032         * (non-Javadoc)
033         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
034         */
035        public int compare(FileObject file1, FileObject file2) {
036            try {
037                return ((int)file1.getContent().getSize()-(int)file2.getContent().getSize());
038            } catch (Exception e) {
039                return 0;
040            }
041        }
042    
043    }