[jboss-cvs] jboss-profiler/java/src/expansion/org/jboss/profiler/exp/view/util ...

Takuro Okada t2-okada at nri.co.jp
Thu Oct 26 04:58:57 EDT 2006


  User: tokada  
  Date: 06/10/26 04:58:57

  Added:       java/src/expansion/org/jboss/profiler/exp/view/util  Tag:
                        JBossProfiler_Expansion Signature.java
  Log:
  
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +111 -0    jboss-profiler/java/src/expansion/org/jboss/profiler/exp/view/util/Attic/Signature.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Signature.java
  ===================================================================
  RCS file: Signature.java
  diff -N Signature.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ Signature.java	26 Oct 2006 08:58:57 -0000	1.1.2.1
  @@ -0,0 +1,111 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + * Copyright 2006, JBoss Inc., and individual contributors as indicated
  + * by the @authors tag. See the copyright.txt in the distribution for a
  + * full listing of individual contributors.
  + *
  + * This is free software; you can redistribute it and/or modify it
  + * under the terms of the GNU Lesser General Public License as
  + * published by the Free Software Foundation; either version 2.1 of
  + * the License, or (at your option) any later version.
  + *
  + * This software is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  + * Lesser General Public License for more details.
  + *
  + * You should have received a copy of the GNU Lesser General Public
  + * License along with this software; if not, write to the Free
  + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  + */
  +
  +package org.jboss.profiler.exp.view.util;
  +
  +import java.util.Iterator;
  +import java.util.Map;
  +import java.util.TreeMap;
  +
  +/**
  + * This class provides to save hierarchical signature.
  + * 
  + * @author Takuro Okada (Nomura Research Institute, Ltd.)
  + * Copyright 2006 Nomura Research Institute, Ltd. All Rights Reserved.
  + * Copyright(c) Information-technology Promotion Agency, Japan. All rights reserved 2006.
  + * Result of Open Source Software Development Activities of Information-technology Promotion Agency, Japan.
  + */
  +public class Signature implements Iterable<Map.Entry<String, Signature.Type>> {
  +    
  +    private static final char DEFAULT_SEPARATOR = '.';
  +    
  +    public enum Type{PACKAGE, CLASS, METHOD;
  +        public String toString() {
  +            switch(ordinal()) {
  +                case 0: return "p";
  +                case 1: return "c";
  +                case 2: return "m";
  +            }
  +            return null;
  +        }
  +    };
  +    
  +    private Map<String, Type> expressions = new TreeMap<String, Type>();
  +    
  +    /**
  +     * Adds a signature.
  +     * @param source - source string of signature
  +     */
  +    public void add(String source) {
  +        char separatorChar = DEFAULT_SEPARATOR;
  +        boolean useClass = true;
  +        if(source.indexOf('/')==0) {
  +            separatorChar = '/';
  +            useClass = false;
  +        }
  +        int index = -1;
  +        while((index = source.indexOf(separatorChar, index+1))>=0) {
  +            if(index==0) {
  +                index = source.indexOf(separatorChar, 1);
  +            }
  +            String expression = source.substring(0, index);
  +            String remainder = source.substring(index+1);
  +            if(remainder.indexOf(separatorChar)>0) {
  +                expressions.put(expression, Type.PACKAGE);
  +            }else {
  +                if(useClass) {
  +                    expressions.put(expression, Type.CLASS);
  +                }else {
  +                    expressions.put(expression, Type.PACKAGE);
  +                }
  +                expressions.put(source, Type.METHOD);
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Returns signature map.
  +     * @return
  +     */
  +    public Iterator<Map.Entry<String, Type>> iterator() {
  +        return expressions.entrySet().iterator();
  +    }
  +    
  +    /**
  +     * Counts the depth of hierarchy.
  +     * @param source - source string of signature
  +     * @return count
  +     */
  +    public static int countDepth(String source) {
  +        char separatorChar = DEFAULT_SEPARATOR;
  +        if(source.indexOf('/')==0) {
  +            separatorChar = '/';
  +        }
  +        int count = 0;
  +        int index = 0;
  +        while((index = source.indexOf(separatorChar, index+1))>0) {
  +            count++;
  +        }
  +        return count;
  +    }
  +    
  +}
  
  
  



More information about the jboss-cvs-commits mailing list