Just for test

 Just for test

public class CVSClient {
 /** Cvs clinet instance used to communicate with cvs server */
 private Client cvsclient;
 /** Cvs connect string */
 private CVSRoot cvsroot;
 /** Connection instance to keep connect with cvs server */
 private Connection connection;
 /** Global options to store the requied parameter for cvs server *//** Global options to store the requied parameter for cvs server *//** Global options to store the requied parameter for cvs server *//** Global options to store the requied parameter for cvs server *//** Global options to store the requied parameter for cvs server */
 private GlobalOptions globalOptions;
 /** The local path on ur local machine */
 private String localPath;
 /**
  * Inner class extend CVSAdapter <br>
  * <p>used to get and send message of the CVS server</p>
  * */
 class BasicListener extends CVSAdapter {
  /**
   * Stores a tagged line
   */
  private final StringBuffer taggedLine = new StringBuffer();
  /**
   * Called when the server wants to send a message to be displayed to the
   * user. The message is only for information purposes and clients can
   * choose to ignore these messages if they wish.
   * 
   * @param e
   *            the event
   */
  public void messageSent(MessageEvent e) {
   String line = e.getMessage();
   PrintStream stream = e.isError() ? System.err : System.out;
   if (e.isTagged()) {
    String message = MessageEvent.parseTaggedMessage(taggedLine,
      "Daniel Six");
    // if we get back a non-null line, we have something
    // to output. Otherwise, there is more to come and we
    // should do nothing yet.
    if (message != null) {
     stream.println(message);
    }
   } else {
    stream.println(line);
   }
  }
 }
    /**
     * Default constructor allows to construct CVSRoot from Properties object.
     * The names are exactly the same as the attribute names in this class.
     */
 public CVSClient() {
 }
 
    /**
     * Breaks the string representation of CVSClient into it's components:
     *
     * The valid format (from the cederqvist) is:
     *
     * :method:[[user][:password]@]hostname[:[port]]/path/to/repository
     *
     * e.g. :pserver;username=anonymous;hostname=localhost:/path/to/repository
     */ 
 public CVSClient(String connectionString) {
  cvsroot = CVSRoot.parse(connectionString);
 }
 /**
  * Get the localPath
  * @return localPath the local path to get project from the CVS server
  * */
 public String getLocalPath() {
  return localPath;
 }
 /**
  * Set the localPath
  * 
  * */
 public void setLocalPath(String localPath) {
  this.localPath = localPath;
 }
 
 /**
  * Parse the CVSROOT string into CVSRoot object. 
  * 
     * The valid format (from the cederqvist) is:
     *
     * :method:[[user][:password]@]hostname[:[port]]/path/to/repository
     *
     * e.g. :pserver;username=anonymous;hostname=localhost:/path/to/repository
  */
 public void createConnection(String connectionString) {
  cvsroot = CVSRoot.parse(connectionString);
 }
 /**
  * Open connection to the cvs server <br>
  * 
  * @return connection to cvs server
  * @throws AuthenticationException
  * @throws CommandAbortedException
  */
 public Connection openConnection() throws AuthenticationException,
   CommandAbortedException {
  connection = ConnectionFactory.getConnection(cvsroot);
  connection.open();
  return connection;
 }
 
 /**
  * Close connection to the cvs server <br>
  * */
 public void closeConnection() throws IOException{
  connection.close();
 }
 
 /**
  * <p>Excute cvs command</p>
  * 
  * @param command to be excute by the cliet
  * @throws AuthenticationException
  * @throws CommandAbortedException
  * @throws IOException
  * @throws CommandException
  */
 public void excute(Command command) throws AuthenticationException,
   CommandAbortedException, IOException, CommandException {
  cvsclient = new Client(connection, new StandardAdminHandler());
  cvsclient.setLocalPath(localPath);
  globalOptions = new GlobalOptions();
  globalOptions.setCVSRoot("d:/client/java");
  cvsclient.getEventManager().addCVSListener(new BasicListener());
  //put the command to the console
  System.out.println("***Command***"+command.getCVSCommand());
  cvsclient.executeCommand(command, globalOptions);
 }
 /**
  * <p>Called when need add files</p>
  * @param files that indicate to be added
  * @return command of add files
  */
 public Command add(String[] files) {
  AddCommand command = new AddCommand();
  command.setBuilder(null);
  for (int i = 0; i < files.length; i++) {
   command.setFiles(new File[] { new File(files[i]) });
  }
  return command;
 }
 /**
  * Called when need commit all files under the local path
  * @return command command of commit files
  */
 public Command commit() {
  CommitCommand command = new CommitCommand();
  command.setBuilder(null);
  command.setForceCommit(true);
  command.setRecursive(true);
  return command;
 }
 /**
  * Called when need commit files
  * @param files need to be commit
  * @return command command of commit files
  * */
 public Command commit(String[] files) {
  CommitCommand command = new CommitCommand();
  for (int i = 0; i < files.length; i++) {
   command.setFiles(new File[] { new File(files[i])});
  }
  command.setBuilder(null);
  command.setForceCommit(true);
  command.setRecursive(true);
  return command;
 }
 /**
  * Called when need update the certain files
  * @param files need to be update
  * @return command command of update files and directoris
  * */
 public Command update(String[] files) {
  UpdateCommand command = new UpdateCommand();
  //fetch files from the array
  for (int i = 0; i < files.length; i++) {
   command.setFiles(new File[] { new File(files[i]) });
  }
  command.setBuilder(null);
  command.setRecursive(true);
  command.setBuildDirectories(true);
  command.setPruneDirectories(true);
  return command;
 }
 /**
  * Called to show the history list since given date
  * @param date Date of the history
  *@return command command show history list
  * */
 public Command historysincedate(String date){
  HistoryCommand command=new HistoryCommand();
  //Format is yyyymmdd e.g 20070205
  command.setSinceDate(date);
  return command;
 }
 
