Home | History | Annotate | Download | only in jarjar
      1 /**
      2  * Copyright 2007 Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.tonicsystems.jarjar;
     18 
     19 import com.tonicsystems.jarjar.util.*;
     20 import java.io.*;
     21 import java.util.*;
     22 
     23 abstract public class AbstractDepHandler implements DepHandler
     24 {
     25     protected final int level;
     26     private final Set<List<Object>> seenIt = new HashSet<List<Object>>();
     27 
     28     protected AbstractDepHandler(int level) {
     29         this.level = level;
     30     }
     31 
     32     public void handle(PathClass from, PathClass to) throws IOException {
     33         List<Object> pair;
     34         if (level == LEVEL_JAR) {
     35             pair = createPair(from.getClassPath(), to.getClassPath());
     36         } else {
     37             pair = createPair(from.getClassName(), to.getClassName());
     38         }
     39         if (!seenIt.contains(pair)) {
     40             seenIt.add(pair);
     41             handle(pair.get(0).toString(), pair.get(1).toString());
     42         }
     43     }
     44 
     45     abstract protected void handle(String from, String to) throws IOException;
     46 
     47     public void handleStart() throws IOException { }
     48     public void handleEnd() throws IOException { }
     49 
     50     private static List<Object> createPair(Object o1, Object o2) {
     51         List<Object> list = new ArrayList<Object>(2);
     52         list.add(o1);
     53         list.add(o2);
     54         return list;
     55     }
     56 }
     57