2021SC@SDUSC
**内容非常主观,可能出现错漏,慎重参考
_SortedArraySet.java
package freemarker.core;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
/** Don't use this; used internally by FreeMarker, might changes without notice. */
public class _SortedArraySet<E> extends _UnmodifiableSet<E> {
private final E[] array;
public _SortedArraySet(E[] array) {
this.array = array;
}
@Override
public int size() {
return array.length;
}
@Override
public boolean contains(Object o) {
return Arrays.binarySearch(array, o) >= 0;
}
@Override
public Iterator<E> iterator() {
return new _ArrayIterator(array);
}
@Override
public boolean add(E o) {
throw new UnsupportedOperationException();
}
@Override
public boolean remove(Object o) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends E> c) {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
}
_TemplateModelException.java
package freemarker.core;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
import freemarker.template.utility.ClassUtil;
public class _TemplateModelException extends TemplateModelException {
// Note: On Java 5 we will use `String descPart1, Object... furtherDescParts` instead of `Object[] descriptionParts`
// and `String description`. That's why these are at the end of the parameter list.
// -----------------------------------------------------------------------------------------------------------------
// Permutation group:
public _TemplateModelException(String description) {
super(description);
}
// -----------------------------------------------------------------------------------------------------------------
// Permutation group:
public _TemplateModelException(Throwable cause, String description) {
this(cause, null, description);
}
public _TemplateModelException(Environment env, String description) {
this((Throwable) null, env, description);
}
public _TemplateModelException(Throwable cause, Environment env) {
this(cause, env, (String) null);
}
public _TemplateModelException(Throwable cause) {
this(cause, null, (String) null);
}
public _TemplateModelException(Throwable cause, Environment env, String description) {
super(cause, env, description, true);
}
// -----------------------------------------------------------------------------------------------------------------
// Permutation group:
public _TemplateModelException(_ErrorDescriptionBuilder description) {
this(null, description);
}
public _TemplateModelException(Environment env, _ErrorDescriptionBuilder description) {
this(null, env, description);
}
public _TemplateModelException(Throwable cause, Environment env, _ErrorDescriptionBuilder description) {
super(cause, env, description, true);
}
// -----------------------------------------------------------------------------------------------------------------
// Permutation group:
public _TemplateModelException(Object... descriptionParts) {
this((Environment) null, descriptionParts);
}
public _TemplateModelException(Environment env, Object... descriptionParts) {
this((Throwable) null, env, descriptionParts);
}
public _TemplateModelException(Throwable cause, Object... descriptionParts) {
this(cause, null, descriptionParts);
}
public _TemplateModelException(Throwable cause, Environment env, Object... descriptionParts) {
super(cause, env, new _ErrorDescriptionBuilder(descriptionParts), true);
}
// -----------------------------------------------------------------------------------------------------------------
// Permutation group:
public _TemplateModelException(Expression blamed, Object... descriptionParts) {
this(blamed, null, descriptionParts);
}
public _TemplateModelException(Expression blamed, Environment env, Object... descriptionParts) {
this(blamed, null, env, descriptionParts);
}
public _TemplateModelException(Expression blamed, Throwable cause, Environment env, Object... descriptionParts) {
super(cause, env, new _ErrorDescriptionBuilder(descriptionParts).blame(blamed), true);
}
// -----------------------------------------------------------------------------------------------------------------
// Permutation group:
public _TemplateModelException(Expression blamed, String description) {
this(blamed, null, description);
}
public _TemplateModelException(Expression blamed, Environment env, String description) {
this(blamed, null, env, description);
}
public _TemplateModelException(Expression blamed, Throwable cause, Environment env, String description) {
super(cause, env, new _ErrorDescriptionBuilder(description).blame(blamed), true);
}
static Object[] modelHasStoredNullDescription(Class expected, TemplateModel model) {
return new Object[] {
"The FreeMarker value exists, but has nothing inside it; the TemplateModel object (class: ",
model.getClass().getName(), ") has returned a null",
(expected != null ? new Object[] { " instead of a ", ClassUtil.getShortClassName(expected) } : ""),
". This is possibly a bug in the non-FreeMarker code that builds the data-model." };
}
}
_TimeZoneBuilder.java
package freemarker.core;
import java.util.TimeZone;
/**
* For internal use only; don't depend on this, there's no backward compatibility guarantee at all!
* Used by {@link _ObjectBuilderSettingEvaluator}.
*/
public class _TimeZoneBuilder {
private final String timeZoneId;
public _TimeZoneBuilder(String timeZoneId) {
this.timeZoneId = timeZoneId;
}
public TimeZone build() {
TimeZone timeZone = TimeZone.getTimeZone(timeZoneId);
if (timeZone.getID().equals("GMT") && !timeZoneId.equals("GMT") && !timeZoneId.equals("UTC")
&& !timeZoneId.equals("GMT+00") && !timeZoneId.equals("GMT+00:00") && !timeZoneId.equals("GMT+0000")) {
throw new IllegalArgumentException("Unrecognized time zone: " + timeZoneId);
}
return timeZone;
}
}