001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.origin;
018
019import org.springframework.util.Assert;
020import org.springframework.util.ObjectUtils;
021
022/**
023 * {@link Origin} for an item loaded from the system environment. Provides access to the
024 * original property name.
025 *
026 * @author Madhura Bhave
027 * @since 2.0.0
028 */
029public class SystemEnvironmentOrigin implements Origin {
030
031        private final String property;
032
033        public SystemEnvironmentOrigin(String property) {
034                Assert.notNull(property, "Property name must not be null");
035                Assert.hasText(property, "Property name must not be empty");
036                this.property = property;
037        }
038
039        public String getProperty() {
040                return this.property;
041        }
042
043        @Override
044        public boolean equals(Object obj) {
045                if (this == obj) {
046                        return true;
047                }
048                if (obj == null || getClass() != obj.getClass()) {
049                        return false;
050                }
051                SystemEnvironmentOrigin other = (SystemEnvironmentOrigin) obj;
052                return ObjectUtils.nullSafeEquals(this.property, other.property);
053        }
054
055        @Override
056        public int hashCode() {
057                return ObjectUtils.nullSafeHashCode(this.property);
058        }
059
060        @Override
061        public String toString() {
062                return "System Environment Property \"" + this.property + "\"";
063        }
064
065}