首页>代码>spring mvc+thymeleaf+Knockout.js整合开发最简单的聊天室实例>/spring-mvc-chat/src/main/java/org/springframework/samples/async/chat/InMemoryChatRepository.java
/* * Copyright 2002-2012 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 org.springframework.samples.async.chat; import java.util.Collections; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import org.springframework.stereotype.Repository; import org.springframework.util.Assert; @Repository public class InMemoryChatRepository implements ChatRepository { private final List<String> messages = new CopyOnWriteArrayList<String>(); public List<String> getMessages(int index) { if (this.messages.isEmpty()) { return Collections.<String> emptyList(); } Assert.isTrue((index >= 0) && (index <= this.messages.size()), "Invalid message index"); return this.messages.subList(index, this.messages.size()); } public void addMessage(String message) { this.messages.add(message); } }
最近下载更多
最近浏览更多
夜起星河 LV8
2023年12月27日
buhuia LV4
2023年6月7日
ChenZheMeng LV3
2022年12月21日
win1991 LV6
2022年8月18日
123456qiqiqi LV1
2022年5月27日
fengshengtian LV8
2022年4月19日
yuxinnan LV4
2022年4月11日
唐家俊 LV2
2021年12月25日
494785 LV5
2021年12月15日
liuxiao2 LV16
2021年11月17日