001package biweekly.io.text; 002 003import java.util.Arrays; 004 005import biweekly.parameter.ICalParameters; 006 007/* 008 Copyright (c) 2013-2015, Michael Angstadt 009 All rights reserved. 010 011 Redistribution and use in source and binary forms, with or without 012 modification, are permitted provided that the following conditions are met: 013 014 1. Redistributions of source code must retain the above copyright notice, this 015 list of conditions and the following disclaimer. 016 2. Redistributions in binary form must reproduce the above copyright notice, 017 this list of conditions and the following disclaimer in the documentation 018 and/or other materials provided with the distribution. 019 020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 023 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 024 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 025 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 026 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 027 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 030 */ 031 032/** 033 * Represents a parsed line from an iCal file. 034 * @author Michael Angstadt 035 */ 036public class ICalRawLine { 037 private final String name, value; 038 private final ICalParameters parameters; 039 040 public ICalRawLine(String name, ICalParameters parameters, String value) { 041 this.name = name; 042 this.value = value; 043 this.parameters = parameters; 044 } 045 046 /** 047 * Gets the property name. 048 * @return the property name 049 */ 050 public String getName() { 051 return name; 052 } 053 054 /** 055 * Gets the property value. 056 * @return the property value 057 */ 058 public String getValue() { 059 return value; 060 } 061 062 /** 063 * Gets the property's parameters. 064 * @return the parameters 065 */ 066 public ICalParameters getParameters() { 067 return parameters; 068 } 069 070 @Override 071 public String toString() { 072 return name + parameters + ":" + value; 073 } 074 075 @Override 076 public int hashCode() { 077 final int prime = 31; 078 int result = 1; 079 result = prime * result + ((name == null) ? 0 : name.hashCode()); 080 result = prime * result + ((parameters == null) ? 0 : parameters.hashCode()); 081 result = prime * result + ((value == null) ? 0 : value.hashCode()); 082 return result; 083 } 084 085 @Override 086 public boolean equals(Object obj) { 087 if (this == obj) 088 return true; 089 if (obj == null) 090 return false; 091 if (getClass() != obj.getClass()) 092 return false; 093 ICalRawLine other = (ICalRawLine) obj; 094 if (name == null) { 095 if (other.name != null) 096 return false; 097 } else if (!name.equals(other.name)) 098 return false; 099 if (parameters == null) { 100 if (other.parameters != null) 101 return false; 102 } else if (!parameters.equals(other.parameters)) 103 return false; 104 if (value == null) { 105 if (other.value != null) 106 return false; 107 } else if (!value.equals(other.value)) 108 return false; 109 return true; 110 } 111 112 public static class Builder { 113 private String name, value; 114 private ICalParameters parameters = new ICalParameters(); 115 116 public Builder name(String name) { 117 this.name = name; 118 return this; 119 } 120 121 public Builder value(String value) { 122 this.value = value; 123 return this; 124 } 125 126 public Builder param(String name, String... values) { 127 this.parameters.putAll(name, Arrays.asList(values)); 128 return this; 129 } 130 131 public ICalRawLine build() { 132 if (name == null) { 133 throw new IllegalArgumentException("Property name required."); 134 } 135 return new ICalRawLine(name, parameters, value); 136 } 137 } 138}