001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.reef.runtime.common.files; 020 021import org.apache.reef.util.BuilderUtils; 022 023/** 024 * Default POJO implementation of FileResource. 025 * Use newBuilder to construct an instance. 026 */ 027public final class FileResourceImpl implements FileResource { 028 private final FileType type; 029 private final String name; 030 private final String path; 031 032 private FileResourceImpl(final Builder builder) { 033 this.type = BuilderUtils.notNull(builder.type); 034 this.name = BuilderUtils.notNull(builder.name); 035 this.path = BuilderUtils.notNull(builder.path); 036 } 037 038 @Override 039 public FileType getType() { 040 return type; 041 } 042 043 @Override 044 public String getName() { 045 return name; 046 } 047 048 @Override 049 public String getPath() { 050 return path; 051 } 052 053 public static Builder newBuilder() { 054 return new Builder(); 055 } 056 057 /** 058 * Builder used to create FileResource instances. 059 */ 060 public static final class Builder implements org.apache.reef.util.Builder<FileResource> { 061 private FileType type; 062 private String name; 063 private String path; 064 065 /** 066 * @see FileResource#getType() 067 */ 068 public Builder setType(final FileType type) { 069 this.type = type; 070 return this; 071 } 072 073 /** 074 * @see FileResource#getName() 075 */ 076 public Builder setName(final String name) { 077 this.name = name; 078 return this; 079 } 080 081 /** 082 * @see FileResource#getPath() 083 */ 084 public Builder setPath(final String path) { 085 this.path = path; 086 return this; 087 } 088 089 @Override 090 public FileResource build() { 091 return new FileResourceImpl(this); 092 } 093 } 094}