com.jfinal.template.stat.ast.ForIteratorStatus Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enjoy Show documentation
Show all versions of enjoy Show documentation
Enjoy is a simple, light, rapid, independent, extensible Java Template Engine.
/**
* Copyright (c) 2011-2019, James Zhan 詹波 ([email protected]).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jfinal.template.stat.ast;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import com.jfinal.template.TemplateException;
import com.jfinal.template.stat.Location;
/**
* ForIteratorStatus
* 封装 #for( id : expr) 迭代语句状态,便于模板中获取
*
* 使用以下表达式可以模板中获取迭代状态:
* for.size 被迭代集合元素数量,不支持 Iterator 与 Iterable
* for.index 从 0 下始的下标
* for.count 从 1 开始的计数器
* for.first 是否第一个元素
* for.last 是否最后一个元素
* for.odd 是否第奇数个元素
* for.even 是否第偶数个元素
* for.outer 获取外层 for 对象,便于获取外层 for 循环状态
* 例如: for.outer.index
*/
public class ForIteratorStatus {
private Object outer;
private int index;
private int size;
private Iterator> iterator;
private Location location;
public ForIteratorStatus(Object outer, Object target, Location location) {
this.outer = outer;
this.index = 0;
this.location = location;
init(target);
}
@SuppressWarnings("unchecked")
private void init(Object target) {
if (target instanceof Collection) {
size = ((Collection>)target).size();
iterator = ((Collection>)target).iterator();
return ;
}
if (target instanceof Map, ?>) {
size = ((Map, ?>)target).size();
iterator = new MapIterator(((Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy