List of usage examples for com.google.common.base Preconditions checkState
public static void checkState(boolean expression, @Nullable Object errorMessage)
From source file:com.google.devtools.build.lib.syntax.Callstack.java
public static List<Object> get() { Preconditions.checkState(enabled, "Must call Callstack#setEnabled before getting"); return callstack.get(); }
From source file:com.facebook.buck.core.util.graph.TopologicalSort.java
public static <T extends Comparable<?>> ImmutableList<T> sort(TraversableGraph<T> graph) { // AtomicInteger is used to decrement the integer value in-place. Map<T, AtomicInteger> effectiveOutDegreesOfExplorableNodes = new HashMap<>(); Queue<T> nextLevel = Queues.newArrayDeque(graph.getNodesWithNoOutgoingEdges()); Set<T> visitedNodes = new HashSet<>(); ImmutableList.Builder<T> toReturn = ImmutableList.builder(); while (!nextLevel.isEmpty()) { Queue<T> toExplore = nextLevel; nextLevel = Queues.newArrayDeque(); Set<T> level = new TreeSet<>(); while (!toExplore.isEmpty()) { T node = toExplore.remove(); Preconditions.checkState(!visitedNodes.contains(node), "The queue of nodes to explore should not contain a node that has already been" + " visited."); level.add(node);/*from w w w. j av a2 s.c om*/ visitedNodes.add(node); // Only add a node to the set of nodes to be explored if all the nodes it depends on have // been visited already. We achieve the same by keeping track of the out degrees of // explorable nodes. After visiting a node, decrement the out degree of each of its parent // node. When the out degree reaches zero, it is safe to add that node to the list of nodes // to explore next. for (T exploreCandidate : graph.getIncomingNodesFor(node)) { if (!effectiveOutDegreesOfExplorableNodes.containsKey(exploreCandidate)) { effectiveOutDegreesOfExplorableNodes.put(exploreCandidate, new AtomicInteger(Iterables.size(graph.getOutgoingNodesFor(exploreCandidate)))); } if (effectiveOutDegreesOfExplorableNodes.get(exploreCandidate).decrementAndGet() == 0) { nextLevel.add(exploreCandidate); } } } toReturn.addAll(level); } return toReturn.build(); }
From source file:io.github.theangrydev.op.generation.jvm.attribute.instruction.Instructions.java
public static Instructions instructions(List<Instruction> instructions) { Preconditions.checkState(!instructions.isEmpty(), "Code must have at least one operation!"); int sizeOfInstructionsInBytes = instructions.stream().mapToInt(Instruction::sizeInBytes).sum(); Preconditions.checkState(sizeOfInstructionsInBytes <= MAX_INSTRUCTION_BYTES, "Total size of instructions must be less than %s bytes but was %s", MAX_INSTRUCTION_BYTES, sizeOfInstructionsInBytes);//from w ww . ja v a 2 s . c o m return new Instructions(instructions, intValue(sizeOfInstructionsInBytes)); }
From source file:me.lucko.luckperms.common.api.ApiUtils.java
public static void checkGroup(Group group) { Preconditions.checkState(group instanceof GroupDelegate, "Group instance cannot be handled by this implementation."); }
From source file:com.google.errorprone.bugpatterns.PreconditionsExpensiveStringPositiveCase1.java
public void error() { int foo = 42; int bar = 78; Preconditions.checkState(true, String.format("The foo %s (%s) is not a good foo", foo, bar)); }
From source file:com.dmdirc.addons.ui_swing.SwingPreconditions.java
/** * Checks that the method is NOT called on the Swing EDT. * * @throws IllegalStateException if the method is called from the EDT. *//*from w w w .jav a 2s . c o m*/ public static void checkNotOnEDT() { Preconditions.checkState(!SwingUtilities.isEventDispatchThread(), "Must not be called ont he event despatch thread"); }
From source file:me.lucko.luckperms.common.api.internal.Utils.java
public static void checkTrack(Track track) { Preconditions.checkState(track instanceof TrackLink, "Track instance cannot be handled by this implementation."); }
From source file:org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.SimpleAttributeReadingStrategy.java
@Override AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws DocumentedException { XmlElement xmlElement = configNodes.get(0); Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + xmlElement + " but was " + configNodes.size()); String textContent = readElementContent(xmlElement); return AttributeConfigElement.create(postprocessNullableDefault(getNullableDefault()), postprocessParsedValue(textContent)); }
From source file:com.google.errorprone.bugpatterns.PreconditionsExpensiveStringNegativeCase2.java
public void error() { int foo = 42; Preconditions.checkState(true, "The foo" + foo + " is not a good foo"); }
From source file:net.techcable.pineapple.LazyPreconditions.java
public static void checkState(boolean expression, String message) { Preconditions.checkState(expression, message); }