![]() |
Hubiquitus Android
0.3
Android client for hubiquitus protocol
|
00001 /* 00002 * Copyright (c) Novedia Group 2012. 00003 * 00004 * This file is part of Hubiquitus. 00005 * 00006 * Hubiquitus is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * Hubiquitus is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with Hubiquitus. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 package org.hubiquitus.hapi.util; 00021 00022 00023 import java.net.URI; 00024 import java.util.List; 00025 00032 public class HUtil { 00033 00039 public static <T> int pickIndex(List<T> list) { 00040 int index = 0; 00041 00042 int size = list.size(); 00043 index = (int) (Math.random() * size); 00044 return index; 00045 } 00046 00052 public static String getHost(String endPoint) { 00053 String host = null; 00054 00055 try { 00056 URI uri = new URI(endPoint); 00057 host = uri.getHost(); 00058 } catch (Exception e) { 00059 host = null; 00060 } 00061 00062 return host; 00063 } 00064 00070 public static int getPort(String endpoint) { 00071 int port = 0; 00072 00073 try { 00074 URI uri = new URI(endpoint); 00075 port = uri.getPort(); 00076 } catch (Exception e) { 00077 port = 0; 00078 } 00079 00080 return port; 00081 } 00082 00088 public static String getPath(String endpoint) { 00089 String path = null; 00090 00091 try { 00092 URI uri = new URI(endpoint); 00093 path = uri.getPath(); 00094 } catch (Exception e) { 00095 path = null; 00096 } 00097 00098 return path; 00099 } 00100 00106 public static String getHserverJid(String hserver, String domain) { 00107 return hserver + "." + domain; 00108 } 00109 00110 } 00111