Java tutorial
/* * Copyright 2013-2014 the original author or authors. * * 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.eryansky.common.orm.core; import com.eryansky.common.utils.ConvertUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.List; /** * ,??orand?? * * @author maurice * */ public class MatchValue { private boolean hasOrOperate; private List<Object> values; /** * ,?? orand?? * * @param hasOrOperate ?or??? * @param values ? */ public MatchValue(boolean hasOrOperate, List<Object> values) { this.hasOrOperate = hasOrOperate; this.values = values; } /** * ??or? * * @return boolean */ public boolean hasOrOperate() { return hasOrOperate; } /** * ?? * * @return List */ public List<Object> getValues() { return values; } /** * andValueSeparatororValueSeparator() * * @param matchValue * @param type * @param andValueSeparator * @param orValueSeparator * * @return {@link com.eryansky.common.orm.core.MatchValue} */ public static MatchValue createMatchValueModel(String matchValue, Class<?> type, String andValueSeparator, String orValueSeparator) { List<Object> values = new ArrayList<Object>(); if (StringUtils.contains(matchValue, andValueSeparator)) { String[] siplit = StringUtils.splitByWholeSeparator(matchValue, andValueSeparator); CollectionUtils.addAll(values, (Object[]) ConvertUtils.convertToObject(siplit, type)); return new MatchValue(false, values); } else if (StringUtils.contains(matchValue, orValueSeparator)) { String[] siplit = StringUtils.splitByWholeSeparator(matchValue, orValueSeparator); CollectionUtils.addAll(values, (Object[]) ConvertUtils.convertToObject(siplit, type)); return new MatchValue(true, values); } else { values.add(ConvertUtils.convertToObject(matchValue, type)); return new MatchValue(false, values); } } }