Here you can find the source of shorten(String pkg, boolean shorten)
Parameter | Description |
---|---|
pkg | a package name |
shorten | whether to shorten it or not |
public static String shorten(String pkg, boolean shorten)
//package com.java2s; /**//from w w w . ja va 2 s. c o m * Copyright 1&1 Internet AG, https://github.com/1and1/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * @param pkg a package name * @param shorten whether to shorten it or not * @return the shortened name, in the form a.b.c.d.package */ public static String shorten(String pkg, boolean shorten) { if (!shorten) { return pkg; } String[] parts = pkg.split("\\."); StringBuilder result = new StringBuilder(); for (int i = 0; i < parts.length - 1; i++) { result.append(parts[i].charAt(0)); result.append("."); } result.append(parts[parts.length - 1]); return result.toString(); } }