View Javadoc
1   /*
2    * Copyright (C) 2016 The Guava Authors
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  
17  package com.google.common.graph;
18  
19  /** A utility class to hold various constants used by the Guava Graph library. */
20  final class GraphConstants {
21  
22    private GraphConstants() {}
23  
24    static final int EXPECTED_DEGREE = 2;
25  
26    static final int DEFAULT_NODE_COUNT = 10;
27    static final int DEFAULT_EDGE_COUNT = DEFAULT_NODE_COUNT * EXPECTED_DEGREE;
28  
29    // Load factor and capacity for "inner" (i.e. per node/edge element) hash sets or maps
30    static final float INNER_LOAD_FACTOR = 1.0f;
31    static final int INNER_CAPACITY = 2; // ceiling(EXPECTED_DEGREE / INNER_LOAD_FACTOR)
32  
33    // Error messages
34    static final String NODE_NOT_IN_GRAPH = "Node %s is not an element of this graph.";
35    static final String EDGE_NOT_IN_GRAPH = "Edge %s is not an element of this graph.";
36    static final String REUSING_EDGE =
37        "Edge %s already exists between the following nodes: %s, "
38            + "so it cannot be reused to connect the following nodes: %s.";
39    static final String MULTIPLE_EDGES_CONNECTING =
40        "Cannot call edgeConnecting() when parallel edges exist between %s and %s. Consider calling "
41            + "edgesConnecting() instead.";
42    static final String PARALLEL_EDGES_NOT_ALLOWED =
43        "Nodes %s and %s are already connected by a different edge. To construct a graph "
44            + "that allows parallel edges, call allowsParallelEdges(true) on the Builder.";
45    static final String SELF_LOOPS_NOT_ALLOWED =
46        "Cannot add self-loop edge on node %s, as self-loops are not allowed. To construct a graph "
47            + "that allows self-loops, call allowsSelfLoops(true) on the Builder.";
48    static final String NOT_AVAILABLE_ON_UNDIRECTED =
49        "Cannot call source()/target() on a EndpointPair from an undirected graph. Consider calling "
50            + "adjacentNode(node) if you already have a node, or nodeU()/nodeV() if you don't.";
51    static final String EDGE_ALREADY_EXISTS = "Edge %s already exists in the graph.";
52  
53    /** Singleton edge value for {@link Graph} implementations backed by {@link ValueGraph}s. */
54    enum Presence {
55      EDGE_EXISTS
56    }
57  }