Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.Collections;
import java.util.zip.ZipEntry;

import java.util.Comparator;
import java.util.List;

public class Main {
    private static Comparator<ZipEntry> zipFilenameCompare = new Comparator<ZipEntry>() {
        public int compare(ZipEntry lhs, ZipEntry rhs) {
            String ls = lhs.getName();
            String rs = rhs.getName();
            if (ls.length() == rs.length())
                return lhs.getName().compareTo(rhs.getName());
            else if (ls.length() > rs.length())
                return 1;
            return -1;
        }
    };

    private static ZipEntry findRootInstallTxt(List<ZipEntry> entries) {
        List<ZipEntry> iz = new ArrayList<ZipEntry>();
        for (ZipEntry e : entries) {
            if (e.getName().contains("install.txt"))
                iz.add(e);
        }

        if (iz.size() == 1)
            return iz.get(0);

        //Log.d(TAG, "has " + iz.size() + " install.txts");
        // sort to get shortest one 
        Collections.sort(iz, zipFilenameCompare);
        //Log.d(TAG, "first" + iz.get(0).getName() + ", last" + iz.get(iz.size() -1).getName());
        return iz.get(0);
    }
}