1/*
2 * Copyright (C) 2012 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.caliper.bridge;
18
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import com.google.common.base.Objects;
22import com.google.common.collect.ImmutableMap;
23import com.google.common.collect.Maps;
24
25import java.io.Serializable;
26
27/**
28 * A message containing a selection of {@link System#getProperties() system properties} from the
29 * worker JVM.
30 */
31public class VmPropertiesLogMessage extends LogMessage implements Serializable {
32  private static final long serialVersionUID = 1L;
33
34  private final ImmutableMap<String, String> properties;
35
36  public VmPropertiesLogMessage() {
37    this(ImmutableMap.copyOf(Maps.fromProperties(System.getProperties())));
38  }
39
40  public VmPropertiesLogMessage(ImmutableMap<String, String> properties) {
41    this.properties = checkNotNull(properties);
42  }
43
44  public ImmutableMap<String, String> properties() {
45    return properties;
46  }
47
48  @Override public void accept(LogMessageVisitor visitor) {
49    visitor.visit(this);
50  }
51
52  @Override
53  public int hashCode() {
54    return Objects.hashCode(properties);
55  }
56
57  @Override
58  public boolean equals(Object obj) {
59    if (obj == this) {
60      return true;
61    } else if (obj instanceof VmPropertiesLogMessage) {
62      VmPropertiesLogMessage that = (VmPropertiesLogMessage) obj;
63      return this.properties.equals(that.properties);
64    } else {
65      return false;
66    }
67  }
68}
69