本文整理汇总了Java中codeu.chat.util.Time类的典型用法代码示例。如果您正苦于以下问题:Java Time类的具体用法?Java Time怎么用?Java Time使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Time类属于codeu.chat.util包,在下文中一共展示了Time类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInfo
import codeu.chat.util.Time; //导入依赖的package包/类
@Override
public ServerInfo getInfo() {
try (final Connection connection = this.source.connect()) {
Serializers.INTEGER.write(connection.out(), NetworkCode.SERVER_INFO_REQUEST);
if (Serializers.INTEGER.read(connection.in()) == NetworkCode.SERVER_INFO_RESPONSE) {
final Uuid version = Uuid.SERIALIZER.read(connection.in());
final Time startTime = Time.SERIALIZER.read(connection.in());
return new ServerInfo(version, startTime);
} else {
LOG.error("Response from server failed.");
}
} catch (Exception ex) {
System.out.println("ERROR: Exception during call on server. Check log for details.");
LOG.error(ex, "Exception during call on server.");
}
return null;
}
示例2: testReadLimited
import codeu.chat.util.Time; //导入依赖的package包/类
@Test
public void testReadLimited() {
final Server relay = new Server(8, 1);
final Uuid team = new Uuid(3);
final byte[] secret = { 0x00, 0x01, 0x02 };
assertTrue(relay.addTeam(team, secret));
assertTrue(relay.write(team,
secret,
relay.pack(new Uuid(4), "User", Time.now()),
relay.pack(new Uuid(5), "Conversation", Time.now()),
relay.pack(new Uuid(6), "Hello World", Time.now())));
assertTrue(relay.write(team,
secret,
relay.pack(new Uuid(4), "User", Time.now()),
relay.pack(new Uuid(5), "Conversation", Time.now()),
relay.pack(new Uuid(7), "Hello World... again", Time.now())));
final Collection<Relay.Bundle> read = relay.read(team, secret, Uuid.NULL, 2);
assertTrue(read.size() == 1);
}
示例3: testWriteSuccess
import codeu.chat.util.Time; //导入依赖的package包/类
@Test
public void testWriteSuccess() {
final Server relay = new Server(8, 8);
final Uuid team = new Uuid(3);
final byte[] secret = { 0x00, 0x01, 0x02 };
assertTrue(relay.addTeam(team, secret));
assertTrue(relay.write(team,
secret,
relay.pack(new Uuid(4), "User", Time.now()),
relay.pack(new Uuid(5), "Conversation", Time.now()),
relay.pack(new Uuid(6), "Hello World", Time.now())));
}
示例4: testAddConversation
import codeu.chat.util.Time; //导入依赖的package包/类
@Test
public void testAddConversation() {
final User user = controller.newUser(userId, "user", Time.now());
assertFalse(
"Check that user has a valid reference",
user == null);
assertTrue(
"Check that the user has the correct id",
Uuid.equals(user.id, userId));
final ConversationHeader conversation = controller.newConversation(
conversationId,
"conversation",
user.id,
Time.now());
assertFalse(
"Check that conversation has a valid reference",
conversation == null);
assertTrue(
"Check that the conversation has the correct id",
Uuid.equals(conversation.id, conversationId));
}
示例5: testFromUserToCreator
import codeu.chat.util.Time; //导入依赖的package包/类
@Test
public void testFromUserToCreator(){
final User user = controller.newUser(userId, "user", Time.now());
final ConversationHeader conversation = controller.newConversation(
conversationId,
"conversation",
user.id,
Time.now());
conversation.userCategory.put(userId, 1);
assertTrue(
"Check that the user is already in the conversation",
conversation.userCounter() == 1);
assertTrue("Check that the user is currently a user",
conversation.userCategory.get(userId) == 1);
}
示例6: read
import codeu.chat.util.Time; //导入依赖的package包/类
@Override
public Relay.Bundle read(InputStream in) throws IOException {
final Uuid id = Uuid.SERIALIZER.read(in);
final Time time = Time.SERIALIZER.read(in);
final Uuid team = Uuid.SERIALIZER.read(in);
final Relay.Bundle.Component user = COMPONENT_SERIALIZER.read(in);
final Relay.Bundle.Component conversation = COMPONENT_SERIALIZER.read(in);
final Relay.Bundle.Component message = COMPONENT_SERIALIZER.read(in);
return new Relay.Bundle() {
@Override
public Uuid id() { return id; }
@Override
public Time time() { return time; }
@Override
public Uuid team() { return team; }
@Override
public Relay.Bundle.Component user() { return user; }
@Override
public Relay.Bundle.Component conversation() { return conversation; }
@Override
public Relay.Bundle.Component message() { return message; }
};
}
示例7: testReadFailMissingTeam
import codeu.chat.util.Time; //导入依赖的package包/类
@Test
public void testReadFailMissingTeam() {
final Server relay = new Server(8, 8);
final Uuid team = new Uuid(3);
final Secret secret = new Secret((byte)0x00, (byte)0x01, (byte)0x02);
assertTrue(relay.addTeam(team, secret));
assertFalse(relay.write(new Uuid(33),
secret,
relay.pack(new Uuid(4), "User", Time.now()),
relay.pack(new Uuid(5), "Conversation", Time.now()),
relay.pack(new Uuid(6), "Hello World", Time.now())));
}
示例8: testReadLimited
import codeu.chat.util.Time; //导入依赖的package包/类
@Test
public void testReadLimited() {
final Server relay = new Server(8, 1);
final Uuid team = new Uuid(3);
final Secret secret = new Secret((byte)0x00, (byte)0x01, (byte)0x02);
assertTrue(relay.addTeam(team, secret));
assertTrue(relay.write(team,
secret,
relay.pack(new Uuid(4), "User", Time.now()),
relay.pack(new Uuid(5), "Conversation", Time.now()),
relay.pack(new Uuid(6), "Hello World", Time.now())));
assertTrue(relay.write(team,
secret,
relay.pack(new Uuid(4), "User", Time.now()),
relay.pack(new Uuid(5), "Conversation", Time.now()),
relay.pack(new Uuid(7), "Hello World... again", Time.now())));
final Collection<Relay.Bundle> read = relay.read(team, secret, Uuid.NULL, 2);
assertTrue(read.size() == 1);
}
示例9: testWriteFailWrongSecret
import codeu.chat.util.Time; //导入依赖的package包/类
@Test
public void testWriteFailWrongSecret() {
final Server relay = new Server(8, 8);
final Uuid team = new Uuid(3);
final Secret secret = new Secret((byte)0x00, (byte)0x01, (byte)0x02);
final Secret wrongSecret = new Secret((byte)0x00, (byte)0x01, (byte)0x03);
assertTrue(relay.addTeam(team, secret));
assertFalse(relay.write(team,
wrongSecret,
relay.pack(new Uuid(4), "User", Time.now()),
relay.pack(new Uuid(5), "Conversation", Time.now()),
relay.pack(new Uuid(6), "Hello World", Time.now())));
}
示例10: getConversations
import codeu.chat.util.Time; //导入依赖的package包/类
@Override
public Collection<Conversation> getConversations(Time start, Time end) {
final Collection<Conversation> conversations = new ArrayList<>();
try (final Connection connection = source.connect()) {
Serializers.INTEGER.write(connection.out(), NetworkCode.GET_CONVERSATIONS_BY_TIME_REQUEST);
Time.SERIALIZER.write(connection.out(), start);
Time.SERIALIZER.write(connection.out(), end);
if (Serializers.INTEGER.read(connection.in()) == NetworkCode.GET_CONVERSATIONS_BY_TIME_RESPONSE) {
conversations.addAll(Serializers.collection(Conversation.SERIALIZER).read(connection.in()));
} else {
LOG.error("Response from server failed.");
}
} catch (Exception ex) {
System.out.println("ERROR: Exception during call on server. Check log for details.");
LOG.error(ex, "Exception during call on server.");
}
return conversations;
}
示例11: getMessages
import codeu.chat.util.Time; //导入依赖的package包/类
@Override
public Collection<Message> getMessages(Uuid conversation, Time start, Time end) {
final Conversation foundConversation = model.conversationById().first(conversation);
final List<Message> foundMessages = new ArrayList<>();
Message current = (foundConversation == null) ?
null :
model.messageById().first(foundConversation.firstMessage);
while (current != null && current.creation.compareTo(start) < 0) {
current = model.messageById().first(current.next);
}
while (current != null && current.creation.compareTo(end) <= 0) {
foundMessages.add(current);
current = model.messageById().first(current.next);
}
return foundMessages;
}
示例12: pack
import codeu.chat.util.Time; //导入依赖的package包/类
@Override
public Relay.Bundle.Component pack(final Uuid id,
final String text,
final Time time) {
return new Relay.Bundle.Component() {
@Override
public Uuid id() { return id; }
@Override
public Time time() { return time; }
@Override
public String text() { return text; }
};
}
示例13: testReadFailWrongSecret
import codeu.chat.util.Time; //导入依赖的package包/类
@Test
public void testReadFailWrongSecret() {
final Server relay = new Server(8, 8);
final Uuid team = new Uuid(3);
final byte[] secret = { 0x00, 0x01, 0x02 };
final byte[] wrongSecret = { 0x00, 0x01, 0x00 };
assertTrue(relay.addTeam(team, secret));
assertFalse(relay.write(team,
wrongSecret,
relay.pack(new Uuid(4), "User", Time.now()),
relay.pack(new Uuid(5), "Conversation", Time.now()),
relay.pack(new Uuid(6), "Hello World", Time.now())));
}
示例14: read
import codeu.chat.util.Time; //导入依赖的package包/类
@Override
public Relay.Bundle.Component read(InputStream in) throws IOException {
final Uuid id = Uuid.SERIALIZER.read(in);
final String text = Serializers.STRING.read(in);
final Time time = Time.SERIALIZER.read(in);
// I could have passed the relay and use its "pack" method but that would
// have been more work than just building an object here.
return new Relay.Bundle.Component() {
@Override
public Uuid id() { return id; }
@Override
public String text() { return text; }
@Override
public Time time() { return time; }
};
}
示例15: newConversation
import codeu.chat.util.Time; //导入依赖的package包/类
@Override
public ConversationHeader newConversation(Uuid id, String title, Uuid owner, Time creationTime) {
final User foundOwner = model.userById().first(owner);
ConversationHeader conversation = null;
if (foundOwner != null && isIdFree(id)) {
conversation = new ConversationHeader(id, owner, creationTime, title);
model.add(conversation);
LOG.info("Conversation added: " + id);
}
return conversation;
}