Android Open Source - RealtimeMessaging-Android Strings






From Project

Back to project page RealtimeMessaging-Android.

License

The source code is released under:

MIT License

If you think the Android project RealtimeMessaging-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * @fileoverview This file contains the implementation of some Strings utilities methods
 * @author ORTC team members (ortc@ibt.pt) 
 *//*from  w  w w .j a v a2s  . c  o m*/
package ibt.ortc.api;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Static class containing the implementation of some Strings utilities methods
 * 
 * @version 2.1.0 27 Mar 2013
 * @author ORTC team members (ortc@ibt.pt) 
 */
public class Strings {
  /**
   * Checks if a string is null or an empty text
   * 
   * @param text
   *            Text to check
   * @return boolean True if text is null or empty otherwise false
   */
  public static boolean isNullOrEmpty(String text) {
        return text == null || text.trim().equals("");
  }

  private static final char[] symbols = new char[36];

  static {
        // CAUSE: For Loops Should Use Braces
        for (int idx = 0; idx < 10; ++idx) {
      symbols[idx] = (char) ('0' + idx);
        }
        // CAUSE: For Loops Should Use Braces
        for (int idx = 10; idx < 36; ++idx) {
      symbols[idx] = (char) ('a' + idx - 10);
  }
    }

  private static final Random random = new Random();

  /**
   * Generates a random alphanumeric string
   * @param length Number of characters the random string contains
   * @return String with the specified length
   */
  public static String randomString(int length) {
        // CAUSE: If-Else Statements Should Use Braces
        if (length < 1) {
            throw new IllegalArgumentException(String.format("length < 1: %s", length));
        }

    char[] buf = new char[length];

    return nextString(buf);
  }

  private static String nextString(char[] buf) {
        // CAUSE: For Loops Should Use Braces
        for (int idx = 0; idx < buf.length; ++idx) {
      buf[idx] = symbols[random.nextInt(symbols.length)];
        }
    return new String(buf);
  }
  
  public static boolean ortcIsValidInput(String value) {
    Pattern regexPattern = Pattern.compile("^[\\w-:\\/.]*$");
    Matcher matcher = regexPattern.matcher(value);
    
    return (matcher != null && matcher.matches()) ? true : false;
  }
  
  public static boolean ortcIsValidChannelForNotifications(String value) {
    Pattern regexPattern = Pattern.compile("^[\\w-:]*$");
    Matcher matcher = regexPattern.matcher(value);
    
    return (matcher != null && matcher.matches()) ? true : false;
  }
  
  public static boolean ortcIsValidUrl(String value) {
    Pattern regexPattern = Pattern.compile("^\\s*(http|https):\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-\\/]))?\\s*$");
    Matcher matcher = regexPattern.matcher(value);
    
    return (matcher != null && matcher.matches()) ? true : false;
  }
  
  public static String treatUrl(String url) {
        // CAUSE: Assignment to method parameter
        String lUrl = url;
        if (!Strings.isNullOrEmpty(lUrl)) {
            lUrl = lUrl.trim();
      
            if (lUrl.charAt(lUrl.length() - 1) == '/') {
                lUrl = lUrl.substring(0, lUrl.length() - 1);
      }
    }
    
        return lUrl;
    }

    // CAUSE: Utility class contains only static elements and is still instantiable
    private Strings() {
  }
}




Java Source Code List

ibt.ortc.api.ApplicationTest.java
ibt.ortc.api.Authentication.java
ibt.ortc.api.Balancer.java
ibt.ortc.api.ChannelPermissions.java
ibt.ortc.api.InvalidBalancerServerException.java
ibt.ortc.api.OnDisablePresence.java
ibt.ortc.api.OnEnablePresence.java
ibt.ortc.api.OnPresence.java
ibt.ortc.api.OnRestWebserviceResponse.java
ibt.ortc.api.OrtcAuthenticationNotAuthorizedException.java
ibt.ortc.api.Ortc.java
ibt.ortc.api.Pair.java
ibt.ortc.api.Presence.java
ibt.ortc.api.RestWebservice.java
ibt.ortc.api.SecureWebConnections.java
ibt.ortc.api.Strings.java
ibt.ortc.extensibility.ChannelSubscription.java
ibt.ortc.extensibility.CharEscaper.java
ibt.ortc.extensibility.ConnectionProtocol.java
ibt.ortc.extensibility.DispatchedMessages.java
ibt.ortc.extensibility.EventEnum.java
ibt.ortc.extensibility.GcmOrtcBroadcastReceiver.java
ibt.ortc.extensibility.GcmOrtcIntentService.java
ibt.ortc.extensibility.GcmRegistration.java
ibt.ortc.extensibility.HeartbeatSender.java
ibt.ortc.extensibility.OnConnected.java
ibt.ortc.extensibility.OnDisconnected.java
ibt.ortc.extensibility.OnException.java
ibt.ortc.extensibility.OnMessageWithPayload.java
ibt.ortc.extensibility.OnMessage.java
ibt.ortc.extensibility.OnReconnected.java
ibt.ortc.extensibility.OnReconnecting.java
ibt.ortc.extensibility.OnSubscribed.java
ibt.ortc.extensibility.OnUnsubscribed.java
ibt.ortc.extensibility.OrtcClient.java
ibt.ortc.extensibility.OrtcFactory.java
ibt.ortc.extensibility.exception.OrtcAlreadyConnectedException.java
ibt.ortc.extensibility.exception.OrtcDoesNotHavePermissionException.java
ibt.ortc.extensibility.exception.OrtcEmptyFieldException.java
ibt.ortc.extensibility.exception.OrtcGcmException.java
ibt.ortc.extensibility.exception.OrtcInvalidCharactersException.java
ibt.ortc.extensibility.exception.OrtcMaxLengthException.java
ibt.ortc.extensibility.exception.OrtcNotConnectedException.java
ibt.ortc.extensibility.exception.OrtcNotSubscribedException.java
ibt.ortc.extensibility.exception.OrtcSubscribedException.java
ibt.ortc.ortclib.ApplicationTest.java
ibt.ortc.ortclib.MainActivity.java
ibt.ortc.ortclib.SettingsActivity.java
ibt.ortc.plugins.IbtRealtimeSJ.IbtRealtimeSJClient.java
ibt.ortc.plugins.IbtRealtimeSJ.IbtRealtimeSJFactory.java
ibt.ortc.plugins.IbtRealtimeSJ.OrtcMessage.java
ibt.ortc.plugins.IbtRealtimeSJ.OrtcOperation.java
ibt.ortc.plugins.IbtRealtimeSJ.OrtcServerErrorException.java
ibt.ortc.plugins.websocket.WebSocketConnection.java
ibt.ortc.plugins.websocket.WebSocketEventHandler.java
ibt.ortc.plugins.websocket.WebSocketException.java
ibt.ortc.plugins.websocket.WebSocketHandshake.java
ibt.ortc.plugins.websocket.WebSocketMessage.java
ibt.ortc.plugins.websocket.WebSocketReceiver.java
ibt.ortc.plugins.websocket.WebSocketSender.java
ibt.ortc.plugins.websocket.WebSocket.java