public static boolean validSystemNameFormat(String systemName,char type){
  Matcher matcher=getAllPattern().matcher(systemName);
  if (!matcher.matches()) {
    return false;
  }
  if (matcher.group(2).charAt(0) != type) {
    log.error("type in " + systemName + " does not match "+ type);
    return false;
  }
  Pattern p;
  if (type == 'L') {
    p=getLightPattern();
  }
 else   if (type == 'T') {
    p=getTurnoutPattern();
  }
 else   if (type == 'H') {
    p=getHeadPattern();
  }
 else   if (type == 'S') {
    p=getSensorPattern();
  }
 else {
    log.error("cannot match type in " + systemName + ", which is unexpected");
    return false;
  }
  Matcher m2=p.matcher(systemName);
  if (!m2.matches()) {
    log.error("illegal system name format: " + systemName + " for type "+ type);
    return (false);
  }
  int node=-1;
  int bit=-1;
  if (matcher.group(7) != null) {
    int num=Integer.valueOf(matcher.group(7)).intValue();
    if (num > 0) {
      node=num / 1000;
      bit=num % 1000;
    }
 else {
      log.error("invalid value in system name: " + systemName);
      return false;
    }
  }
 else {
    node=Integer.valueOf(matcher.group(4)).intValue();
    bit=Integer.valueOf(matcher.group(6)).intValue();
  }
  if ((node < 1) || (node > 127)) {
    log.error("invalid node number " + node + " in "+ systemName);
    return false;
  }
  if ((type == 'T') || (type == 'H') || (type == 'L')) {
    if (!((bit >= 101 && bit <= 124) || (bit >= 201 && bit <= 224) || (bit >= 301 && bit <= 324)|| (bit >= 401 && bit <= 424))) {
      log.error("invalid bit number " + bit + " in "+ systemName);
      return false;
    }
  }
 else {
    assert type == 'S';
    String subtype=matcher.group(5);
    if (subtype == null) {
      if ((bit < 1) || (bit > 224)) {
        log.error("invalid bit number " + bit + " in "+ systemName);
        return false;
      }
 else {
        return true;
      }
    }
    subtype=subtype.toUpperCase();
    if (subtype.equals("A")) {
      if ((bit < 1) || (bit > 24)) {
        log.error("invalid bit number " + bit + " in "+ systemName);
        return false;
      }
    }
 else     if (subtype.equals("M")) {
      if ((bit < 1) || (bit > 24)) {
        log.error("invalid bit number " + bit + " in "+ systemName);
        return false;
      }
    }
 else     if (subtype.equals("S")) {
      if ((bit < 1) || (bit > 24)) {
        log.error("invalid bit number " + bit + " in "+ systemName);
        return false;
      }
    }
 else     if (subtype.equals("P")) {
      if ((bit < 1) || (bit > 96)) {
        log.error("invalid bit number " + bit + " in "+ systemName);
        return false;
      }
    }
  }
  return true;
}

public static boolean validSystemNameFormat ( String systemName , char type ) { Matcher matcher = getAllPattern ( ) . matcher ( systemName ) ; if ( ! matcher . matches ( ) ) { return false ; } if ( matcher . group ( 2 ) . charAt ( 0 ) != type ) { log . error ( "type in " + systemName + " does not match " + type ) ; return false ; } Pattern p ; if ( type == 'L' ) { p = getLightPattern ( ) ; } else if ( type == 'T' ) { p = getTurnoutPattern ( ) ; } else if ( type == 'H' ) { p = getHeadPattern ( ) ; } else if ( type == 'S' ) { p = getSensorPattern ( ) ; } else { log . error ( "cannot match type in " + systemName + ", which is unexpected" ) ; return false ; } Matcher m2 = p . matcher ( systemName ) ; if ( ! m2 . matches ( ) ) { log . error ( "illegal system name format: " + systemName + " for type " + type ) ; return ( false ) ; } int node = - 1 ; int bit = - 1 ; if ( matcher . group ( 7 ) != null ) { int num = Integer . valueOf ( matcher . group ( 7 ) ) . intValue ( ) ; if ( num > 0 ) { node = num / 1000 ; bit = num % 1000 ; } else { log . error ( "invalid value in system name: " + systemName ) ; return false ; } } else { node = Integer . valueOf ( matcher . group ( 4 ) ) . intValue ( ) ; bit = Integer . valueOf ( matcher . group ( 6 ) ) . intValue ( ) ; } if ( ( node < 1 ) || ( node > 127 ) ) { log . error ( "invalid node number " + node + " in " + systemName ) ; return false ; } if ( ( type == 'T' ) || ( type == 'H' ) || ( type == 'L' ) ) { if ( ! ( ( bit >= 101 && bit <= 124 ) || ( bit >= 201 && bit <= 224 ) || ( bit >= 301 && bit <= 324 ) || ( bit >= 401 && bit <= 424 ) ) ) { log . error ( "invalid bit number " + bit + " in " + systemName ) ; return false ; } } else { assert type == 'S' ; String subtype = matcher . group ( 5 ) ; if ( subtype == null ) { if ( ( bit < 1 ) || ( bit > 224 ) ) { log . error ( "invalid bit number " + bit + " in " + systemName ) ; return false ; } else { return true ; } } subtype = subtype . toUpperCase ( ) ; if ( subtype . equals ( "A" ) ) { if ( ( bit < 1 ) || ( bit > 24 ) ) { log . error ( "invalid bit number " + bit + " in " + systemName ) ; return false ; } } else if ( subtype . equals ( "M" ) ) { if ( ( bit < 1 ) || ( bit > 24 ) ) { log . error ( "invalid bit number " + bit + " in " + systemName ) ; return false ; } } else if ( subtype . equals ( "S" ) ) { if ( ( bit < 1 ) || ( bit > 24 ) ) { log . error ( "invalid bit number " + bit + " in " + systemName ) ; return false ; } } else if ( subtype . equals ( "P" ) ) { if ( ( bit < 1 ) || ( bit > 96 ) ) { log . error ( "invalid bit number " + bit + " in " + systemName ) ; return false ; } } } return true ; }
public static method to validate system name format
