Coverage Report - org.mockftpserver.fake.filesystem.AbstractFileSystemEntry
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractFileSystemEntry
100%
30/30
100%
4/4
1.125
 
 1  
 /*
 2  
  * Copyright 2008 the original author or authors.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.mockftpserver.fake.filesystem;
 17  
 
 18  
 import org.mockftpserver.core.util.Assert;
 19  
 
 20  
 import java.util.Date;
 21  
 
 22  
 /**
 23  
  * The abstract superclass for concrete file system entry classes representing files and directories.
 24  
  *
 25  
  * @author Chris Mair
 26  
  * @version $Revision: 182 $ - $Date: 2008-11-30 21:37:49 -0500 (Sun, 30 Nov 2008) $
 27  
  */
 28  
 public abstract class AbstractFileSystemEntry implements FileSystemEntry {
 29  
 
 30  
     private String path;
 31  807
     private boolean pathLocked = false;
 32  
 
 33  
     private Date lastModified;
 34  
     private String owner;
 35  
     private String group;
 36  
 
 37  
     public Date getLastModified() {
 38  762
         return lastModified;
 39  
     }
 40  
 
 41  
     public void setLastModified(Date lastModified) {
 42  710
         this.lastModified = lastModified;
 43  710
     }
 44  
 
 45  
     public String getOwner() {
 46  119
         return owner;
 47  
     }
 48  
 
 49  
     public void setOwner(String owner) {
 50  66
         this.owner = owner;
 51  66
     }
 52  
 
 53  
     public String getGroup() {
 54  75
         return group;
 55  
     }
 56  
 
 57  
     public void setGroup(String group) {
 58  66
         this.group = group;
 59  66
     }
 60  
 
 61  
     public Permissions getPermissions() {
 62  234
         return permissions;
 63  
     }
 64  
 
 65  
     public void setPermissions(Permissions permissions) {
 66  96
         this.permissions = permissions;
 67  96
     }
 68  
 
 69  
     private Permissions permissions;
 70  
 
 71  
     /**
 72  
      * Construct a new instance without setting its path
 73  
      */
 74  124
     public AbstractFileSystemEntry() {
 75  124
     }
 76  
 
 77  
     /**
 78  
      * Construct a new instance with the specified value for its path
 79  
      *
 80  
      * @param path - the value for path
 81  
      */
 82  683
     public AbstractFileSystemEntry(String path) {
 83  683
         this.path = path;
 84  683
     }
 85  
 
 86  
     /**
 87  
      * @return the path for this entry
 88  
      */
 89  
     public String getPath() {
 90  912
         return path;
 91  
     }
 92  
 
 93  
     /**
 94  
      * @return the file name or directory name (no path) for this entry
 95  
      */
 96  
     public String getName() {
 97  66
         int separatorIndex1 = path.lastIndexOf('/');
 98  66
         int separatorIndex2 = path.lastIndexOf('\\');
 99  
 //        int separatorIndex = [separatorIndex1, separatorIndex2].max();
 100  66
         int separatorIndex = separatorIndex1 > separatorIndex2 ? separatorIndex1 : separatorIndex2;
 101  66
         return (separatorIndex == -1) ? path : path.substring(separatorIndex + 1);
 102  
     }
 103  
 
 104  
     /**
 105  
      * Set the path for this entry. Throw an exception if pathLocked is true.
 106  
      *
 107  
      * @param path - the new path value
 108  
      */
 109  
     public void setPath(String path) {
 110  132
         Assert.isFalse(pathLocked, "path is locked");
 111  126
         this.path = path;
 112  126
     }
 113  
 
 114  
     public void lockPath() {
 115  696
         this.pathLocked = true;
 116  696
     }
 117  
 
 118  
     public void setPermissionsFromString(String permissionsString) {
 119  6
         this.permissions = new Permissions(permissionsString);
 120  6
     }
 121  
 
 122  
     /**
 123  
      * Abstract method -- must be implemented within concrete subclasses
 124  
      *
 125  
      * @return true if this file system entry represents a directory
 126  
      */
 127  
     public abstract boolean isDirectory();
 128  
 
 129  
 }