Example usage for com.google.common.base Preconditions checkNotNull

List of usage examples for com.google.common.base Preconditions checkNotNull

Introduction

In this page you can find the example usage for com.google.common.base Preconditions checkNotNull.

Prototype

public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) 

Source Link

Document

Ensures that an object reference passed as a parameter to the calling method is not null.

Usage

From source file:org.terasology.monitoring.ChunkMonitor.java

private static synchronized ChunkMonitorEntry registerChunk(ChunkImpl chunk) {
    Preconditions.checkNotNull(chunk, "The parameter 'chunk' must not be null");
    final Vector3i pos = chunk.getPos();
    ChunkMonitorEntry entry = CHUNKS.get(pos);
    if (entry == null) {
        entry = new ChunkMonitorEntry(pos);
        CHUNKS.put(pos, entry);/*w  w w.  j  a  v  a  2s.  com*/
    }
    entry.addChunk(chunk);
    return entry;
}

From source file:com.google.security.zynamics.binnavi.Gui.SettingsDialog.CHintCreator.java

/**
 * Adds a hint icon to a component./*from   w ww . j a  v  a 2s  . c  o m*/
 * 
 * @param component The component the hint icon is added to.
 * @param message The message shown by the hint icon when the cursor hovers over it.
 * 
 * @return The new component that contains both the passed component and the hint icon.
 */
public static Component createHintPanel(final Component component, final String message) {
    Preconditions.checkNotNull(component, "IE01256: Component argument can not be null");

    Preconditions.checkNotNull(message, "IE01257: Message argument can not be null");

    final JPanel panel = new JPanel(new BorderLayout());

    panel.add(component, BorderLayout.CENTER);

    final JHintIcon hintPopup = new JHintIcon(message);
    hintPopup.setBorder(new EmptyBorder(0, 3, 0, 0));
    panel.add(hintPopup, BorderLayout.EAST);

    return panel;
}

From source file:com.addthis.cronus.CronParser.java

static String print(CronPattern pattern) {
    Preconditions.checkNotNull(pattern, "pattern argument must be non-null");
    List<String> components = new ArrayList<>();
    TimePeriod[] periods = TimePeriod.values();
    for (int i = 0; i < periods.length; i++) {
        TimePeriod period = periods[i];//from  w w w . j  a  v a  2s  .  c  o m
        Interval interval = pattern.getInterval(period);
        if (interval.isFull()) {
            components.add("*");
        } else {
            List<String> sections = new ArrayList<>();
            int current = period.min;
            while (current <= period.max) {
                int start, end;
                while (current <= period.max && !interval.test(current)) {
                    current++;
                }
                if (current > period.max) {
                    break;
                }
                start = current;
                while (current <= period.max && interval.test(current)) {
                    current++;
                }
                end = current - 1;
                if (start == end) {
                    sections.add(Integer.toString(start));
                } else {
                    sections.add(start + "-" + end);
                }
            }
            components.add(COMMA_JOINER.join(sections));
        }
    }
    return SPACE_JOINER.join(components);
}

From source file:com.google.security.zynamics.binnavi.API.reil.ReilHelpers.java

/**
 * Determines whether a given REIL instruction is a function call.
 *
 * @param instruction The instruction to check.
 *
 * @return True, if the instruction is a function call. False, otherwise.
 *///w  w  w .j  a  v a 2  s  . com
public static boolean isFunctionCall(final ReilInstruction instruction) {
    Preconditions.checkNotNull(instruction, "Error: Instruction argument can not be null");

    return com.google.security.zynamics.reil.ReilHelpers.isFunctionCall(instruction.getNative());
}

From source file:org.apache.mahout.common.IOUtils.java

public static void quietClose(Closeable... closeables) {
    Preconditions.checkNotNull(closeables, "Closables cannot be null");
    for (Closeable closeable : closeables) {
        if (closeable != null) {
            try {
                closeable.close();/*from  ww  w.j a  v a 2  s  .  c  om*/
            } catch (IOException ioe) {
                log.warn("Unexpected exception while closing; continuing", ioe);
            }
        }
    }
}

From source file:org.apache.usergrid.persistence.collection.mvcc.entity.MvccValidationUtils.java

/**
 * Verify the version is correct.  Also verifies the contained entity
 */// ww  w  .  j  a  v  a  2 s  . c  o m
public static void verifyMvccEntityWithEntity(MvccEntity entity) {

    Preconditions.checkNotNull(entity.getEntity().isPresent(), "Entity is required");
    verifyVersion(entity.getVersion());
    verifyMvccEntityOptionalEntity(entity);
}

From source file:com.cloudbees.mail.FreemarkerUtils.java

/**
 * @param rootMap      root node of the freemarker datamodel.
 * @param templatePath classpath classpath path of the template (e.g. "/my-template.ftl")
 * @return generated file//from ww  w  .j a  va2  s  .  co m
 */
@SuppressWarnings("unchecked")
@Nonnull
public static String generate(@Nullable Map<String, ? extends Object> rootMap, @Nonnull String templatePath) {
    Preconditions.checkNotNull(templatePath, "'templatePath' can NOT be null");
    rootMap = (Map<String, Object>) Objects.firstNonNull(rootMap, Collections.emptyMap());

    try {
        Configuration cfg = new Configuration();
        cfg.setClassForTemplateLoading(FreemarkerUtils.class, "/");

        Template template = cfg.getTemplate(templatePath);
        Writer out = new StringWriter();
        template.process(rootMap, out);
        return out.toString();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    } catch (TemplateException e) {
        throw Throwables.propagate(e);
    }
}

From source file:io.crate.core.collections.MapComparator.java

public static <K, V> int compareMaps(Map<K, V> m1, Map<K, V> m2) {
    Preconditions.checkNotNull(m1, "map is null");
    Preconditions.checkNotNull(m2, "map is null");
    int sizeCompare = Integer.compare(m1.size(), m2.size());
    if (sizeCompare != 0)
        return sizeCompare;

    for (Map.Entry<K, V> entry : m1.entrySet()) {
        V thisValue = entry.getValue();/*  w  ww .ja  v a  2s.  c om*/
        V otherValue = m2.get(entry.getKey());
        if (thisValue == null) {
            if (otherValue != null) {
                return 1;
            } else {
                continue;
            }
        }
        if (!thisValue.equals(otherValue)) {
            if (otherValue == null) {
                return -1;
            }
            if (!thisValue.getClass().equals(otherValue.getClass())) {
                DataType leftType = DataTypes.guessType(thisValue);
                int cmp = leftType.compareValueTo(thisValue, leftType.value(otherValue));
                if (cmp == 0) {
                    continue;
                }
                return cmp;
            }
            return 1;
        }
    }
    return 0;
}

From source file:fr.norad.visuwall.providers.hudson.helper.HudsonXmlHelper.java

private static void checkBuild(Build build) {
    Preconditions.checkNotNull(build, "build is mandatory");
}

From source file:azkaban.crypto.Version.java

/**
 * Provides Version enum based on version String
 * @param ver Version String//from w  w w .ja  v a  2 s.  c o m
 * @return
 */
public static Version fromVerString(String ver) {
    Version result = REVERSE_ENTRIES.get(ver);
    Preconditions.checkNotNull(ver, "Invalid version " + ver);
    return result;
}