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.actuate.endpoint.web; 018 019import org.springframework.core.style.ToStringCreator; 020import org.springframework.util.Assert; 021 022/** 023 * Details for a link in a 024 * <a href="https://tools.ietf.org/html/draft-kelly-json-hal-08">HAL</a>-formatted 025 * response. 026 * 027 * @author Andy Wilkinson 028 * @since 2.0.0 029 */ 030public class Link { 031 032 private final String href; 033 034 private final boolean templated; 035 036 /** 037 * Creates a new {@link Link} with the given {@code href}. 038 * @param href the href 039 */ 040 public Link(String href) { 041 Assert.notNull(href, "HREF must not be null"); 042 this.href = href; 043 this.templated = href.contains("{"); 044 } 045 046 /** 047 * Returns the href of the link. 048 * @return the href 049 */ 050 public String getHref() { 051 return this.href; 052 } 053 054 /** 055 * Returns whether or not the {@link #getHref() href} is templated. 056 * @return {@code true} if the href is templated, otherwise {@code false} 057 */ 058 public boolean isTemplated() { 059 return this.templated; 060 } 061 062 @Override 063 public String toString() { 064 return new ToStringCreator(this).append("href", this.href).toString(); 065 } 066 067}