commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1099001 - in /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime: net/SelectionEvent.java platform/windows/RegistryKey.java
Date Tue, 03 May 2011 11:03:49 GMT
Author: mturk
Date: Tue May  3 11:03:49 2011
New Revision: 1099001

URL: http://svn.apache.org/viewvc?rev=1099001&view=rev
Log:
Add SelectionEvent class. This is similar to NIO SelectionKey.OP_FOO fields

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionEvent.java
  (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionEvent.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionEvent.java?rev=1099001&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionEvent.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionEvent.java
Tue May  3 11:03:49 2011
@@ -0,0 +1,127 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime.net;
+
+import java.util.EnumSet;
+
+/**
+ * Selection event flags.
+ */
+public enum SelectionEvent
+{
+    /** Accept operation.
+     * <p>
+     * </p>
+     */
+    ACCEPT(     0x01),
+    /** Connect operation.
+     * <p>
+     * </p>
+     */
+    CONNECT(    0x02),
+    /** Read operation.
+     * <p>
+     * </p>
+     */
+    READ(       0x04),
+    /** Write operation.
+     * <p>
+     * </p>
+     */
+    WRITE(      0x08),
+    /** Read hang up operation.
+     * <p>
+     * If present in output it signals that
+     * stream socket peer closed connection,
+     * or shut down writing half of connection.
+     * </p>
+     */
+    RDHUP(      0x10),
+    /** Hang up happened on the associated descriptor.
+     * <p>
+     * This is output only flag.
+     * </p>
+     */
+    HANGUP(     0x20),
+    /** Error condition happened on the associated descriptor.
+     * <p>
+     * This is output only flag.
+     * </p>
+     */
+    ERROR(      0x40);
+    
+
+    private int value;
+    private SelectionEvent(int v)
+    {
+        value = v;
+    }
+
+    public int valueOf()
+    {
+        return value;
+    }
+
+    /**
+     * Integer representing the sum of the integer values
+     * of the {@code SelectionEvent} enums.
+     * @param set The {@code EnumSet} which values to get.
+     * @return sum of {@code SelectionEvent} values
+     */
+    public static int bitmapOf(EnumSet<SelectionEvent> set)
+    {
+        int bitmap = 0;
+        if (set != null && set.size() != 0) {
+            for (SelectionEvent a : set)
+                bitmap += a.valueOf();
+        }
+        return bitmap;
+    }
+
+    /**
+     * Integer representing the sum of the integer values
+     * of the {@code SelectionEvent} enums.
+     * @param set arguments of {@code SelectionEvent} which values to get.
+     * @return sum of {@code SelectionEvent} values
+     */
+    public static int bitmapOf(SelectionEvent... set)
+    {
+        int bitmap = 0;
+        if (set != null) {
+            for (SelectionEvent a : set)
+                bitmap += a.valueOf();
+        }
+        return bitmap;
+    }
+
+    /**
+     * Returns {@code EnumSet} of {@code SelectionEvent} enums
+     * from the integer bitmap value.
+     * @param value Integer used to construct the {@code EnumSet}
+     * with {@code SelectionEvent} values mathching the value flags.
+     * @return set of {@code SelectionEvent} enums.
+     */
+    public static EnumSet<SelectionEvent> valueOf(int value)
+    {
+        EnumSet<SelectionEvent> set = EnumSet.noneOf(SelectionEvent.class);
+        for (SelectionEvent e : values()) {
+            if ((e.value & value) == e.value)
+                set.add(e);
+        }
+        return set;
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java?rev=1099001&r1=1099000&r2=1099001&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java
Tue May  3 11:03:49 2011
@@ -41,9 +41,13 @@ import org.apache.commons.runtime.util.U
 public abstract class RegistryKey implements Closeable, Flushable
 {
 
+    /**
+     * Initializes a new instance of this class.
+     */
     protected RegistryKey()
     {
     }
+
     /**
      * Free the allocated resource by the Operating system.
      * <p>



Mime
View raw message