public static String shortenDbName(String dbName,int desiredLength){
  StringBuilder dbBuf=new StringBuilder(dbName);
  if (dbBuf.length() > desiredLength) {
    for (int i=dbBuf.length() - 1; i > 0; i--) {
      if (dbBuf.charAt(i - 1) == '_') {
        continue;
      }
      char curChar=dbBuf.charAt(i);
      if (vowelBag.indexOf(curChar) > 0) {
        dbBuf.deleteCharAt(i);
      }
    }
  }
  while (dbBuf.indexOf("__") > 0) {
    dbBuf.deleteCharAt(dbBuf.indexOf("__"));
  }
  while (dbBuf.length() > desiredLength) {
    boolean removedChars=false;
    int usIndex=dbBuf.lastIndexOf("_");
    while (usIndex > 0 && dbBuf.length() > desiredLength) {
      int prevUsIndex=dbBuf.lastIndexOf("_",usIndex - 1);
      if (prevUsIndex < 0 && usIndex < 4) {
        break;
      }
      if (prevUsIndex >= 0 && (usIndex - prevUsIndex) <= 4) {
        usIndex=prevUsIndex;
        continue;
      }
      dbBuf.deleteCharAt(usIndex - 2);
      removedChars=true;
      if (usIndex > 2) {
        usIndex=dbBuf.lastIndexOf("_",usIndex - 2);
      }
 else {
        break;
      }
    }
    if (dbBuf.length() > desiredLength) {
      int removeIndex=dbBuf.length() - 1;
      int prevRemoveIndex=dbBuf.lastIndexOf("_",removeIndex - 1);
      if (prevRemoveIndex < 0 || (removeIndex - prevRemoveIndex) >= 3) {
        dbBuf.deleteCharAt(removeIndex - 1);
        removedChars=true;
      }
    }
    while (dbBuf.indexOf("__") > 0) {
      dbBuf.deleteCharAt(dbBuf.indexOf("__"));
      removedChars=true;
    }
    if (!removedChars) {
      break;
    }
  }
  while (dbBuf.indexOf("__") > 0) {
    dbBuf.deleteCharAt(dbBuf.indexOf("__"));
  }
  while (dbBuf.length() > desiredLength) {
    int firstUs=dbBuf.indexOf("_");
    if (firstUs > 0) {
      int nextUs=dbBuf.indexOf("_",firstUs + 1);
      if (nextUs > 0) {
        dbBuf.delete(firstUs,nextUs);
      }
    }
  }
  return dbBuf.toString();
}

public static String shortenDbName ( String dbName , int desiredLength ) { StringBuilder dbBuf = new StringBuilder ( dbName ) ; if ( dbBuf . length ( ) > desiredLength ) { for ( int i = dbBuf . length ( ) - 1 ; i > 0 ; i -- ) { if ( dbBuf . charAt ( i - 1 ) == '_' ) { continue ; } char curChar = dbBuf . charAt ( i ) ; if ( vowelBag . indexOf ( curChar ) > 0 ) { dbBuf . deleteCharAt ( i ) ; } } } while ( dbBuf . indexOf ( "__" ) > 0 ) { dbBuf . deleteCharAt ( dbBuf . indexOf ( "__" ) ) ; } while ( dbBuf . length ( ) > desiredLength ) { boolean removedChars = false ; int usIndex = dbBuf . lastIndexOf ( "_" ) ; while ( usIndex > 0 && dbBuf . length ( ) > desiredLength ) { int prevUsIndex = dbBuf . lastIndexOf ( "_" , usIndex - 1 ) ; if ( prevUsIndex < 0 && usIndex < 4 ) { break ; } if ( prevUsIndex >= 0 && ( usIndex - prevUsIndex ) <= 4 ) { usIndex = prevUsIndex ; continue ; } dbBuf . deleteCharAt ( usIndex - 2 ) ; removedChars = true ; if ( usIndex > 2 ) { usIndex = dbBuf . lastIndexOf ( "_" , usIndex - 2 ) ; } else { break ; } } if ( dbBuf . length ( ) > desiredLength ) { int removeIndex = dbBuf . length ( ) - 1 ; int prevRemoveIndex = dbBuf . lastIndexOf ( "_" , removeIndex - 1 ) ; if ( prevRemoveIndex < 0 || ( removeIndex - prevRemoveIndex ) >= 3 ) { dbBuf . deleteCharAt ( removeIndex - 1 ) ; removedChars = true ; } } while ( dbBuf . indexOf ( "__" ) > 0 ) { dbBuf . deleteCharAt ( dbBuf . indexOf ( "__" ) ) ; removedChars = true ; } if ( ! removedChars ) { break ; } } while ( dbBuf . indexOf ( "__" ) > 0 ) { dbBuf . deleteCharAt ( dbBuf . indexOf ( "__" ) ) ; } while ( dbBuf . length ( ) > desiredLength ) { int firstUs = dbBuf . indexOf ( "_" ) ; if ( firstUs > 0 ) { int nextUs = dbBuf . indexOf ( "_" , firstUs + 1 ) ; if ( nextUs > 0 ) { dbBuf . delete ( firstUs , nextUs ) ; } } } return dbBuf . toString ( ) ; }
start by removing all vowels , then pull 1 letter at a time off the end of each _ separated segment , go until it is less than or equal to the desired length
