Java Code Examples for com.helger.commons.ValueEnforcer#notNull()
The following examples show how to use
com.helger.commons.ValueEnforcer#notNull() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringDecoder.java From ph-commons with Apache License 2.0 | 6 votes |
@Nonnull public String finish (@Nonnull final ByteBuffer aByteBuffer) { ValueEnforcer.notNull (aByteBuffer, "ByteBuffer"); _decode (aByteBuffer, true); final CoderResult aResult = m_aDecoder.flush (m_aBuffer); if (aResult == CoderResult.OVERFLOW) throw new IllegalStateException ("TODO: Handle overflow?"); if (aResult != CoderResult.UNDERFLOW) throw new IllegalStateException ("TODO: Handle errors?"); // Copy out the string final String sRet = new String (m_aBuffer.array (), 0, m_aBuffer.position ()); // Reset for the next string m_aBuffer.clear (); m_aDecoder.reset (); return sRet; }
Example 2
Source File: Graph.java From ph-commons with Apache License 2.0 | 6 votes |
@Nonnull public EChange removeNodeAndAllRelations (@Nonnull final IMutableGraphNode aNode) { ValueEnforcer.notNull (aNode, "Node"); if (!m_aNodes.containsKey (aNode.getID ())) return EChange.UNCHANGED; // Remove all affected relations from all nodes for (final IMutableGraphRelation aRelation : aNode.getAllRelations ()) for (final IMutableGraphNode aNode2 : aRelation.getAllConnectedNodes ()) aNode2.removeRelation (aRelation); // Remove the node itself if (removeNode (aNode).isUnchanged ()) throw new IllegalStateException ("Inconsistency removing node and all relations"); return EChange.CHANGED; }
Example 3
Source File: CertificateHelper.java From ph-commons with Apache License 2.0 | 6 votes |
/** * Get the provided certificate as PEM (Base64) encoded String. * * @param aCert * The certificate to encode. May not be <code>null</code>. * @return The PEM string with {@link #BEGIN_CERTIFICATE} and * {@link #END_CERTIFICATE}. * @throws IllegalArgumentException * If the certificate could not be encoded. Cause is a * {@link CertificateEncodingException}. * @since 8.5.5 */ @Nonnull @Nonempty public static String getPEMEncodedCertificate (@Nonnull final Certificate aCert) { ValueEnforcer.notNull (aCert, "Cert"); try { final String sEncodedCert = Base64.encodeBytes (aCert.getEncoded ()); return BEGIN_CERTIFICATE + "\n" + sEncodedCert + "\n" + END_CERTIFICATE; } catch (final CertificateEncodingException ex) { throw new IllegalArgumentException ("Failed to encode certificate " + aCert, ex); } }
Example 4
Source File: CollectionHelper.java From ph-commons with Apache License 2.0 | 6 votes |
@Nullable public static <ELEMENTTYPE, DSTTYPE> DSTTYPE findFirstMapped (@Nullable final Iterable <? extends ELEMENTTYPE> aCollection, @Nullable final Predicate <? super ELEMENTTYPE> aFilter, @Nonnull final Function <? super ELEMENTTYPE, DSTTYPE> aMapper, @Nullable final DSTTYPE aDefault) { ValueEnforcer.notNull (aMapper, "Mapper"); if (isNotEmpty (aCollection)) { if (aFilter == null) return aMapper.apply (getFirstElement (aCollection)); for (final ELEMENTTYPE aElement : aCollection) if (aFilter.test (aElement)) return aMapper.apply (aElement); } return aDefault; }
Example 5
Source File: SettingsPersistenceXML.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull public T readSettings (@Nonnull @WillClose final InputStream aIS) { ValueEnforcer.notNull (aIS, "InputStream"); final IMicroDocument aDoc = MicroReader.readMicroXML (aIS); if (aDoc == null) throw new IllegalArgumentException ("Passed XML document is illegal"); // read items final SettingsMicroDocumentConverter <T> aConverter = new SettingsMicroDocumentConverter <> (m_aSettingsFactory); return aConverter.convertToNative (aDoc.getDocumentElement ()); }
Example 6
Source File: PDTMask.java From ph-commons with Apache License 2.0 | 5 votes |
protected PDTMask (@Nonnull @Nonempty final String sPattern, @Nonnull final ITemporalQuery <T> aQuery) { ValueEnforcer.notEmpty (sPattern, "Pattern"); ValueEnforcer.notNull (aQuery, "Query"); m_sPattern = sPattern; m_aQuery = aQuery; }
Example 7
Source File: PSSpan.java From ph-schematron with Apache License 2.0 | 5 votes |
public void addForeignAttribute (@Nonnull final String sAttrName, @Nonnull final String sAttrValue) { ValueEnforcer.notNull (sAttrName, "AttrName"); ValueEnforcer.notNull (sAttrValue, "AttrValue"); if (m_aForeignAttrs == null) m_aForeignAttrs = new CommonsLinkedHashMap <> (); m_aForeignAttrs.put (sAttrName, sAttrValue); }
Example 8
Source File: DirectedGraphIteratorBackward.java From ph-commons with Apache License 2.0 | 5 votes |
public DirectedGraphIteratorBackward (@Nonnull final IMutableDirectedGraphNode aStartNode, @Nullable final IPredicate <? super IMutableDirectedGraphRelation> aRelationFilter) { ValueEnforcer.notNull (aStartNode, "StartNode"); m_aRelationFilter = aRelationFilter; // Ensure that the start node is present m_aNodeStack.push (new IterationNode (aStartNode)); }
Example 9
Source File: JsonWriter.java From ph-commons with Apache License 2.0 | 5 votes |
public void writeToWriter (@Nonnull final IJson aJson, @Nonnull @WillNotClose final Writer aWriter) throws IOException { ValueEnforcer.notNull (aJson, "Json"); ValueEnforcer.notNull (aWriter, "Writer"); _writeToWriter (aJson, aWriter, 0); if (m_aSettings.isWriteNewlineAtEnd ()) aWriter.write (m_aSettings.getNewlineString ()); aWriter.flush (); }
Example 10
Source File: BasicTree.java From ph-commons with Apache License 2.0 | 5 votes |
public BasicTree (@Nonnull final ITreeItemFactory <DATATYPE, ITEMTYPE> aFactory) { ValueEnforcer.notNull (aFactory, "Factory"); m_aRootItem = aFactory.createRoot (); if (m_aRootItem == null) throw new IllegalStateException ("Failed to create root item!"); }
Example 11
Source File: JsonWriter.java From ph-commons with Apache License 2.0 | 5 votes |
/** * Write the JSON to an OutputStream using the provided Charset, and leave the * OutputStream open. * * @param aJson * The JSON to be written. May not be <code>null</code>. * @param aOS * The OutputStream to write to. May not be <code>null</code>. * @param aCharset * The character set to be used. May not be <code>null</code>. * @throws IOException * On IO error * @since 9.4.0 */ public void writeToStream (@Nonnull final IJson aJson, @Nonnull @WillNotClose final OutputStream aOS, @Nonnull final Charset aCharset) throws IOException { ValueEnforcer.notNull (aJson, "Json"); ValueEnforcer.notNull (aOS, "OutputStream"); ValueEnforcer.notNull (aCharset, "Charset"); // Ensure OutputStream stays open try (final Writer aWriter = new OutputStreamWriter (new NonClosingOutputStream (aOS), aCharset)) { writeToWriter (aJson, aWriter); } }
Example 12
Source File: MimeType.java From ph-commons with Apache License 2.0 | 5 votes |
/** * Add a parameter. * * @param aParameter * The parameter to be added. May not be <code>null</code>. * @return this */ @Nonnull public MimeType addParameter (@Nonnull final MimeTypeParameter aParameter) { ValueEnforcer.notNull (aParameter, "Parameter"); m_aParameters.add (aParameter); return this; }
Example 13
Source File: JsonEscapeHelper.java From ph-commons with Apache License 2.0 | 5 votes |
public static void jsonEscape (@Nullable final String sInput, @Nonnull final StringBuilder aSB) { ValueEnforcer.notNull (aSB, "StringBuilder"); if (StringHelper.hasText (sInput)) { final char [] aInput = sInput.toCharArray (); if (!StringHelper.containsAny (aInput, CHARS_TO_MASK)) aSB.append (sInput); else jsonEscapeToStringBuilder (aInput, aSB); } }
Example 14
Source File: MicroAttribute.java From ph-commons with Apache License 2.0 | 4 votes |
public MicroAttribute (@Nonnull final IMicroQName aQName, @Nonnull final String sAttributeValue) { m_aQName = ValueEnforcer.notNull (aQName, "QName"); m_sAttributeValue = ValueEnforcer.notNull (sAttributeValue, "AttributeValue"); }
Example 15
Source File: PSAssertReport.java From ph-schematron with Apache License 2.0 | 4 votes |
public void addEmph (@Nonnull final PSEmph aEmph) { ValueEnforcer.notNull (aEmph, "Emph"); m_aContent.add (aEmph); }
Example 16
Source File: CSSReaderDeclarationList.java From ph-css with Apache License 2.0 | 4 votes |
/** * Read the CSS from the passed {@link Reader}. * * @param aReader * The reader to use. Will be closed automatically after reading - * independent of success or error. May not be <code>null</code>. * @param aSettings * The settings to be used for reading the CSS. May not be * <code>null</code>. * @return <code>null</code> if reading failed, the CSS declarations * otherwise. * @since 3.8.2 */ @Nullable public static CSSDeclarationList readFromReader (@Nonnull @WillClose final Reader aReader, @Nonnull final CSSReaderSettings aSettings) { ValueEnforcer.notNull (aReader, "Reader"); ValueEnforcer.notNull (aSettings, "Settings"); final ECSSVersion eVersion = aSettings.getCSSVersion (); try { final CSSCharStream aCharStream = new CSSCharStream (aReader); // Use the default CSS parse error handler if none is provided ICSSParseErrorHandler aRealParseErrorHandler = aSettings.getCustomErrorHandler (); if (aRealParseErrorHandler == null) aRealParseErrorHandler = getDefaultParseErrorHandler (); // Use the default CSS exception handler if none is provided ICSSParseExceptionCallback aRealParseExceptionHandler = aSettings.getCustomExceptionHandler (); if (aRealParseExceptionHandler == null) aRealParseExceptionHandler = getDefaultParseExceptionHandler (); final CSSNode aNode = _readStyleDeclaration (aCharStream, eVersion, aRealParseErrorHandler, aRealParseExceptionHandler); // Failed to parse content as CSS? if (aNode == null) return null; // Get the interpret error handler ICSSInterpretErrorHandler aRealInterpretErrorHandler = aSettings.getInterpretErrorHandler (); if (aRealInterpretErrorHandler == null) aRealInterpretErrorHandler = getDefaultInterpretErrorHandler (); final boolean bUseSourceLocation = aSettings.isUseSourceLocation (); // Convert the AST to a domain object return CSSHandler.readDeclarationListFromNode (eVersion, aRealInterpretErrorHandler, bUseSourceLocation, aNode); } finally { StreamHelper.close (aReader); } }
Example 17
Source File: MutableLong.java From ph-commons with Apache License 2.0 | 4 votes |
@Nonnull public EChange set (@Nonnull final Number aValue) { ValueEnforcer.notNull (aValue, "Value"); return set (aValue.longValue ()); }
Example 18
Source File: AuthIdentificationResult.java From ph-commons with Apache License 2.0 | 3 votes |
/** * Factory method for success authentication. * * @param aAuthToken * The auth token. May not be <code>null</code>. * @return Never <code>null</code>. */ @Nonnull public static AuthIdentificationResult createSuccess (@Nonnull final IAuthToken aAuthToken) { ValueEnforcer.notNull (aAuthToken, "AuthToken"); return new AuthIdentificationResult (aAuthToken, null); }
Example 19
Source File: CSSDeclaration.java From ph-css with Apache License 2.0 | 3 votes |
/** * Set the expression (= value) of this declaration. * * @param aExpression * The value of the property. May not be <code>null</code>. * @return this * @since 3.7.4 */ @Nonnull public final CSSDeclaration setExpression (@Nonnull final CSSExpression aExpression) { m_aExpression = ValueEnforcer.notNull (aExpression, "Expression"); return this; }
Example 20
Source File: PSWriter.java From ph-schematron with Apache License 2.0 | 3 votes |
/** * Get the passed Schematron element as a String * * @param aPSElement * The schematron element to convert to a string. May not be * <code>null</code>. * @return The passed element as a string or <code>null</code> if * serialization failed. */ @Nullable public String getXMLString (@Nonnull final IPSElement aPSElement) { ValueEnforcer.notNull (aPSElement, "PSElement"); final IMicroElement eXML = aPSElement.getAsMicroElement (); return MicroWriter.getNodeAsString (getAsDocument (eXML), m_aWriterSettings.getXMLWriterSettings ()); }