 /**
  *Called to show the history list since given version
  *@param reversion reversion of the history
  *@return command command show history list 
  **/
 public Command historysincerRevision(String reversion){
  //Init command
  HistoryCommand command=new HistoryCommand();
  //set parameters
  command.setSinceRevision(reversion);
  return command;
 }
 
 /**
  * Called to show the different between two versions
  * @param files the files to compare with
  * @param revision1 one revision 
  * @param revision2 another revision 
  * @return
  * */
 public Command diffbyreveision(String[] files,String revision1,String revision2){
  //Inite command
  DiffCommand command=new DiffCommand();
  //Set parameters
  for(int i=0;i<files.length;i++){
   command.setFiles(new File[]{new File(files[i])});
  }
  command.setRevision1(revision1);
  command.setRevision2(revision2);
  return command;
 }
 
 /**
  * Show difference between of the file that with different date
  * @param files an array of files path
  * @param date1 one date
  * @param date2 another date 
  * @return command command of show difference between files
  * */
 public Command diffbydate(String[] files,String date1,String date2){
  //Init command
  DiffCommand command=new DiffCommand();
  //Set parameters
  for(int i=0;i<files.length;i++){
   command.setFiles(new File[]{new File(files[i])});
  }
  //Format is yyyymmdd e.g 20070205
  command.setBeforeDate1(date1);
  command.setBeforeDate2(date2);
  return command;
 }
 
 /**
  * Check out the module
  * @param modulename name of the module that to be checked out
  * @return command command of check out the module
  * */
 public Command checkout(String modulename){
  //Init new command
  CheckoutCommand command=new CheckoutCommand();
  //Set paramaters
  command.setModule(modulename);
  command.setRecursive(true);
  return command;
 }
 
 /**
  * Check out the module
  * @param modulename name of the module that to be checked out
  * @return command command of check out the module
  * */
 public Command checkouttoOutput(String modulename){
  //Init new command
  CheckoutCommand command=new CheckoutCommand();
  //Set paramaters
  command.setModule(modulename);
  command.setPipeToOutput(true);
  command.setRecursive(true);
  return command;
 } 
}

 

转载于:https://my.oschina.net/jerval/blog/1827245

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
// just for test,无向图,邻接矩阵,书上图 6.17(a) void CreateUDG_AMG_Test(AMGraph &g){ g.vexnum = 8; g.arcnum = 9; // vertices string temp[] = {"V1", "V2", "V3","V4", "V5", "V6","V7", "V8"}; for (int i=0; i<g.vexnum; i++){ g.vexs[i] = temp[i]; } // init arcs as 0 for (int j=0; j<g.vexnum; j++) for (int k=0; k<g.vexnum; k++){ g.arcs[j][k] = 0; } // arcs int arc_i[] = {0, 0, 1, 1, 2, 2, 3, 4, 5}; int arc_j[] = {1, 2, 3, 4, 5, 6, 7, 7, 6}; int i, j; for (int k=0; k<g.arcnum; k++){ i = arc_i[k]; j = arc_j[k]; g.arcs[i][j] = 1; g.arcs[j][i] = 1; } return; } // just for test,无向网,邻接矩阵,书上图 6.19 void CreateUDN_AMG_Test(AMGraph &g){ g.vexnum = 6; g.arcnum = 10; // vertices string temp[] = {"V1", "V2", "V3","V4", "V5", "V6"}; for (int i=0; i<g.vexnum; i++){ g.vexs[i] = temp[i]; } // init arcs as MaxInt for (int j=0; j<g.vexnum; j++){ for (int k=0; k<g.vexnum; k++){ g.arcs[j][k] = MaxInt; } } // arcs int arc_i[] = {0, 0, 0, 1, 1, 2, 2, 2, 3, 4}; int arc_j[] = {1, 2, 3, 2, 4, 3, 4, 5, 5, 5}; int weights[] = {6, 1, 5, 5, 3, 5, 6, 4, 2, 6}; int i, j; for (int k=0; k<g.arcnum; k++){ i = arc_i[k]; j = arc_j[k]; g.arcs[i][j] = weights[k]; g.arcs[j][i] = weights[k]; } return; } // just for test,有向网,邻接矩阵 void CreateDN_AMG_Test(AMGraph &g, int vexnum, int arcnum, string vertices[], int arc_i[], int arc_j[], int weights[]){ g.vexnum = vexnum; g.arcnum = arcnum; // vertices for (int i=0; i<g.vexnum; i++){ g.vexs[i] = vertices[i]; } // init arcs as MaxInt for (int j=0; j<g.vexnum; j++){ for (int k=0; k<g.vexnum; k++){ g.arcs[j][k] = MaxInt; } } // arcs int i, j; for (int k=0; k<g.arcnum; k++){ i = arc_i[k]; j = arc_j[k]; g.arcs[i][j] = weights[k]; } return; }如何根据这个来编写以邻接矩阵存储创建无向网
最新发布
06-11

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值